Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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



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



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
Posted
Updated 16-Mar-16 23:50pm

1 solution

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.
 
Share this answer
 
Comments
Member 12018498 18-Mar-16 1:03am    
thank you Richard for a suggestion. so if I cant do that, we have to move only files, delete the existing smybolic links and recreate a new link. I will try it
Richard MacCutchan 18-Mar-16 4:52am    
On reflection, I think you can still do this with the find command. Just check the man page for options to list only certain types.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900