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.


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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.
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

All commands from sorted by
Terminal - All commands - 12,430 results
alias bman='man --html=x-www-browser'
2016-10-23 17:59:47
User: lordtoran
Functions: alias
Tags: man groff
4

An easy alias for opening a manpage, nicely HTML formatted, in your set internet browser.

If you get a "command exited with status 3" error you need to install groff.

xmlstarlet ed -u '//food[calories="650"]/calories' -v "999" simple.xml
id <username> | sed s/' '/'\n'/g | sed s/,/',\n '/g | sed s/'('/' ('/g | sed s/uid/' uid'/g | sed s/gid/' gid'/g | sed s/=/' = '/g
printf -vl "%${COLUMNS:-`tput cols 2>&-||echo 80`}s\n" && echo ${l// /-};
2016-09-25 10:37:20
User: AskApache
Functions: echo printf
4

Unlike other methods that use pipes and exec software like tr or sed or subshells, this is an extremely fast way to print a line and will always be able to detect the terminal width or else defaults to 80. It uses bash builtins for printf and echo and works with printf that supports the non-POSIX `-v` option to store result to var instead of printing to stdout.

Here it is in a function that lets you change the line character to use and the length with args, it also supports color escape sequences with the echo -e option.

function L() { local l=; builtin printf -vl "%${2:-${COLUMNS:-`tput cols 2>&-||echo 80`}}s\n" && echo -e "${l// /${1:-=}}"; }

With color:

L "`tput setaf 3`="

1. Use printf to store n space chars followed by a newline to an environment variable "l" where n is local environment variable from $COLUMNS if set, else it will use `tput cols` and if that fails it will default to 80.

2. If printf succeeds then echo `$l` that contains the chars, replacing all blank spaces with "-" (can be changed to anything you want).

From: http://www.askapache.com/linux/bash_profile-functions-advanced-shell.html http://www.askapache.com/linux/bash-power-prompt.html

aws cloudfront list-distributions | jq -r '.DistributionList | .Items | .[] | .Id + " " + .Aliases.Items[]'
2016-09-19 06:36:59
User: hendry
Tags: aws jq awscli
0

Looking up the id of a CF domain can be painful. Not anymore with this tip.

pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
find . -name '*.desktop' | sed s/[^/]*\.desktop$// | uniq -c | sort -g
2016-09-16 12:22:38
User: T4b
Functions: find sed sort uniq
2

In this case searches for where .desktop files are stored. The resulted is a sorted list of the top directories containing such files.

Xephyr -keybd ephyr,,,xkbmodel=evdev,xkblayout=it -listen tcp -ac -reset -output VGA1 :5
2016-09-12 15:59:07
User: hute37
Tags: X awesome Xephyr
0

# from xfce session to avoid keyboard shortcut clashing

# start xephyr in VGA1 monitor:

Xephyr -keybd ephyr,,,xkbmodel=evdev,xkblayout=it -listen tcp -ac -reset -output VGA1 :5

# then start an xterm locally

export DISPLAY=:5.0

xterm

# and remote ssh (no X fw needed if local tcp with access disablesd (-tcp -ac) => UNSECURE!!!

ssh remote-host

export DISPLAY=notebook:5.0

xrdb -merge ~/.Xresources

xterm -geometry 132x50-0+0

# start awesome

dbus-launch $(which awesome)

dex -a -e Awesome

for y in {1..10}; do for x in {1..10}; do echo -n "| $x*$y=$((y*x)) "; done; echo; done|column -t
2016-09-07 12:31:18
User: lpalgarvio
Functions: column echo
3

The multiplication table for math study

find . -name \*.pyc -delete
curl ipinfo.io
2016-09-04 08:23:25
User: MrTux
18

Return IP information about your external ip address with JSON format

host -t srv _ldap._tcp | sed "s/.*[ ]\([^ ]*\)[.]$/\1/g" | xargs -i ping -c 1 {} | grep -E "(statistics|avg)" | sed "s/^--- \([^ ]*\).*/,\1:/g"|tr -d "\n" | tr "," "\n" | sed "1d;s|^\([^:]*\).*=[^/]*/\([^/]*\).*|\2\t\1|g" |sort -n
2016-09-02 03:26:29
User: glaudiston
Functions: grep host ping sed sort tr xargs
Tags: ldap
2

This command line detect ldap hosts, by mandatory dns entry, then ping them to detect response average. based on ping response average it sorts and print the faster server in first output line

ifconfig | awk -F: '/inet addr:/ { sub(/\.[^.]+$/, "", $2); if (!seen[$2]++ && $2 != "127.0.0") print $2 }'
2016-09-01 14:02:43
User: chrismccoy
Functions: awk ifconfig
Tags: ifconfig awk
3

For machines that have many ip blocks spanning different Class C's, this will show which ones.

tail -v -f $(php -i | grep "^[ \t]*error_log" | awk -F"=>" '{ print $2; }' | sed 's/^[ ]*//g')
2016-08-31 12:13:31
User: paulera
Functions: awk grep sed tail
0

Runs "php -i", filter the error_log location, then watches it using "tail"

curl wttr.in/seville
$ sed "2s/$/ $(sed -n '4p' sound.desktop)/" sound.desktop
2016-08-23 02:50:31
User: pibarnas
Functions: sed
0

Using "", which allow bash commands to be interpreted by sed scripts, I've embedded a sed script in another sed substitution, in case, the 4th line of the file at the end of the second one.

rsync --daemon --port 1234 --no-detach -v --config rsyncd.conf
mv ~/html/*~ ~
2016-08-17 17:28:07
User: pascalv
Functions: mv
Tags: mv html CGI
-6

This prevents access to old CGI code

Print everything after last slash
2016-08-17 07:10:33
User: qdrizh
Functions: last
Tags: sed
0

FQPN - Path = Filename

pip install --prefix $PWD -I pip
2016-08-16 06:02:17
User: yoyoyojomo
Functions: install
4

For subsequent commands in the prefixed path:

PYTHONPATH=$PWD/lib/python*/site-packages ./bin/pip --version
printf '%s-%s-%s-%s\n' $(grep -v "[A-Z]\|'" /usr/share/dict/british | shuf -n 4)
2016-08-15 08:13:10
User: hendry
Functions: grep printf
1

https://xkcd.com/936/ introduced us to what actually is a good password. Here's such an implementation.

Credit: quinq on #suckless

printf "\U$(printf '%x' $((RANDOM%79+128512)) )"
2016-08-11 15:59:59
Functions: printf
Tags: bash emoji
3

This will print a random emoji within the range of 1F600 - 1F64F, which includes all the face emoji.

Obviously, this will only show something meaningful if your terminal can display emoji, but it may be useful in scripts.

This likely requires recent versions of bash

curl -s httpbin.org/ip | jq -r .origin
while true ; do fswebcam -d /dev/video0 -r 1280x1024 -F 15 - | uuencode $(date +\%Y\%m\%d\%H\%M).jpeg | mail -s "Video surveillance" [email protected] ; sleep 300 ; done
2016-08-09 14:22:45
User: pascalv
Functions: date mail sleep true uuencode
2

This takes a picture (with the web cam) every 5 minutes, and send the picture to your e-mail.

Some systems support

mail -a "References: "

so that all video surveillance emails are grouped in a single email thread.

To keep your inbox clean, it is still possible to filter and move to trash video surveillance emails (and restore these emails only if you really get robbed!)

For instance with Gmail, emails sent to [email protected] can be filtered with "Matches: DeliveredTo:[email protected]"

ps auxw | grep -E 'sbin/(apache|httpd)' | awk '{print"-p " $2}' | xargs strace -F
2016-08-04 10:59:58
User: gormux
Functions: awk grep ps strace xargs
Tags: awk grep ps strace
2

Will open strace on all apache process, on systems using sbin/apache (debian) or sbin/httpd (redhat), and will follow threads newly created.