Hide

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using rename from sorted by
Terminal - Commands using rename - 57 results
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
14

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
2

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
2

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
0

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
3

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
8

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
8

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
6

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
18

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

Add -n to test the command without renaming files.

Check the 'sample output'.

rename -v 's/ /_/g' *
rename 's/^/prefix/' *
2009-08-14 03:26:45
User: lingo
Functions: rename
12

Best to try first with -n flag, to preview

exiv2 rename *.jpg
find -name '*oldname*' -print0 | xargs -0 rename 's/oldname/newname/'
2009-07-27 00:44:06
Functions: find rename xargs
0

This is better than doing a "for `find ...`; do ...; done", if any of the returned filenames have a space in them, it gets mangled. This should be able to handle any files.

Of course, this only works if you have rename installed on your system, so it's not a very portable command.

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

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/.*/[it]$&/' *.pdf
find ./ -name '*.JPG' -type f -execdir rename -f 'y/A-Z/a-z/' {} \+
2009-03-27 13:49:56
User: pronoiaque
Functions: find rename
2

Change files case, without modify directories, recursively.

... fucking vfat