commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for:
Using xargs is better than:
find /path/to/dir -type f -exec rm \-f {} \;
as the -exec switch uses a separate process for each remove. xargs splits the streamed files into more managable subsets so less processes are required.
There is 1 alternative - vote for the best!
Optimal way of deleting huge numbers of files
Using -delete is faster than:
find /path/to/dir -type f -print0 | xargs -0 rm
find /path/to/dir -type f -exec rm {} +
find /path/to/dir -type f -exec rm \-f {} \;
If you can do better, submit your command here.
You must be signed in to comment.
cd /path/to/dir ; ls | xargs rm
I think you can get find to delete for you with the -delete option, which I imagine might be fastest:
find /path/to/dir -type f -deleteor with the -exec xargs-like behavoir:
find /path/to/dir -type f -exec rm {} +without launching the extra xargs process.
@speirs: Never parse ls: http://mywiki.wooledge.org/ParsingLs
@bwoodacre: +1 for the "+"
Benchmarked this using the drupal-6.14 files extracted from http://ftp.drupal.org/files/projects/drupal-6.14.tar.gz
time find drupal-6.14 -type f -deletereal 0m0.024s
user 0m0.004s
sys 0m0.020s
time find drupal-6.14 -type f -print0 | xargs -0 rmreal 0m0.030s
user 0m0.008s
sys 0m0.020s
time find drupal-6.14 -type f -exec rm {} +real 0m0.032s
user 0m0.004s
sys 0m0.028s
time find drupal-6.14 -type f -exec rm \-f {} \;real 0m1.700s
user 0m0.592s
sys 0m0.628s
how about this?
time rm -r drupal-6.14rm -r drupal-6.14
0.00s user 0.04s system 76% cpu 0.049 total
find drupal-6.14 -type f -deletefind drupal-6.14 -type f -delete
0.00s user 0.04s system 108% cpu 0.041 total
rm -r will also delete subdirectories, whereas the find -type -f leaves the directory tree intact.
Just curious...why have people wanted to delete just the files and not the directories (and other stuff)?
Also, what does the plus do?
i have had this fail for me once on a machine with low ram, find couldn't expand the path, got the too many arguments error.
ls | grep string |xargs rmworked in that situation.
Most other times find works fine :)