Deleting files with spaces in their names
You can use standard globbing on the rm
command:
rm -- *\ *
This will delete any file whose name contains a space; the space is escaped so the shell doesn't interpret it as a separator. Adding --
will avoid problems with filenames starting with dashes (they won’t be interpreted as arguments by rm
).
If you want to confirm each file before it’s deleted, add the -i
option:
rm -i -- *\ *
I would avoid parsing ls
output
Why not :
find . -type f -name '* *' -delete
No problem with rm
:-).
Although this is recursive and will delete all files with space in current directory and nested directories, as mentionned in comments.
Look at this Suppose name "strange file"
Solution one
rm strange\ file
solution two
rm "strange file"
solution three
ls -i "strange file"
you see the inode then
find . -inum "numberoofinode" -exec rm {} \;
In case of very strange file names like
!-filename or --filename
use
rm ./'!-filename'