1
0
I have a list of filename in list.txt, which have 'abc1.png, abc2.png, abc3.png....'.
However, I don't know the directories where the files are.
I want to find all files in the txt file, and move them to a new folder.
1
0
I have a list of filename in list.txt, which have 'abc1.png, abc2.png, abc3.png....'.
However, I don't know the directories where the files are.
I want to find all files in the txt file, and move them to a new folder.
0
You need to read each filename line-by-line, then try to find it using the name option, and finally mv it to the target:
while IFS= read -r filename; do
find /somewhere -type f -name "$filename" -exec mv -- {} /somewhere/else/ \;
done < file.txt
The {} will be replaced with the found file path.
0
Assuming your file names do not contain ", " or newlines and every file exists in list.txt only once. You also naturally have to change newdirectory to directory you want. If any file in list.txt is missing, the file is not copied (and no info given).
sed -s "s/, /\\n/g" list.txt | xargs -IFILE -n1 find -name FILE -exec mv {} newdirectory \;
-1
This is easy with some bash :
first find your files with find and redirect the ouptut in another file :
for arg in $(cat list.txt); do find / -name $arg -print >> files_with_path.txt; done
then mv the files :
for arg in $(cat files_with_path.txt); do mv $arg /your/dest/folder; done
1 Please read: Why you don't read lines with "for" – your command will fail in certain situations, notably when files (or found paths) contain whitespace.
Search for every single file through entire filesystem?? – pbies – 2013-12-06T18:19:53.410
1It would be rather difficult to do in one shell command since AFAIK you can't pipe cat to find or locate, so I'd reccomend using
find / -name a.pngto locate the directory, then runningcd DIRECTORY; mv $(cat list.txt) ~/or you could write a more complicated shell script to loop through line by line, but that might cost more time than it saves. – None – 2013-12-06T17:11:38.997