//View Tip #232
Similar Tips
» Randomized find
» Find files by mime-type
» Remove duplicate files
» Find last modified files on a filesystem
» Moved Trac and Subversion repositories to another machine/direct


Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
To delete a file who's file name is a pain to define (eg. ^H^H^H) find it's inode number with the command "ls -il". Use the line below to find and delete the file.
find . -inum 12345 | xargs rm

View Comments »


Add your comment

Comments are currently disabled
Nice site. Please fix this entry as it is a double command where a single command is needed only, and is faster. Also '.' is default location of find and is therefore not needed.

What you have:
find . -inum 12345 | xargs rm

What is faster and uses only one command:
find -inum 12345 -exec rm {} \;

Proof just time them. On my system I see:
xxx@xxx-laptop:~/Desktop$ time find -name xxx -exec rm {} \;

real    0m0.009s
user    0m0.004s
sys     0m0.004s
xxx@xxx-laptop:~/Desktop$ time find -name xxx | xargs rm

real    0m0.014s
user    0m0.012s
sys     0m0.004s
Posted 2008-10-02 16:05:28
Or use:

find . -inum 12345 -print0 | xargs -0 rm

if there is a space in the file-name, and you're not in the hurry.
Posted 2008-10-21 11:17:29

find -inum 12345 -exec rm {} \;

uses two commands.

find -inum 12345 -delete

Posted 2009-02-06 10:28:48
Touché Paul. I like how Nathan wrote a nice long comment complaining that the original submission ran two commands when his did as well. Granted, piping find output is slower than using the exec option, but it's still two commands. ^.^
Posted 2009-03-10 07:44:41
Amos Shapira
The first option (with xargs) is DANGEROUS.

If the file name contains white spaces then you can end up with xargs splitting at the spaces and passing different names to those find found.
Posted 2009-06-15 12:21:39

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit