【问题标题】:How to move files to another directory which are created today in Shell?如何将文件移动到今天在 Shell 中创建的另一个目录?
【发布时间】:2016-02-29 14:45:47
【问题描述】:

我有以下脚本

find . -mtime 0 -type f -exec ls -ltr {} \; | grep "$(date +%d|sed 's,^0,,g') ..:.." | while read fname; do
   echo "$fname"
done

而且我可以打印文件详细信息。如何将 test1.txt test2.txt 文件移动到另一个目录?

输出:

[nca@ldc039 failure]$ . ../../scripts/retryFailedFiles.sh 
-rwxrwxr-x. 1 nca nca 0 Feb 29 16:16 ./test1.txt
-rwxrwxr-x. 1 nca nca 0 Feb 29 16:16 ./test2.txt 

【问题讨论】:

  • 不清楚您所说的“触发mv 命令”是什么意思。是否要将 test1.txt 移动到 test2.txt?请编辑您的 Q,而不是在 cmets 中回复。祝你好运。

标签: shell


【解决方案1】:
# You can use the option -1tr instead -ltr :
find . -mtime 0 -type f -exec ls -1tr {} \; | while read fname; do
echo "$fname" 
mv $fname newfolder
done

# Or, by using the following commande :
find . -mtime 0 -type f -exec mv {} newfolder \;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-26
    • 2014-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-20
    • 1970-01-01
    • 2014-07-18
    相关资源
    最近更新 更多