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.

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:



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!

Top Tags





Commands using sudo from sorted by
Terminal - Commands using sudo - 435 results
sudo aa-complain /etc/apparmor.d/usr.bin.chromium-browser
2015-09-30 18:56:28
User: lordtoran
Functions: sudo

If AppArmor is installed with all profiles enforced, Chromium may refuse to start, printing a "failed to launch zygote process" error on stderr.

This command switches the Chromium profile from enforce to complain mode, effectively un-sandboxing the browser, but depending on the system setup it may be a smaller deal than a nonfunctional application.

sudo sh -c "aptitude update; aptitude -DrVWZ full-upgrade; aptitude autoclean; exit"
2015-09-28 23:48:05
User: lordtoran
Functions: sh sudo

This has been my "sysupgrade" alias since ca. 2006, first used on Debian Sid, then Sabayon, and it still does its duty on Mint nowadays without breaking stuff.

sudo sh -c "rm /usr/share/mime/packages/kde.xml && update-mime-database /usr/share/mime"
echo apt-get\ {update,-y\ upgrade}\ \&\& true | sudo bash
2015-09-22 00:48:26
User: alecthegeek
Functions: echo sudo true

it's nice to be able to use the command `ls program.{h,c,cpp}`. This expands to `ls program.h program.c program.cpp`. Note: This is a text expansion, not a shell wildcard type expansion that looks at matching file names to calculate the expansion. More details at http://www.linuxjournal.com/content/bash-brace-expansion

I often run multiple commands (like apt-get) one after the other with different subcommands. Just for fun this wraps the whole thing into a single line that uses brace expansion.

sudo lsof -nP | awk '/deleted/ { sum+=$8 } END { print sum }'
2015-09-19 00:45:23
Functions: awk sudo sum

A potential source of a full filesystem are large files left open but have been deleted. On Linux, a file may be deleted (removed/unlinked) while a process has it open. When this happens, the file is essentially invisible to other processes, but it still takes on physical space on the drive. Tools like du will not see it.

sudo apt-get remove --purge $(dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d')
sudo sh -c 'printf "[SeatDefaults]\nallow-guest=false\n" >/usr/share/lightdm/lightdm.conf.d/50-no-guest.conf'; sudo sh -c 'printf "[SeatDefaults]\nallow-guest=false\n" >/usr/share/lightdm/lightdm.conf.d/50-guest-wrapper.conf'
2015-08-31 18:12:21
User: andregyn62
Functions: sh sudo

This command will disable a guest user logon, this user don't have password to login in the system.

sudo apt-get install ufraw
2015-08-20 20:37:00
User: dnlcorrea
Functions: install sudo

Convert RAW files (eg. .CR2) to JPEGs, PNGs and whatnot.

sudo lsof | egrep 'w.+REG' | awk '{print $10}' | sort | uniq -c | sort -n
2015-08-18 14:09:02
User: kennethjor
Functions: awk egrep sort sudo uniq

This command run fine on my Ubuntu machine, but on Red Hat I had to change the awk command to `awk '{print $10}'`.

sudo docker rm $(docker ps -a -q); sudo docker rmi $(docker images -q)
2015-05-20 12:34:40
User: lpalgarvio
Functions: ps rm sudo

# Delete all containers

docker rm $(docker ps -a -q)

# Delete all images

docker rmi $(docker images -q)

if [[ $(expr $(date +%s) - $(stat -c %X /var/lib/apt/periodic/update-success-stamp)) -gt 86400 ]]; then sudo apt-get update fi
2015-05-12 14:45:11
User: gargolito
Functions: date expr stat sudo

I have this in my .bash_aliases and call it before running apt-get install or apt-get upgrade


alias apt-install='apt-update; apt-get install'

alias apt-upgrade='apt-update; apt-get upgrade'

function apt-update () {

if [[ $(expr $(date +%s) - $(stat -c %X /var/lib/apt/periodic/update-success-stamp)) -gt 86400 ]]; then

sudo apt-get update


echo apt is up to date



sudo mysql -sNe 'show tables like "PREFIX_%"' DBNAME | xargs sudo mysqldump DBNAME > /tmp/dump.sql
sudo npm cache clean -f | sudo npm install -g n | sudo n stable
sudo mtr -s 1472 -B 0 -oLDRSWNBAWVJMXI <ip address>
2015-04-24 13:46:36
User: bort
Functions: sudo

Uses packet size 1472, padded with zeroes, and shows more columns with jitter statistics to the right. This is a greatly improved version of traceroute.

sudo lsof -i -n | grep sshd | grep sshuser | grep :[PORT-RANGE] | grep -v IPv6 | awk -F\: '{print $2}' | grep -v http | awk -F" " '{print $1}'
2015-04-09 15:41:11
User: das_shark
Functions: awk grep sshd sudo

gets network ports

only ones for the sshd service

only logged in a specific user (changed for public posting)

only in a specific localhost:port range

not IPv6

Only the part of the response after the ":" character

Only the part of the response before the 1st space

Output is just the rssh port

ssh user@server sudo date -s @`( date -u +"%s" )`
sudo apt-get purge $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')")
sudo sh -c 'echo 1 > /proc/sys/kernel/dmesg_restrict'
2015-03-13 20:54:45
User: Blacksimon
Functions: sh sudo

Linux offers an interesting option to restrict the use of dmesg. It is available via /proc/sys/kernel/dmesg_restrict.

You can check the status with:

cat /proc/sys/kernel/dmesg_restrict

Alternatively you can use sysctl:

sudo sysctl -w kernel.dmesg_restrict=1

To make your change persistent across reboot, edit a fille in /etc/sysctl.d/.

sudo iptables -A INPUT -m limit --limit 2000/sec -j ACCEPT && sudo iptables -A INPUT -j DROP
2015-03-09 20:16:17
User: qdrizh
Functions: iptables sudo
Tags: iptables

VPS server hosts suspect DOS attack if PPS is too high. This limits packets at the interface level. Do "sudo apt-get install iptables-persistent" to make persistent, or, if you already have, reconfigure with "sudo dpkg-reconfigure iptables-persistent"

command foo bar | sudo tee /etc/write-protected > /dev/null
sudo gpg --refresh-keys; sudo apt-key update; sudo rm -rf /var/lib/apt/{lists,lists.old}; sudo mkdir -p /var/lib/apt/lists/partial; sudo apt-get clean all; sudo apt-get update
sudo netstat -tulpn | grep :8080
python -c "import pip; print(' '.join([x.project_name for x in pip.get_installed_distributions()]))" | xargs sudo pip install -U
sudo hdparm -B 200 /dev/sda
sudo tee /path/to/file < /dev/null