查找,复制,在同一目录中重命名 [英] Find, copy, rename within the same directory
问题描述
我一个新的bash的,可能与一些帮助做的。我期待创建一个命令,将立即与新新复制最后创建的文件。到目前为止,我想出了下面的命令;
I an new to bash and could do with some help. I am looking to create a command that will instantly duplicate the last created file with a new new. So far I come up with the following command;
find /home/ian/Desktop/TEST/ -type f -mmin -1 -exec echo cp {} /home/ian/Desktop/TEST/ \;
但对于生活还是我,我不能找到一种方法来重命名文件,我已经看了看周围,并尝试了各种方法,但似乎没有工作。我想有过改名的控制,这样我可以添加_backup到被复制的每个文件。
But for the life or me I cannot find a way to rename the file and I have looked around and tried various methods but none seemed to work. I would like to have control over the renaming so that I can add '_backup' to each file that is copied.
什么是去了解这一点的最好方法是什么?很抱歉,如果这是这样一个基本的问题。
What would be the best way to go about this? Sorry if this is such a basic question
一切顺利,
伊恩
All the best, Ian
推荐答案
您可能需要使用 -execdir
而不是 -exec
:
You probably need to use -execdir
instead of -exec
:
-execdir command ;
-execdir command {} +
Like -exec, but the specified command is run from the subdirec‐
tory containing the matched file, which is not normally the
directory in which you started find.
下面的命令似乎按预期方式工作:
The following command seems to work as expected:
find /home/ian/Desktop/TEST/ -type f -mmin -1 -execdir echo cp \{} \{}_backup \;
这篇关于查找,复制,在同一目录中重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!