Rename Files That Start With a Special Character
Gregg
Suppose you find that you have a file with a special character and you want to delete it:
$ ls-badfile.txt PrintHood reg57.txtFavorites Recent scripts$ rm -badfile.txtrm: invalid option -- 'b'Try 'rm ./-badfile.txt' to remove the file '-badfile.txt'.Try 'rm --help' for more information.$ ls *.txtls: invalid option -- 'e'Try 'ls --help' for more information.
First, find the inode of the file by using ls -i on the command line:
$ ls -i54804119 -badfile.txt 56634824 PrintHood56634825 Recent 56634807 Favorites54804251 reg57.txt 56634833 scripts
The “-i” flag will display the file’s inode: 54804119 -badfile.txt
The inode for the “bad” file is 54804119. Once the inode is identified, use the find command to rename the file:
$ find . -inum 54804119 -exec mv {} NewName \;$ ls NewNameNewName
Now you can delete it.
$ rm NewName