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

Commands using sudo from sorted by
Terminal - Commands using sudo - 426 results
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
2

# 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
0

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

Example:

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

else

echo apt is up to date

fi

}

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
0

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
-2

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
1

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
1

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
sudo bash -c "> /var/log/httpd/access_log"
for i in chmod chown; do sudo "$i" --reference=/home/user/copyfromfile /tmp/targetfile; done
2014-08-28 15:08:32
User: zlemini
Functions: chmod sudo
2

Copy both perms and owner group from one file to another.

sudo pip install rainbowstream && rainbowstream -iot
2014-08-20 06:45:16
User: DTVD
Functions: install sudo
0

Rainbow Stream is a smart and nice Twitter client on terminal.

Almost everything you can do with a GUI application can be done, even viewing an image.

- Tab-autocomplete, history browsing

- Beautiful built-in themes and custom configuration support

- Tweet's images directly on your terminal.

sudo dpkg -P $(dpkg -l yourPkgName* | awk '$2 ~ /yourPkgName.*/ && $1 ~ /.i/ {print $2}')
2014-08-06 22:40:32
User: wejn
Functions: awk sudo
Tags: dpkg purge
0

Recently in Debian Wheezy the dpkg command refuses to work with wildcards, so this is the one-liner alternative. (alternative to #13614)

sudo restart lightdm
sudo dpkg -P $(sudo dpkg -l yourPkgName* | awk '$2 ~ /yourPkgName.*/' | awk '$1 ~ /.i/' | awk '{print $2}')
2014-08-02 18:14:02
User: woohoo
Functions: awk sudo
Tags: dpkg purge
0

Recently in Debian Wheezy the dpkg command refuses to work with wildcards, so this is the one-liner alternative.

sudo bash -c "cd /PATH/TO/THE/DIRECTORY;bash"
2014-07-28 20:20:04
User: Zath
Functions: bash sudo
0

Change current working directory with root permissions.

Place this snippet in your .bashrc to add a new "sudocd" command:

function sudocd { sudo bash -c "cd $1;bash" }

Usage: sudocd DIRECTORY

Please note that if you will use this command to cd into directories with the permissions allowing only root to be in them, you will have to use sudo as a prefix to every command that changes/does something in that directory (yes, even ls).

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
sudo apt-get install msttcorefonts