Deleting a file(Name) with spaces

September 8, 2008 at 21:59:30
Specs: Unix, P3/256 MB

I need to write a script to delete files with spaces in the filename. Can anyone help me out?

Thanks and Regards,
Gopikrishna.V


See More: Deleting a file(Name) with spaces

Report •


#1
September 8, 2008 at 22:36:45

surround the file name with double quotes:

touch "file spaces" # create the file
rm "file spaces" # remove the file


Report •

#2
September 9, 2008 at 22:04:03

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


Report •

#3
September 11, 2008 at 03:51:46

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.

Hope u find it useful,
Regards,
Sujan


Report •

Related Solutions


Ask Question