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.


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.
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

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!
Hide

Top Tags

Hide

Functions

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

Commands using rename from sorted by
Terminal - Commands using rename - 65 results
find / -name "*.xls" -print0 | xargs -0 rename .xls .ods {}
2011-07-18 12:48:49
User: jagjit
Functions: find rename xargs
0

This command can be used to rename all the files with extension .xls( in this case) to .ods files. It can be used for other files with certain extension.

rename foo bar filename
rename foo bar directory/filename
2011-05-04 22:29:11
User: hexram
Functions: rename
-2

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
11

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
6

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
1

easier way to recursively change files to lowercase using rename instead

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

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
16

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
3

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/' {} \;