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,162 results
dhclient -r && rm -f /var/lib/dhcp3/dhclient* && sed "s=$(hostname)=REPLACEME=g" -i /etc/hosts && hostname "$(echo $RANDOM | md5sum | cut -c 1-7 | tr a-z A-Z)" && sed "s=REPLACEME=$(hostname)=g" -i /etc/hosts && macchanger -e eth0 && dhclient
2009-09-28 22:07:31
User: syssyphus
Functions: hostname rm sed
Tags: privacy
7

this string of commands will release your dhcp address, change your mac address, generate a new random hostname and then get a new dhcp lease.

command -geometry 120x30+1280+0
2009-09-28 20:01:32
User: random_bob
Functions: command
Tags: geometry
0

open an application to wherever you like on your current display. the first set of #'s (120x30) denotes size of window opened in, and the second set (+1280+0) identifies the location. Either set can be used alone, or with the other. Also, opening gnome-terminal with this option requires it to be "--geometry" for some reason.

PERMA () { echo "$@" >> ~/.bashrc; }
2009-09-28 16:03:24
User: zlemini
Functions: echo
2

Simple function to permanently add an alias to your profile.

Tested on bash and Ksh, bash version above.

Here is the ksh version: PERMA () { print "$@" >> ~/.profile; }

Sample usage:

PERMA alias la='ls -a'

dig -x 74.125.45.100
2009-09-28 15:13:34
User: postrational
Functions: dig
4

Performs a reverse DNS lookup, variants include:

nslookup 74.125.45.100

or:

host 74.125.45.100
su -- user
2009-09-28 04:23:43
User: matthewdavis
Functions: su
Tags: bash root su
13

I've used this a number of times troubleshooting user permissions. Instead of just 'su - user' you can throw another hyphen and stay in the original directory.

gitstart () { if ! [[ -d "$@" ]]; then mkdir -p "$@" && cd "$@" && git init; else cd "$@" && git init; fi }
echo -e "\e[32m"; while :; do for i in {1..16}; do r="$(($RANDOM % 2))"; if [[ $(($RANDOM % 5)) == 1 ]]; then if [[ $(($RANDOM % 4)) == 1 ]]; then v+="\e[1m $r "; else v+="\e[2m $r "; fi; else v+=" "; fi; done; echo -e "$v"; v=""; done
2009-09-27 15:30:38
User: dennisw
Functions: echo
Tags: color
19

I like the fact the Patola's version uses only ones and zeros, but I also like the sparse output of the other versions. This one combines both of those features and eliminates some unnecessary cruft.

You can vary the sparseness by changing "$(($RANDOM % 5))" to another number. The number in this term "$(($RANDOM % 4))" controls how frequently the numbers are output bold.

enscript jrandom.txt -o - | ps2pdf - ~/tmp/jrandom.pdf (from file) or: ls | enscript -o - | ps2pdf - ~/tmp/ls.pdf (from stdout)
wget 'link of a Picasa WebAlbum' -O - |perl -e'while(<>){while(s/"media":{"content":\[{"url":"(.+?\.JPG)//){print "$1\n"}}' |wget -w1 -i -
sudo alien --to-deb Your_PackAge.rpm
2009-09-27 13:49:07
User: eastwind
Functions: sudo
-5

convert to debian package file (deb) a redhat package file (rpm) , then you can install it by using dpkg , require alien package ( sudo apt-get install alien first )

echo "blacklist pcspkr"|sudo tee -a /etc/modprobe.d/blacklist.conf
2009-09-27 11:42:47
User: sliceoflinux
Functions: echo sudo tee
4

This command will disable the beep sound from the PC speaker.

export HISTTIMEFORMAT='%F %T '
sudo tasksel install lamp-server
2009-09-26 08:15:03
User: sliceoflinux
Functions: install sudo
5

The execution of this command will install a LAMP server (Linux, Apache, MySQL and PHP) in a Debian based distribution. For example, in Ubuntu.

curl -s -c /tmp/cookie -k -u tivo:$MAK --digest "$(curl -s -c /tmp/cookie -k -u tivo:$MAK --digest https://$tivo/nowplaying/index.html | sed 's;.*<a href="\([^"]*\)">Download MPEG-PS</a>.*;\1;' | sed 's|\&amp;|\&|')" | tivodecode -m $MAK -- - > tivo.mpg
2009-09-26 03:00:46
User: matthewbauer
Functions: sed
0

Download the last show on your TiVo DVR.

Replace $MAK with your MAK see https://www3.tivo.com/tivo-mma/showmakey.do

Replace $tivo with your TiVo's IP

while true; do curl -s http://www.commandlinefu.com/commands/view/3643/log-a-commands-votes | grep 'id="num-votes-' | sed 's;.*id="num-votes-[0-9]*">\([0-9\-]*\)</div>;\1;' >> votes; sleep 10; done
2009-09-26 00:55:24
User: matthewbauer
Functions: grep sleep
0

Log a command's votes,

then run:

gnuplot -persist <(echo "plot 'votes' with lines")
export HISTTIMEFORMAT="%h/%d-%H:%M:%S "
2009-09-25 22:42:28
User: eastwind
Functions: export
8

for the change stay in your history file , export command by writing it into your .bashrc

mencoder -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mpeg4 -ffourcc xvid -vf scale=320:-2,expand=:240:::1 -o output.avi dvd://0
2009-09-25 19:29:25
User: ivalladt
4

Rip DVD to YouTube ready AVI file, using MPEG-4 video codec and MP3 audio codec. Resizes to 320x240 and deinterlaces as needed.

git log --pretty='format:%Cgreen%H %Cred%ai %Creset- %s'
2009-09-25 19:18:37
User: levenbrech
1

In color. Additionally you may define in your ~/.gitconfig and run it just as 'git one':

one = log --pretty='format:%Cgreen%H %Cred%ai %Creset- %s'

socat -v tcp4-l:<port> tcp4:<host>:<port>
for /F "DELIMS=""" %i in ('dsquery group -name SourceGroupName ^| dsget group -members') do dsquery group -name TargetGroupName | dsmod group -addmbr %i
2009-09-25 16:32:33
User: miketheman
-3

Interacting with Active Directory to add users from one group to another group.

This prevents from having to deal with long DNs and copying, pasting problems. It executes once per returned object.

apropos network |more
2009-09-25 15:05:33
User: shaiss
Functions: apropos
11

Get all the networking related commands for your distro

dmidecode | awk '/VMware Virtual Platform/ {print $3,$4,$5}'
2009-09-25 14:46:35
User: SuperFly
Functions: awk
6

If you run this command on a VMWare Virtual Machine, it will return the string "VMware Virtual Platform". If you run it on a physical machine, it will return nothing. Useful for having a script determine if it's running on a VM or not. Of course, you must have dmidecode installed for this to work.

Try it this way in a script: ISVM=$(dmidecode | awk '/VMware Virtual Platform/ {print $3,$4,$5}')

Then test if $ISVM has text in it, or is blank.

ack --pager='less -r'
encfs ~/.crypt ~/crypt
2009-09-25 10:13:39
User: bkn390
8

Create/open/use an encrypted directory

encfs needs to be installed

During creation easiest to use default values

The encrypted files will be in ~/.crypt and you will work as usual in ~/crypt

To close the encrypted directory run:

fusermount -u ~/crypt

When you switch off the computer the encrypted directory will be automatically closed

This example uses /home/user/crypt as encrypted directory

I use ubuntu linux 8.04 and I am also the creator of www.minihowto.org

sudo dpkg -i packagename.deb
2009-09-25 09:54:04
User: bkn390
Functions: sudo
-7

Install a deb package you have downloaded (synaptic has to be closed).

(dpkg-dev needs to be installed)

After that you may have to run following:

sudo apt-get install -f

(that should fix any dependency problems)

I am using ubuntu linux