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 sudo from sorted by
Terminal - Commands using sudo - 400 results
sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
2010-05-23 11:39:35
User: bandie91
Functions: echo sudo sync tee
7

where proc filesystem mounted under /proc

sudo vconfig add eth0 [VID]
2010-05-15 21:32:24
User: leovailati
Functions: sudo
Tags: sudo vconfig
1

Great for sysadmins! Don't forget to pass the vlan to your port in a manageable switch.

After vconfig, you should use

sudo ifconfig eth0.[VID] up

Now the interface is up, you can use dhclient or ifconfig again to get an ip address.

pgrep rouge-process | xargs sudo kill -9
2010-05-09 22:30:05
User: mheadd
Functions: kill sudo xargs
Tags: xargs pgrep
-3

Find and kill multiple instances of a process with one simple command.

sudo usermod -p $(mkpasswd '') user_id
2010-05-06 20:39:58
User: ckclark
Functions: sudo usermod
-1

It is safe when there is

"PermitEmptyPasswords no"

in /etc/ssh/sshd_config.

This command is useful when there is no need to have a password.

echo "savedefault --default=2 --once" | grub --batch; sudo reboot
2010-05-02 03:06:23
User: matthewbauer
Functions: echo sudo
Tags: grub Reboot os
7

This will reboot as the Grub 2 option.

sudo powertop
2010-04-19 21:59:29
User: rkulla
Functions: sudo
3

Run this command as root to get enough stats. It works on AMD and Intel machines, including desktops. If ran on a laptop it'll give you suggestions on extending your battery life.

You'll need to install PowerTOP if you don't have, via 'apt-get install powertop', etc.

To grep the output use: sudo powertop -d | grep ...

The many command suggestions PowerTOP gives you alone will increase your command-line fu!

APP=wine; if [ $(sudo apt-get --print-uris -y install $APP | sed -ne 's/^After this operation, \([0-9]\{1,\}\).*MB.*/\1/p') -gt 50 ]; then gnometris 2>/dev/null & sudo apt-get install $APP; else sudo apt-get install $APP; fi
2010-04-18 19:32:26
User: rkulla
Functions: install sed sudo
2

Change the APP variable's value to whatever you want to install. Depending on how fast your machine is, you'll want to adjust the value 50 to something else. You might also want to play a different game than Gnometris - just make sure it's a GUI game.

cd /etc/init.d && sudo ./apache2 start
2010-04-17 16:01:18
User: nco
Functions: cd sudo
-9

This command is designed in order to avoid this error :

/etc/init.d/apache2 force-reload

* Reloading web server config apache2 httpd not running, trying to start

(13)Permission denied: make_sock: could not bind to address 0.0.0.0:80

no listening sockets available, shutting down

Unable to open logs

[fail]

sudo deborphan | xargs sudo apt-get -y remove --purge
sudo dmidecode --type=processor | grep -i -A 1 charac
sudo awk '($9 ~ /404/)' /var/log/httpd/www.domain-access_log | awk '{print $2,$9,$7,$11}' | sort | uniq -c
2010-04-09 10:31:50
User: ninjasys
Functions: awk sort sudo uniq
Tags: log error apache
1

This command will return a full list of Error 404 pages in the given access log. The following variables have been given to awk

Hostname ($2), ERROR Code ($9), Missing Item ($7), Referrer ($11)

You can then send this into a file (>> /path/to/file), which you can open with OpenOffice as a CSV

sudo ethtool -s eth0 speed 100 duplex full
2010-04-05 10:36:27
User: 0disse0
Functions: sudo
1

ethtool is used for querying settings of an ethernet device and changing them. In this example I setup 100 Mb/s full duplex on my Linux Box

sudo date -s "$(ssh user@server.com "date -u")"
2010-03-31 11:59:27
User: rpavlick
Functions: date sudo
Tags: sudo
5

(Useful when firewalls prevent you from using NTP.)

sudo ifconfig en1 ether 00:e2:e3:e4:e5:e6
2010-03-30 21:48:55
User: rpavlick
Functions: ifconfig sudo
0

If you want to check that the spoof worked, type the same command as earlier:

ifconfig en1 | grep ether

Now you will see:

ether 00:e2:e3:e4:e5:e6

For the wired ethernet port:

sudo ifconfig en0 ether 00:e2:e3:e4:e5:e6
sudo chattr -i <file that cannot be modified>
2010-03-25 03:14:34
User: leovailati
Functions: chattr sudo
Tags: Ubuntu chattr
1

I had problems in Ubuntu while trying to edit /etc/resolv.conf, even with sudo I couldn't make any change. After a 2 minutes search on google I found this command.

Hope someone finds it useful.

It works like chmod, with + and - to denote which attributes are being added and which are being removed.

See other attributes on man pages or on wikipedia http://en.wikipedia.org/wiki/Chattr

sudo apt-get -o Acquire::http::Dl-Limit=30 upgrade
2010-03-22 01:29:44
User: alemani
Functions: sudo
16

Limits the usage of bandwidth by apt-get, in the example the command will use 30Kb/s ;)

It should work for most apt-get actions (install, update, upgrade, dist-upgrade, etc.)

awk '/d[a-z]+$/{print $4}' /proc/partitions | xargs -i sudo hdparm -I /dev/{} | grep 'device size with M'
for I in $(awk '/d[a-z]+$/{print $4}' /proc/partitions); do sudo hdparm -I '/dev/'$I; done | grep 'device size with M'
2010-03-02 18:56:32
User: ElAlecs
Functions: awk grep hdparm size sudo
Tags: hdparm
0

I know this sucks in some way but if someone can improve it please be my guest

sudo truecrypt <truecrypt-file> <mount-point>
2010-02-27 16:25:19
User: kbrill
Functions: sudo
1

It seems to completely void the benefit of having an encrypted folder if you then have a script on your unencrypted hard drive with your password in it. This command will mount a truecrypt file at a given mount point after asking you for the password.

sudo aptitude update; sudo apt-get -y --print-uris upgrade | egrep -o -e "http://[^\']+" | sudo aria2c -c -d /var/cache/apt/archives -i -; sudo aptitude -y safe-upgrade
2010-02-18 16:02:29
User: freethinker
Functions: egrep sudo
2

Please install aria2c before you try the above command. On ubuntu the command to install aria2c would be:

sudo aptitude install aria2
sudo sed -iorig '/\(up\|down\)/s/^/#/' /etc/zsh/zshrc
2010-02-02 23:17:08
User: cbrinker
Functions: sed sudo
Tags: Ubuntu vi zsh
1

Use sed to comment out any up/down bindings in zsh

sudo ping -f -s 56500 192.168.1.100
2010-01-27 17:42:33
User: alamati
Functions: ping sudo
-3

A ping flood is a simple DoS attack where the attacker overwhelms the victim with ICMP Echo Request (ping) packets. It only succeeds if the attacker has more bandwidth than the victim (for instance an attacker with a DSL line and the victim on a dial-up modem).

In this command replace 192.168.1.100 with victim IP address.

sudo arp-scan --interface=eth0 -l
2010-01-27 05:36:48
User: alamati
Functions: sudo
1

replace eth0 with your ethernet or wireless network interface.

sudo netselect -v -s3 $(curl -s http://dns.comcast.net/dns-ip-addresses2.php | egrep -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort | uniq)
2010-01-27 00:03:44
User: hackerb9
Functions: egrep sort sudo
2

Comcast is an ISP in the United States that has started hijacking DNS requests as a "service" for its customers. For example, in Firefox, one used to be able to do a quick "I'm Feeling Lucky" Google search by typing a single word into the URL field, assuming the word is not an existing domain when surrounded by www.*.com. Comcast customers never receive the correct NX (non-existent domain) error from DNS. Instead, they are shown a page full of advertising. There is a way to "opt out" from their service, but that requires having the account password and the MAC address of your modem handy. For me, it was easier just to set static DNS servers. But the problem is, which ones to choose? That's what this command answers. It'll show you the three _non-hijacked_ Comcast DNS servers that are the shortest distance away.

Perhaps you don't have Comcast (lucky you!), but hopefully this command can serve as an example of using netselect to find the fastest server from a list. Note that, although this example doesn't show it, netselect will actually perform the uniq and DNS resolution for you.

Requires: netselect, curl, sort, uniq, grep

dpkg -l | grep ^rc | awk '{print $2}' | sudo xargs dpkg -P