I have a large filelist of 7000+ files to delete from a Unix directory. I could have accomplished this using a while loop
while read file
do
rm $file
done < filelist
or just
cat filelist | xargs rm
The challenge comes from deleting those files which have "Windows-like back slash \, colon : and spaces " in their filenames.
Eg.
C:\Sxxx Accr Vac 1111.txt
N:\Lxxx\Dxxx_FOLDER\Mxxx\Mxxx_DOWNLOAD_TEXTFILE_PATH\000000_Mxxx_Bxxx-Pxxx-H.txt
N:\Lxxx\Dxxx_FOLDER\Mxxx\Mxxx_DOWNLOAD_TEXTFILE_PATH\130607_Mxxx_Bxxx-Cxxx-L.txt
N:\Lxxx\Dxxx_FOLDER\Mxxx\Mxxx_DOWNLOAD_TEXTFILE_PATH\140103_Mxxx_Xxxx-Pxx-H.txt
To delete these, I had to enclose the entire filename in double quotes. I wanted to preview the rm commands for each file before actual deletion:
while read -r file
do
echo rm \"$file\"
done < filelist
The problem is that filenames with "\0000" in their strings
eg. N:\Lxxx\Dxxx_FOLDER\Mxxx\Mxxx_DOWNLOAD_TEXTFILE_PATH\000000_Mxxx_Bxxx-Pxxx-H.txt
always ended up with the "\0000" mysteriously truncated from the output.
Eg. For the above file, the rm commands shows up as:
rm "N:\Lxxx\Dxxx_FOLDER\Mxxx\Mxxx_DOWNLOAD_TEXTFILE_PATH00_Mxxx_Bxxx-Pxxx-H.txt"
None of the other files had this problem after passing through the loop.
Any clues?