我希望能够搜索超过 14 天和超过 10k 的文件,然后将那些找到的文件 rsync 到目的地。
有没有办法组合这两个命令?
find ./ -mtime +14 -size +10k
rsync --remove-sent-files -avz /src /dest
Run Code Online (Sandbox Code Playgroud) 我正在制作的脚本的目的是比较两个系列的文件。文件名本身存储在两个单独的文件中,每行一个路径。我的想法是有两个while read循环,每个文件名列表一个循环,但是如何将两个循环混合在一起?
while read compareFile <&3; do
if [[ ! $server =~ [^[:space:]] ]] ; then #empty line exception
continue
fi
echo "Comparing file - $compareFile"
if diff "$compareFile" _(other file from loop?_) >/dev/null ; then
echo Same
else
echo Different
fi
done 3</infanass/dev/admin/filestoCompare.txt
Run Code Online (Sandbox Code Playgroud)
我需要能够通过两个 while 读取循环同时比较来自两个不同列表的文件......这甚至可能吗?
#!/bin/bash
while read server <&3; do #read server names into the while loop
if [[ ! $server =~ [^[:space:]] ]] ; then #empty line exception
continue
fi
echo "Connecting to - $server"
#ssh "$server" #SSH login
while read updatedfile <&3 && read oldfile <&4; do
echo Comparing $updatedfile with $oldfile
if diff "$updatedfile" "$oldfile" >/dev/null ; then
echo The files compared are the same. No changes were made.
else
echo The files compared are different.
# copy the new file …Run Code Online (Sandbox Code Playgroud) 我希望能够将 $oldfile 移动到我的备份文件夹并将日期添加到文件名中。所以我尝试了这个...
mv $oldfile /home/u0146121/backupfiles/$oldfile_$(date +%F-%T)
Run Code Online (Sandbox Code Playgroud)
这只是给了我这个输出文件名。(没有原始文件名)
2013-07-11-10:22:25
然后我意识到了上述方法的潜在问题。我有一个 while 读取循环,它读取我想比较的其他文件的路径名文本文件。例如,$oldfile 实际上是 =
$ cat oldfiles.txt
/home/u0146121/OldLogFiles/file2.txt
Run Code Online (Sandbox Code Playgroud)
所以......我希望能够移动file2.txt并保留file2.txt名称并为其添加日期。
我想知道是否有人知道如何找到一个模式,然后将其移动到不同的位置。
例如,我有很多文件名为:
odbc.ini_20110630
odbc.ini_20110639
odbc.ini_20110643
etc...Run Code Online (Sandbox Code Playgroud)
我想搜索 just 的模式odbc.ini并将它们全部移动到不同的文件夹。
我不太熟悉如何一次执行两个命令(管道)。
我正在努力使用 find 命令,该命令将允许我查找 7 天前修改过且大于 1 MB 的所有文件。
这是我所拥有的 -
find /path/to/files* -mtime +7 | -size +1M
Run Code Online (Sandbox Code Playgroud)
但我认为这不是正确的语法。
bash ×5
find ×3
filenames ×2
rename ×2
shell ×2
control-flow ×1
pipe ×1
rsync ×1
shell-script ×1