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 - 415 results
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
sudo apt-get install p7zip-rar p7zip-full unace unrar zip unzip sharutils rar uudeview mpack arj cabextract file-roller
sudo apt-get install libavcodec-extra
2014-06-03 16:28:22
Functions: install sudo
2

Install the unrestricted version of libavcodec . It will keep away from any issues or missing codecs in video editors or transcoders. Install unrestricted version of libavcodec by the command.

sudo kill -9 $( ps -e | grep Xorg | awk '{ print $1 }' )
2014-06-01 22:43:32
Functions: awk grep kill ps sudo
0

There are times when a X Window server hangs. When this happens, you can log in on a terminal and kill the Xorg process (i.e. the X Server). This one line command will do the trick.

sudo efibootmgr --bootnext `efibootmgr | sed -n "s/^Boot\([0-9]\{4\}\)\* Windows Boot Manager$/\1/p"` && reboot
2014-05-31 11:51:52
User: moneytoo
Functions: sed sudo
0

Quickly reboot directly to Windows (or any other operating system) without the need to enter BIOS/UEFI or boot loader (if any). It's valid for one boot only, no persistent changes to boot priorities.

sudo ntpdate serverip
export NEWUSER=newuser; mkdir /home/$NEWUSER; useradd -d /home/$NEWUSER -s /bin/bash -G sudo $NEWUSER; passwd $NEWUSER
for i in $(getent group|cut -d: -f1); do sudo usermod -a -G "$i" $USER; done
sudo add-apt-repository ppa:PPA_TO_ADD
2014-04-24 20:02:39
User: KlfJoat
Functions: sudo
-1

There is no longer a need to add PGP keys for Ubuntu Launchpad PPA's.

The add-apt-repository command creates a new file for the PPA in /etc/sources.list.d/ then adds the PPA's keys to the apt keyring automatically. No muss, no fuss.

sudo /sbin/route add -host 192.168.12.50 -interface ppp0
2014-04-13 00:17:53
User: jifilis
Functions: sudo
Tags: unix VPN route
0

In this example, 192.168.12.50 is the host that should be routed via the VPN and "ppp0" is the name of the VPN network interface (ifconfig shows you the list of network interfaces). Can be a IP or domain name.

(mountpoint -q "/media/mpdr1" && df /media/mpdr1/* > /dev/null 2>&1) || ((sudo umount "/media/mpdr1" > /dev/null 2>&1 || true) && (sudo mkdir "/media/mpdr1" > /dev/null 2>&1 || true) && sudo mount "/dev/sdd1" "/media/mpdr1")
2014-04-12 11:23:21
User: tweet78
Functions: df mkdir mount sudo umount
20

In my example, the mount point is /media/mpdr1 and the FS is /dev/sdd1

/mountpoint-path = /media/mpdr1

filesystem=/dev/sdd1

Why this command ?

Well, in fact, with some external devices I used to face some issues : during data transfer from the device to the internal drive, some errors occurred and the device was unmounted and remounted again in a different folder.

In such situations, the command mountpoint gave a positive result even if the FS wasn't properly mounted, that's why I added the df part.

And if the device is not properly mounted, the command tries to unmount, to create the folder (if it exists already it will also work) and finally mount the FS on the given mount point.

sudo tcpdump -i wlan0 -n ip | awk '{ print gensub(/(.*)\..*/,"\\1","g",$3), $4, gensub(/(.*)\..*/,"\\1","g",$5) }' | awk -F " > " '{print $1"\n"$2}'
echo $(sudo lshw -businfo | grep -B 1 -m 1 $(df "/path/to/file" | tail -1 | awk '{print $1}' | cut -c 6-8) | head -n 1 | awk '{print $1}' | cut -c 5- | tr ":" "-") | sudo tee /sys/bus/usb/drivers/usb/unbind
2014-04-06 12:06:29
User: tweet78
Functions: awk cut df echo grep head sudo tail tee tr
29

You have an external USB drive or key.

Apply this command (using the file path of anything on your device) and it will simulate the unplug of this device.

If you just want the port, just type :

echo $(sudo lshw -businfo | grep -B 1 -m 1 $(df "/path/to/file" | tail -1 | awk '{print $1}' | cut -c 6-8) | head -n 1 | awk '{print $1}' | cut -c 5- | tr ":" "-")

for i in `sudo /sbin/fdisk -l |grep Disk |grep dev |awk '{ print $2 }' |sed s/://g` ; do sudo /usr/bin/dd if=/dev/urandom of=$i bs=8M & done
2014-03-16 12:04:59
User: aimana007
Functions: awk grep sed sudo
Tags: bash Linux
1

This command will use the fdisk utility to find all block devices on your system, and overwrite them with data from the /dev/urandom non-blocking random number generator.

CAUTION: This will irrevocably erase EVERY SINGLE physical block storage device visible to the fdisk utility, including plugged USB devices, RAID sets, LVM, etc.

sudo lshw -html > /tmp/hardware.html && xdg-open /tmp/hardware.html
2014-03-08 10:40:21
User: Sadi
Functions: sudo
0

entering this command as root may give more complete results, creating a tmp file, and immediately opening the file might be more useful

sudo update-grub
2014-02-27 19:50:25
User: Anshik
Functions: sudo
-5

sudo gedit /etc/default/grub

This would open the Grub configuration file. In this file we have to edit the line

GRUB_CMDLINE_LINUX=""

to

GRUB_CMDLINE_LINUX="acpi_backlight=vendor"

sudo lsof -i -n -P | grep TCP
sudo chmod --reference=Referenz.foo Datei.foo