找到目录下的所有文件和符号链接,并将其移动到unix中的其他目录 [英] Find all the files and symbolic links under a directory and move it to other directory in unix

查看:149
本文介绍了找到目录下的所有文件和符号链接,并将其移动到unix中的其他目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下内容的目录

I have a directory with contains the following

ls
cat.txt mat.txt animal(directory) cat_bar.txt
ll
rwxrwxrwx 1 85594 16416   26 Feb  3 08:38 cat.txt -> animal/cat.txt
lrwxrwxrwx 1 85594 16416   53 Feb  3 08:38 cat_bar.txt -> sle12/cat_bar.txt
lrwxrwxrwx 1 85594 16416   43 Feb  3 08:38 mat.txt
drwxrwxr-x 2 85594 16416 4096 Mar 17 06:01 animal







当我给出如下命令时

find。 -iname* cat *

输出是






when i give the find command as below
find . -iname "*cat*"
the output is

cat.txt
 cat_bar.txt
 ./animal/cat.txt
 ./animal/cat_bar.txt







我可以看到动物目录下的文件被移动到新的临时目录,但是没有移动符号链接。

我们如何移动所有文件,包括符号链接


我尝试过:



问题:

我想在一个临时文件夹中移动find的结果,所以我给了下面的命令

find。 - * cat *| xargs mv -t / home / temp



错误。我得到以下错误

mv:不会用'./cat.txt'覆盖刚刚创建的`/home/temp/cat.txt'

mv:will不要用'./cat_bar.txt'覆盖刚创建的`/home/temp/cat_bar.txt'



我想要的解决方案是命令应该同时移动链接和文件到新文件夹




I could see that the file under animal directory is moved to the new temp directory, but symbolic links are not moved.
How can we move all the files including symbolic links

What I have tried:

Problem:
I want to move the result of find in a temporary folder, so i gave the below command
find . -iname "*cat*" | xargs mv -t /home/temp

Error. i get the below error
mv: will not overwrite just-created `/home/temp/cat.txt' with `./cat.txt'
mv: will not overwrite just-created `/home/temp/cat_bar.txt' with `./cat_bar.txt'

the solution i want is that the command should move both links and files to the new folder

推荐答案

我认为你不能移动符号链接,你需要在<$ c $的新位置重新创建它们c> ln 命令。您很可能需要更复杂的脚本处理程序(例如awk)来检查目录条目是否为链接。
I don't think you can move symbolic links, you need to recreate them at the new location with the ln command. You most likely need a more sophisticated script handler, such as awk, to do the work of checking whether a directory entry is a link or not.


这篇关于找到目录下的所有文件和符号链接,并将其移动到unix中的其他目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆