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

All commands from sorted by
Terminal - All commands - 11,928 results
less -r <some file>
2009-03-01 21:19:53
User: prayer
Functions: less
Tags: less
2

It allows customizing by means of lesspipe. You need to write a ~/.lessfilter script and put this into your ~/.bashrc:

eval $(lesspipe)

export LESS=-r

elinks http://partmaps.org/era/unix/award.html
2009-03-01 18:59:55
User: sud0er
0

Everyone on CLIFU needs to check this site out. Learn how to accomplish what you've been doing faster and more efficiently.

sudo mount -o remount,rw /
2009-03-01 13:36:05
User: blindgaenger
Functions: mount sudo
Tags: mount remount rw
4

Saved my day, when my harddrive got stuck in read-only mode.

ethtool -S eth0
bzgrep -i "pattern" pattern.bz2
2009-03-01 10:21:26
User: rockon
Functions: bzgrep
0

Search the pattern in bzip2 compressed file with out having to unzip.

pinky -l <username>
2009-03-01 10:17:08
User: rockon
Functions: pinky
2

Gives information about user's home directory and real name and shell user is having.

hdparm -i[I] /dev/sda
2009-03-01 10:00:28
User: rockon
Functions: hdparm
9

Get the hard disk information with out shutting down and opening the system.

It gives information on model no., serial no., cylinders/heads/sectors, and the supported features of the hard disk.

lsb-release -a
2009-03-01 09:42:52
User: rockon
0

To know the OS distro and version, release.

Is same like /etc/redhat-release

join file1.txt file2.txt > file3.txt
cat file1.txt | uniq > file2.txt
find . |more |grep -v filename |xargs rm
wrestool -x --output . -t14 /path/to/your-file.exe
taskset -c 0 your_command
2009-02-28 22:38:02
User: Alanceil
Functions: taskset
19

This is useful if you have a program which doesn't work well with multicore CPUs. With taskset you can set its CPU affinity to run on only one core.

mplayer -dumpstream -dumpfile "yourfile" -playlist "URL"
2009-02-28 22:18:17
User: Alanceil
9

I use this command to save RTSP video streams over night from one of our national TV stations, so I won't have to squeeze the data through my slow internet connection when I want to watch it the next day.

For ease of use, you might want to put this in a file:

#!/bin/bash

FILE="`basename \"$1\"`"

mplayer -dumpstream -dumpfile "$FILE" -playlist "$1"

alias calc 'echo "scale=4;\!*"|bc -l'; alias xcalc 'echo "\!*"|bc -l'
2009-02-28 21:30:59
User: boomer_tn
Functions: alias
1

allows simple C shell access to the power of bc - never could figure out how to do the same thing with Bash - that's why I use tcsh most of the time.

find -name '*wma' -exec ffmpeg -i {} -acodec vorbis -ab 128k {}.ogg \;
export IFS=$'\n';for dir in $( ls -l | grep ^d | cut -c 52-);do du -sh $dir; done
dpkg --compare-versions 1.0-2ubuntu5 lt 1.1-1~raphink3 && echo y || echo n
2009-02-28 18:01:59
User: raphink
Functions: echo
Tags: Debian Ubuntu
2

Compares two versions with dpkg. It is not always obvious what version dpkg/apt will consider to be more recent. Operators include the following :

* These treat an empty version as earlier than any version: lt le eq ne ge gt.

* These treat an empty version as later than any version: lt-nl le-nl ge-nl gt-nl.

* These are provided only for compatibility with control file syntax: < > >.

This command doesn't output anything. It only returns with status 0 or 1, hence the echo "y" || echo "n" to get an output.

ps axww | grep SomeCommand | awk '{ print $1 }' | xargs kill
2009-02-28 17:48:51
User: philiph
Functions: awk grep ps xargs
-7

This command kills all processes with 'SomeCommand' in the process name. There are other more elegant ways to extract the process names from ps but they are hard to remember and not portable across platforms. Use this command with caution as you could accidentally kill other matching processes!

xargs is particularly handy in this case because it makes it easy to feed the process IDs to kill and it also ensures that you don't try to feed too many PIDs to kill at once and overflow the command-line buffer.

Note that if you are attempting to kill many thousands of runaway processes at once you should use 'kill -9'. Otherwise the system will try to bring each process into memory before killing it and you could run out of memory. Typically when you want to kill many processes at once it is because you are already in a low memory situation so if you don't 'kill -9' you will make things worse

:rm 1
find $HOME -type f -print | perl -wnlaF'/' -e 'BEGIN{ print "#EXTM3U"; } /.+\.wmv$|.+\.mpg$|.+\.vob$/i and print "#EXTINF:$F[-1]\nfile://$&";' > movies.m3u
svn status | grep '^\?' | sed -e 's/^\?//g' | xargs svn add
2009-02-28 03:00:28
User: dollyaswin
Functions: grep sed xargs
0

These part of the command:

svn status | grep '^\?' => find new file or directory on working copy

sed -e 's/^\?//g' => remove "^" character on the first character of file name

xargs svn add => add file to subversion repository

You can modify above command to other circumtances, like revert addition files or commit files that have been modified. ^_^

e2label /dev/vg0/lv0 MyFiles
v=/dev/vg0/lv0; lvextend -L+200G $v && resize2fs $v
2009-02-28 02:30:49
User: wwest4
Functions: resize2fs
4

Live extension of an ext3 file system on logical volume $v by 200GB without the need to unmount/remount.

Requires that you have 1) a version of resize2fs that contains code merged from ext2online, and 2) kernel support for online resizing. (e.g. RHEL 5)

pkill -n firefox
2009-02-28 01:19:59
User: Williebee
3

Kills the most recently created firefox process.