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.

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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Commands using command from sorted by
Terminal - Commands using command - 52 results
command systemctl --no-page --no-legend --plain -t service --state=running
command ${MYVAR:+--someoption=$MYVAR}
2015-11-04 19:47:24
User: pdxdoughnut
Functions: command

See "Parameter Expansion" in the bash manpage. They refer to this as "Use Alternate Value", but we're including the var in the at alternative.

touch .tardis; the command ; find . -newer .tardis; rm .tardis;
2015-10-15 19:18:54
User: BeniBela
Functions: command find rm touch

This lists all files modified after calling some command using a temporal anchor.

command foo bar | sudo tee /etc/write-protected > /dev/null
any command | sed "s/^/\[`date +"%Y%m%d%H%M%S"`]/"
any command | while read line; do echo "[`date -Iseconds`] $line"; done
2014-02-07 22:27:29
User: ayosec
Functions: command echo read

Useful to add a timestamp to every line printed to stdout.

You can use `-Ins` instead of `-Iseconds` if you want more precision.

command -v <command>
ssh() { [ $TERM == screen ] && (screen -X title "${1##*@}"; command ssh "$@"; screen -X title '';exit;) || command ssh "$@"; }
2013-06-03 12:31:05
User: djkadu
Functions: command screen ssh

By adding this to your bashrc, when SSH'ing to a server while screen is active it will change the window tittle to the name of the server you going to.

sudo apt-get <apt-get command and options> --print-uris -qq | sed -n "s/'\([^ ]\+\)' \([^ ]\+\) \([^ ]\+\) MD5Sum:\([^ ]\+\)/wget -c \1/p" > dowload_deb_list.txt
command 3>&1 1>&2 2>&3 | tee -a file
2012-10-30 15:40:08
User: netkill
Functions: command tee

Appends output to the file, some systems require the -a to do this.

command 3>&1 1>&2 2>&3 | tee file
2012-10-30 10:53:21
User: hute37
Functions: command tee

taken from



What does it mean?

The redirection operator n>&m makes file descriptor n to be a copy of file descriptor m. So, whe are:

- Opening a new file descriptor, 3, that is a copy of file descriptor 1, the standard output;

- Making file descriptor 1 a copy of file descriptor 2, the standard error output;

- Making file descriptor 2 to be a copy of file descriptor 3 (the "backup" of the standard output)

in a short: we swapped the standard output and the standard error output.


vim -p $(complicated command to list the files you want)
2012-09-28 10:18:30
Functions: command vim
Tags: vim,xargs

see: https://groups.google.com/forum/?fromgroups=#!topic/vim_use/e3Er8x_P8jg

cd () { command cd $1 && ls ; }
func "*" call command run "uname -i"
2012-07-23 13:32:32
User: tduvally
Functions: command

Using "func" to run any command and receive output from all your systems. Default output from func is normally meant for further script parsing, but is generally readable. This example shows system arch, but any command can be used and will run as typed.

command <<< word
2012-02-29 03:14:54
User: adeverteuil
Functions: command
Tags: bash stdin

Don't do this:

echo word | command

Using a bash "here strings" and "here documents" look leeter than piping echo into the command. Also prevents subshell execution. Word is also expanded as usual.

command > >(tee stdout.log) 2> >(tee stderr.log >&2)
command W :execute ':silent w !sudo tee % > /dev/null' | :edit!
2011-10-06 20:37:54
Functions: command tee
Tags: vim sudo tee

Calls sudo tee like all the other lines, but also automatically reloads the file.

Optionally you can add

command Wq :execute ':W' | :q


command WQ :Wq

to make quitting easier

command -v bash
2011-09-26 10:17:41
User: atoponce
Functions: command
Tags: which command

it is generally advised to avoid using which(1) whenever possible. which(1) is usually a csh(1) script, or sometimes a compiled binary. It's output is highly variable from operating system to operating system, so platform independent scripts could become quite complicated with the logic. On HP-UX 10.20, for example, it prints "no bash in /path /path /path ..."; on OpenBSD 4.1, it prints "bash: Command not found."; on Debian (3.1 through 5.0 at least) and SuSE, it prints nothing at all; on Red Hat 5.2, it prints "which: no bash in (/path:/path:...)"; on Red Hat 6.2, it writes the same message, but on standard error instead of standard output; and on Gentoo, it writes something on stderr. And given all these differences, it's still variable based on your shell. This is why POSIX is king. See http://mywiki.wooledge.org/BashFAQ/081 for more ways on avoiding which(1).

ps ewwo command PID | tr ' ' '\n' | grep \=
myreadlink() { [ ! -h "$1" ] && echo "$1" || (local link="$(expr "$(command ls -ld -- "$1")" : '.*-> \(.*\)$')"; cd $(dirname $1); myreadlink "$link"; }
2011-09-13 11:02:27
User: keymon
Functions: cd command dirname echo ls

This is a equivalent to the GNU ' readlink' tool, but it supports following all the links, even in different directories.

An interesting alternative is this one, that gets the path of the destination file

myreadlink() { [ ! -h "$1" ] && echo "$1" || (local link="$(expr "$(command ls -ld -- "$1")" : '.*-> \(.*\)$')"; cd $(dirname $1); myreadlink "$link" | sed "s|^\([^/].*\)\$|$(dirname $1)/\1|"); }
command >&-
sudo lsof -rc command >> /tmp/command.txt
2011-08-03 20:19:53
User: zlemini
Functions: command sudo

Run this before you run a command in order to see what the command does as it starts.

The -c flag is useful here as the PID is unknown before startup.

All config files, libraries, logs, ports, etc used by the command as it starts up, (and shuts down) will be captured at 1s intervals and written to a file.

Useful for debugging etc.

cd() { if [ -n "$1" ]; then [ -f "$1" ] && set -- "${1%/*}"; else [ -n "$CDDIR" ] && set -- "$CDDIR"; fi; command cd "$@"; }
2011-06-24 08:48:13
User: flatcap
Functions: cd command set
Tags: cd test set

Move efficiently between directories.


This command adds a couple of extra features to cd, without affecting normal use.

CDPATH use is also unaffected. It introduces and environment variable CDDIR which is used as an alternate home directory.


Note: I don't want to alter $HOME because then all my dot files will move.




cd dir

Change directory to "dir" (using CDPATH if necessary)


cd dir/file.txt

Change directory to "dir" (containing folder of "file.txt")

This allows you to cut'n'paste, or use


CDDIR is unset


Change directory to $HOME




Change directory to /home/flatcap/work


For convenience, put the command, and the following, in your .bashrc or .bash_profile

export CDDIR="/home/flatcap/work"

alias cdd="CDDIR=$(pwd)"

command & echo $!
2011-06-08 18:16:38
User: Mahrud
Functions: command echo

Actually $! is an internal variable containing PID of the last job in background.

More info: http://tldp.org/LDP/abs/html/internalvariables.html#PIDVARREF

Using $! for job control:

possibly_hanging_job & { sleep ${TIMEOUT}; eval 'kill -9 $!' &> /dev/null; }
awk '{command="echo "$2"|md5sum" ;command | getline $2; close(command);sub(/[[:blank:]].*/,"",$2); print $0}'