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.

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

Hide

Credits

All commands from sorted by
Terminal - All commands - 12,130 results
jhead -n%Y%m%d-%H%M%S *.jpg
2009-08-10 03:49:30
4

jhead is a very nice tool to do all sorts of things with photographs, in a batch-oriented way. It has a specific function to rename files based on dates, and the format I used above was just an example.

ls -1 *.jpg | while read fn; do export pa=`exiv2 "$fn" | grep timestamp | awk '{ print $4 " " $5 ".jpg"}' | tr ":" "-"`; mv "$fn" "$pa"; done
2009-08-10 00:52:22
User: axanc
Functions: awk export grep ls mv read tr
0

Renames all the jpg files as their timestamps with ".jpg" extension.

old='apt-get'; new="su-${old}"; command="sudo ${old}"; alias "${new}=${command}"; $( complete | sed -n "s/${old}$/${new}/p" ); alias ${new}; complete -p ${new}
2009-08-10 00:15:05
User: Josay
Functions: alias sed
4

In Bash, when defining an alias, one usually loses the completion related to the function used in that alias (that completion is usually defined in /etc/bash_completion using the complete builtin).

It's easy to reuse the work done for that completion in order to have smart completion for our alias.

That's what is done by this command line (that's only an example but it may be very easy to reuse).

Note 1 : You can use given command line in a loop "for old in apt-get apt-cache" if you want to define aliases like that for many commands.

Note 2 : You can put the output of the command directly in your .bashrc file (after the ". /etc/bash_completion") to always have the alias and its completion

for f in *.eps;do ps2pdf -dEPSCrop $f `basename $f .eps`.pdf; done
perl -p -i -e 's/this/that/g' filename
column -t /proc/mounts
2009-08-09 17:00:41
Functions: column
10

since fuse mounts do not appear in /etc/mtab (fuse can't write there, dunno if it would if it could) this is propably a better way.

FECHA=$(date +"%F") FINAL="$FECHA.sql.gz" mysqldump -h localhost -u user --password="pass" --opt jdiaz61_lupajuridica | gzip > /home/jdiaz61/www/backup/$FINAL
2009-08-09 14:51:46
User: juancabo
Functions: date gzip
-2

Tres lineas en un shell script para copiar la base de datos diaramente

iconv --from-code=ISO-8859-1 --to-code=UTF-8 iso.txt > utf.txt
2009-08-09 14:22:09
User: jsiei97
Functions: iconv
3

Nothing fancy it just converts one file from one character encoding into another one.

grep . filename
2009-08-09 05:33:58
Functions: grep
Tags: Linux grep
7

Remove newlines from output.

One character shorter than awk /./ filename and doesn't use a superfluous cat.

To be fair though, I'm pretty sure fraktil was thinking being able to nuke newlines from any command is much more useful than just from one file.

curl www.whatismyip.com/automation/n09230945.asp
update-java-alternatives
2009-08-09 02:43:06
User: stuart
Tags: Debian Ubuntu
2

Lets you set all the java alternatives at once to a matching version. Also has options for just changing the jre or the plugin.

git add --patch <filename>
dig +short $HOSTNAME
awk /./ filename
2009-08-09 02:04:46
Functions: awk
Tags: awk
1

?Cat and grep? You can use only grep ("grep \. filename"). Better option is awk.

cat filename | grep .
2009-08-09 01:00:59
User: fraktil
Functions: cat grep
Tags: cat Linux grep
2

Pipe any output to "grep ." and blank lines will not be printed.

getconf LONG_BIT
2009-08-08 21:22:19
User: caiosba
Functions: getconf
Tags: getconf 32 64
98

Easy and direct way to find this out.

host $HOSTNAME|cut -d' ' -f4
2009-08-08 12:39:00
User: penpen
Functions: cut host
1

Using DynDNS or a similar service not only allows access to your home machine from outside without needing to know what IP the ISP has assigned to it but it also comes in handy if you want to know your external IP address. The only purpose of the sed command is to remove the leading "host.na.me has address " part from the output. If you don't need to discard it you can simply use

host $HOSTNAME
tzwatch
2009-08-08 01:26:08
User: terry2wa
4

On Ubuntu, if tzwatch is installed, then you can call up in terminal the output for every time zone configured in gWorldClock.

tzwatch
2009-08-08 01:25:50
User: terry2wa
0

On Ubuntu, if tzwatch is installed, then you can call up in terminal the output for every time zone configured in gWorldClock.

du --max-depth=1
let utime=$offsetutc*3600+$(date --utc +%s)+3600; date --utc --date=@${utime}
2009-08-07 23:12:14
User: flokra
Functions: date
0

prints out the time for the timezone specified in $offsetutc. So you have less to think about things like: "I'm in utc+4 and my friend in utc-7, can I call him now or will I wake him?"

Note: $offsetutc should be an integer between -12 and 12.

nc $telnetserver 23 < $commandfile
2009-08-07 21:32:38
User: flokra
1

sends commands specified in $commandfile to the telnet-server specified by $telnetserver.

to have newlines in $commandfile interpreted as ENTER, save the file in CR+LF (aka "Windows-Textfile") format.

if you want to save the output in a separate file, use:

nc $telnetserver 23 < $commandfile > $resultfile
wget http://checkip.dyndns.org && clear && echo && echo My IP && egrep -o '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}' index.html && echo && rm index.html