What's this?

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.

Get involved!

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.

Universal configuration monitoring and system of record for IT.

Stay in the loop…

Follow the Tweets.

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

Subscribe to the feeds.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Renames all files in the current directory such that the new file contains no space characters.

Terminal - Renames all files in the current directory such that the new file contains no space characters.
rename 's/ /_/g' *
2011-07-04 06:21:27
User: twjolson
Functions: rename
Renames all files in the current directory such that the new file contains no space characters.


There is 1 alternative - vote for the best!

Terminal - Alternatives
rename 'y/ /_/' *
2009-06-27 22:20:47
User: signal9
Functions: rename
Tags: file rename

This command will replace all the spaces in all the filenames of the current directory with underscores. There are other commands that do this here, but this one is the easiest and shortest.

rename 's/ //g' *
for file in *; do mv -v "$file" "$(sed 's/ //g' <(echo $file))"; done
2011-07-10 21:08:31
User: laebshade
Functions: file mv

This is a better version, as it does no command piping, uses for instead of while loops, which allows for a list of files in the current working directory to be natively processed. It also uses the -v/verbose option with mv to let you know what the command is doing.

While the command does exactly the same in a better way, I would modify the sed option to replace spaces with underscores instead, or dashes.

Please note that you'll receive errors with this command as it tries to rename files that don't even have spaces.

This is an alternative to: http://www.commandlinefu.com/commands/view/8761/renames-all-files-in-the-current-directory-such-that-the-new-file-contains-no-space-characters.

zmv '* *' '$f:gs/ /_'
2013-03-23 00:58:52
User: khayyam

replace (any number of) space[s] with underscore.

find ./ $1 -name "* *" | while read a ; do mv "${a}" "${a//\ /_}" ; done

Know a better way?

If you can do better, submit your command here.

What others think

This depends on the Perl 'prename' command to be installed -- popular on Debian-based distributions, where /usr/bin/rename is a link to this file. The more common POSIX version of 'rename' doesn't do regular expressions, only one-time substring matches. 'rename oldstring newstring list_of_files' I.E.:

rename .htm .html *.htm
Comment by Mozai 277 weeks and 1 day ago

Your point of view

You must be signed in to comment.