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.

If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

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





Commands using rename from sorted by
Terminal - Commands using rename - 64 results
rename foo bar filename
rename foo bar directory/filename
2011-05-04 22:29:11
User: hexram
Functions: rename

rename command in my system -Fuduntu running 2.6.38 Linux Kernel- is an ELF 64-bit LSB executable, not a Perl script. man page for rename command shows syntax as "rename from to where" (or something like that), so I am doing just what I have been told...

rename 's/\d+/sprintf("%04d",$&)/e' *.jpg
2011-05-01 20:50:36
User: eightmillion
Functions: rename

This uses Perl's rename utility (you may have to call it as prename on your box) and won't choke on spaces or other characters in filenames. It will also zero pad a number even in filenames like "vacation-4.jpg".

rename 's/foo/bar/g' ./*
2011-05-01 15:55:20
Functions: rename

Would this command line achieve the desired function? My CLI knowledge is not great so this could certainly be wrong. It is merely a suggestion for more experienced uses to critique. Best wishes roly :-)

find . -depth -print -execdir rename -f 'y/A-Z/a-z/' '{}' \;
2011-03-25 03:10:27
User: rsimpson
Functions: find rename
Tags: bash find mv rename tr

easier way to recursively change files to lowercase using rename instead

rename -n "s/-.*//" *
2011-03-06 12:08:39
User: pepin
Functions: rename

of course, replace the "-" after / by the character you wish. a dot must by protected by a backslash, as it is a regexp. it's the same result as the command proposed. but if there is more than a dash in the name, only the part before the first dash is kept... so that's not an "extension renaming" command.

rename .txt .md *.txt
rename 's/\.txt$/\.md$/i' *
rename 's/.txt/.md/i' *
rename 's/\.jpe?g$/.jpg/i' *
2010-11-14 21:22:13
User: icebrain
Functions: rename
Tags: rename jpg

the "i" controls case sensitiveness. It's slightly inefficient since it uselessly renames .jpg to .jpg, but that's more than compensated by launching only one process instead of two, besides being shorter to write.

rename 's/\.jpeg/\.jpg/' *.jpeg; rename 's/\.JPG/\.jpg/' *.JPG
rename 's/ /-/g' *
2010-10-23 17:03:54
User: depesz
Functions: rename

As long as you have perl based rename. You can check:

=$ rename --help

Unknown option: help

Usage: rename [-v] [-n] [-f] perlexpr [filenames]

That's the good one.

rename 'y/ /_/' *
rename 's/\b((?!(a|of|that|to)\b)[a-z]+)/\u$1/g' *
2010-08-22 15:00:33
User: John_W
Functions: rename

All words of the filenames except "a", "of", "that" and "to" are capitalized.

To also match words which begin with a specific string, you can use this:

rename 's/\b((?!hello\b|t)[a-z]+)/\u$1/g' *

This will capitalize all words except "hello" and words beginning with "t".

rename 's/\b([a-z])/\u$1/g' *
rename 's/(^|[\s\(\)\[\]_-])([a-z])/$1\u$2/g' *
2010-08-22 11:26:20
User: l0b0
Functions: rename

Anyone know how to avoid title casing some words, like 'to', 'of', 'that', etc.?

rename 's/foo/bar/g' foobar
2010-08-19 03:33:13
Functions: rename
Tags: bash

Uses vi style search / replace in bash to rename files. Works with regex's too (I use the following a script to fixup / shorten file names):

# Remove complete parenthetical/bracket/brace phrases

rename 's/\(.*\)//g' *

rename 's/\[.*\]//g' *

rename 's/\{.*\}//g' *

rename 's/ /_/g' *
2010-01-29 21:15:03
User: tuxilicious
Functions: rename
Tags: bash

It's the rename-tool from debians perl-package.

find /path/to/images -name '*.JPG' -exec rename "s/.JPG/.jpg/g" \{\} \;
2010-01-02 19:12:37
User: renich
Functions: find rename
Tags: find rename

This command is useful for renaming a clipart, pic gallery or your photo collection. It will only change the big caps to small ones (on the extension).

rename "s/ *//g" *.jpg
2010-01-02 16:54:19
User: Vasudev
Functions: rename

This commands removes space from all the files with specific extension. I've specifed *.jpg as an example.

rename 'y/A-Z/a-z/' *
find my_root_dir -depth -exec rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;
rename -v 's/.*[s,S](\d{2}).*[e,E](\d{2}).*\.avi/SHOWNAME\ S$1E$2.avi/' poorly.named.file.s01e01.avi
2009-09-29 16:39:57
User: Karakh
Functions: rename

Replace 'SHOWNAME' with the name of the TV show.

Add -n to test the command without renaming files.

Check the 'sample output'.