« Super Friends The Office | Main | Google Maps Enhancements »

Deleting files with special names under Linux

In the spirit of this blog being a way for me to remember how to do things, I present a method to delete filenames under Linux that confuse the command-line utilities.

I had a script which, as a result of a syntax error, produced a file called:

—exclude-from=exclusions

Trying to remove this file by simply deleting it yielded this error:

rm: unrecognized option --exclude-from=exclusions' Tryrm —help’ for more information.

So, Googling found this link:

http://www.cyberciti.biz/tips/delete-remove-files-with-inode-number.html

The method described there is simple. Find the file’s internal i-node number and use the find’s ability to execute any command on results it’s finds to invoke rm on the results.

Two simple commands fixed by file:

obraxus:~/backup> ls -il
total 2932488
1746866 -rw-r--r--  1 ncodigno pg51206   48218112 Apr 10 19:39 --exclude-from=exclusions
1746694 -rwxr-xr-x  1 ncodigno pg51206        328 Apr 10 19:41 backup_primordia.csh
1746494 -rw-r--r--  1 ncodigno pg51206        167 Apr 14  2006 crontab_file
1746547 -rw-r--r--  1 ncodigno pg51206   35799040 Jan 28 03:24 d21_200701.tar.gz
1746442 -rw-r--r--  1 ncodigno pg51206         25 Jan 28 03:55 exclusions
3216545 -rwxr-xr-x  1 ncodigno pg51206       2728 Apr 15  2006 moin_config.py
3216543 -rwxr-xr-x  1 ncodigno pg51206       2688 Apr 15  2006 moin_config2.py
1746546 -rw-r--r--  1 ncodigno pg51206 2915876864 Jan 28 03:23 primordia_200701.tar.gz

Then issue this command:

find . -inum 1746866 -exec rm -i {} \;

QED.

TrackBack

TrackBack URL for this entry:
http://www.primordia.com/blog/mt-tb.cgi/743