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 by totti from sorted by
Terminal - Commands by totti - 87 results
lsblk | grep <mountpoint>
proot -r /media/user/ubuntu12.10/ cat /etc/motd
2014-01-21 07:50:22
User: totti
Functions: cat
2

PRoot is a user-space implementation of chroot, mount --bind, and binfmt_misc. This means that users don't need any privileges or setup to do things like using an arbitrary directory as the new root filesystem, making files accessible somewhere else in the filesystem hierarchy, or executing programs built for another CPU architecture transparently through QEMU user-mode. Also, developers can use PRoot as a generic Linux process instrumentation engine thanks to its extension mechanism, see CARE for an example. Technically PRoot relies on ptrace, an unprivileged system-call available in every Linux kernel.

https://github.com/cedric-vincent/PRoot

_autoOptions() { local cur=${COMP_WORDS[COMP_CWORD]} COMPREPLY=( $(compgen -W "--fooOption --barOption -f -b" -- $cur) ) ;}; complete -F _autoOptions autoOptions
read -N1
2013-10-10 10:09:43
User: totti
Functions: read
Tags: read user
6

Usage exaple cmd

echo 'Sure to continue ??'; read -n1 choi; if [ "$choi" = 'y' ] || [ "$choi" = 'Y' ]; then echo -e '\nExecuting..'; else echo 'Aborted'; fi
printTextInColorRed () { echo -e '\033[01;31m\033[K'"$@"'\033[m\033[K' ;} ## print text/string in color red
2013-08-28 10:06:59
User: totti
Functions: echo
1

eg:

printTextInColorRed foo bar

foo bar [in red color]

rsync -a --append source-file destination
convert_path2uri () { echo -n 'file://'; echo -n "$1" | perl -pe 's/([^a-zA-Z0-9_\/.])/sprintf("%%%.2x", ord($1))/eg' ;} #convert2uri '/tmp/a b' ### convert file path to URI
2013-07-01 08:54:45
User: totti
Functions: echo file perl
Tags: encoding PATH url
1

Really helpfull when play with files having spaces an other bad name. Easy to store and access names and path in just a field while saving it in a file.

This format (URL) is directly supported by nautilus and firefox (and other browsers)

aria2c --max-download-limit=100K file.metalink
2013-03-26 16:05:52
User: totti
0

Throttle download speed

aria2c --max-download-limit=100K file.metalink

Throttle upload speed

aria2c --max-upload-limit=100K file.torrent
axel --max-speed=x
2013-03-26 16:00:43
User: totti
Tags: download speed
2

Axel

--max-speed=x, -s x

You can specify a speed (bytes per second) here and Axel will

try to keep the average speed around this speed. Useful if you

don?t want the program to suck up all of your bandwidth.

gocr -i ~/Screenshot.png
2013-02-28 07:38:13
User: totti
-3

Image to text converter.

Convert your scanned book in image format like .png, .jpg into editable text format.

OCR ==> Optical Code Reader

sudo apt-get <apt-get command and options> --print-uris -qq | sed -n "s/'\([^ ]\+\)' \([^ ]\+\) \([^ ]\+\) MD5Sum:\([^ ]\+\)/wget -c \1/p" > dowload_deb_list.txt
dbus-send --session --print-reply --dest="org.gnome.SettingsDaemon" /org/gnome/SettingsDaemon/Power org.gnome.SettingsDaemon.Power.Screen.SetPercentage uint32:30
xrandr --output LVDS1 --brightness 0.4
2013-02-04 11:00:16
User: totti
Tags: brightness
0
xrandr --output <outputname> --brightness <value>

If the driver of your graphics card supports it, then you can use xrandr.

The following command lists the current configuration:

xrandr --current --verbose

If you want to change the configuration of an output, then you need the name of the output. This name is part of the output of xrandr --current, for example LVDS1.

The brightness can be changed like this:

xrandr --output <outputname> --brightness 0.8

Gamma:

xrandr --output <outputname> --gamma 0.5:1.0:1.0
import -window root -quality 98 screenshot.png
blacklist usb_storage >> /etc/modprobe.d/blacklist.conf
2013-02-01 09:38:43
User: totti
Tags: block usb
3

Some times you may ban usb to protect thefting of your personal data.

Blacklist the usb_storage module by adding blacklist usb_storage to /etc/modprobe.d/blacklist.conf.

To load the module manually,

sudo modprobe usb_storage.
fatattr -h <file>
2013-02-01 09:25:18
User: totti
Tags: hide FAT
0

Syntax is

fatattr [+-hsra] [files]

The letters are...

h hidden

s system

r read only

a archive

echo 'foo' | tee >(wc -c) >(grep o) >(grep f)
2013-01-31 09:54:18
User: totti
Functions: echo grep tee wc
Tags: tee output input
5

Output of a command as input to many

readlink -f /proc/$pid/exe
diffprocess () { diff <($*) <(sleep 3; $*); }
2013-01-25 08:46:41
User: totti
Functions: diff sleep
1

Execute a process or list of commands in the given interval and output the difference in output.

sudo nethogs eth0
xprop | awk '/PID/ {print $3}'
notify-send " " -i notification-display-brightness-low -h int:value:50 -h string:x-canonical-private-synchronous:brightness
2013-01-18 14:24:40
User: totti
Tags: notify custom
1

Brightness indicator to be used in scripts that adjust brightness [especially sys that doesn't support automatically]

xbacklight -10%
sudo pm-hibernate
dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend
2013-01-15 18:47:21
User: totti
1
dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend