Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Deleting a file(Name) with spaces
Name: Gopikrishna_V Date: September 8, 2008 at 21:59:30 Pacific OS: Unix CPU/Ram: P3/256 MB
Comment:
I need to write a script to delete files with spaces in the filename. Can anyone help me out?
Name: nails Date: September 8, 2008 at 22:36:45 Pacific
Reply:
surround the file name with double quotes:
touch "file spaces" # create the file rm "file spaces" # remove the file
0
Response Number 2
Name: Gopikrishna_V Date: September 9, 2008 at 22:04:03 Pacific
Reply:
Hi Nails, If i'm finding the files using find command and pass them as arguments through pipe, will I be still able to remove the files ??
Thanks and Regards, Gopikrishna.V
0
Response Number 3
Name: Sujan (by Sujan Banerjee) Date: September 11, 2008 at 03:51:46 Pacific
Reply:
Hi Gopal,
I am not sure how u r using find to trace files with spaces.Can u give the code-snippet for the same? Anyway here is what u desire:- #<ur find command> -exec rm {} \; e.g. #find /urpath -name ".* .*" -exec rm {} \; OR #find /urpath -name ".* .*"|xargs -i rm {} The second one with xargs is faster than the 1 with exec. U can use xargs with -p option or instead of "-exec" use "-ok" if u want to be prompted before each delete operation.
Summary: Taken directly from the man pages of rm > man rm Users often wonder how to deal with filenames that begin with ``-'', since arguments that begin with ``-'' are usually treated as flags. The special a...
Summary: Hi All, In this Unix forum, i saw a msg from Gopalkrishna V titled "Deleting a file(Name) with spaces". I was just wondering how can I find files with spaces in a large directory and rename files by r...
Summary: How can I delete a file with the name -C in unix? I tried below and get the error. > rm "-C" rm: illegal option -- C Usage: rm [-Rfir] file ... ...