Computing.Net > Forums > Unix > Deleting a file(Name) with spaces

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

Reply to Message Icon

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?

Thanks and Regards,
Gopikrishna.V



Sponsored Link
Ads by Google

Response Number 1
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.

Hope u find it useful,
Regards,
Sujan


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


parsing html file & put i... Need help in XIPT003I



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Deleting a file(Name) with spaces

How to delete a file named -x www.computing.net/answers/unix/how-to-delete-a-file-named-x/3350.html

How to remove spaces in filenames www.computing.net/answers/unix/how-to-remove-spaces-in-filenames/8204.html

Deleting a file in unix www.computing.net/answers/unix/deleting-a-file-in-unix-/7581.html