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.

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





All commands from sorted by
Terminal - All commands - 12,274 results
find . -type f -name '*.sh' -print | cpio -o | gzip >sh.cpio.gz
2011-12-21 21:13:29
User: djangofan
Functions: cpio find gzip

Archive all .sh files in a directory into a gzip archive.

:autocmd BufNewFile *.sh,*.bash 0put =\"#!/bin/bash\<nl># -*- coding: UTF8 -*-\<nl>\<nl>\"|$
2012-02-06 08:28:05
User: jlaunay
Tags: bash

or add this line to your ~/.vimrc if using vim

lsgrp() { read GID USERS <<< "$(grep "^$1:" /etc/group | cut -d: -f3,4 | tr ':,' ' ')" ; echo -e "${USERS// /\n}" | egrep -v "^($1)?$" ; egrep :[0-9]+:$GID: /etc/passwd | cut -d: -f1 ; }
2012-03-16 09:57:33
User: livibetter
Functions: cut echo egrep read

I can't find the lid command on my system, there is also another complied program: http://xyne.archlinux.ca/projects/lsgrp/

ls -tl --time-style=full-iso
db2 connect to STGNSY3; db2 -tvf source_CUST_DIM_DELTA.sql > kk.out
find . -name vmware-*.log -exec rm -i {} \;
while curl -dsL example.com 2>&1 | grep 503;do sleep 8;done;echo server up
for a in $(find . -maxdepth 1 -name "*.mp4" -type f -printf "%f\n" | rev | cut -d '.' -f2- | rev | sort -u); do if [ ! -f "$a.mp3" ]; then avconv -i "$a."* -vn -ab 128 "$a.mp3"; fi done
2014-06-27 05:13:53
User: adanisch
Functions: cut find rev sort

Good for when you download youtube videos and want the mp3 for your mp3 player.

jstat -gc [jvmpid]
rename 's/.*/[it]$&/' *.pdf
for img in $( ls *.CR2 ); do convert $img $img.jpg; done
printf "%02u " {3..20}; echo
2009-09-18 18:48:41
User: Escher
Functions: printf
Tags: bash strings

emulates bash4's "echo {03..20}"

Uses bash3 builtin function printf

find -type f -regex ".*\.\(js\|php\|inc\|htm[l]?\|css\)$" -exec grep -il 'searchstring' '{}' +
dos2unix <file>
sudo pacman -Scc
2011-03-20 20:57:42
User: ibnarrashid
Functions: sudo

Clears the package cache of all packages, installed and uninstalled packages. Do NOT USE if you might want to downgrade a package later.

cd ~/ruby/project_a ; find . -name "*profile*" -exec pax -rw {} ~/ruby/project_b/ \;
2011-11-10 21:18:15
User: cbpowell
Functions: cd find pax

Let's say you have a set of files in tree A that you want duplicated to tree B while preserving their directory structure / hierarchy. (For example, you might want to copy your 'profile' model/views/controller from one Rails application to another.) The "pax" command will copy all matching files to the destination while creating any necessary directories.

diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://8000000`
2012-03-16 23:51:17
User: centro

Creates a 4GB ramdisk on OSX. Use when you need high speed operations and have plenty of RAM

sudo find . -name "*.csv" | xargs /bin/rm
2012-08-29 11:38:37
User: defc0n1
Functions: find sudo xargs

In case you ever got to many arguments using rm to delete multiple files matching a pattern this will help you

echo "template file: ";read tpl;echo "new file(s separated w. space):"; read fl;touch $fl;find $fl -exec cp -ap $tpl "{}" \;
2013-03-08 10:00:36
User: knoppix5
Functions: cp echo find read touch

make a bunch of files with the same permissions, owner, group, and content as a template file

(handy if you have much to do w. .php, .html files or alike)

for gz in `find . -type f -name '*.gz' -print`; do f=`basename $gz .gz` && d=`dirname $gz` && echo -n `ls -s $gz` "... " && gunzip -c $gz | bzip2 - -c > $d/$f.bz2 && rm -f $gz && echo `ls -s $d/$f.bz2`; done
2014-03-13 08:36:24
User: pdwalker
Functions: bzip2 echo gunzip rm

- recompresses all gz files to bz2 files from this point and below in the directory tree

- output shows the size of the original file, and the size of the new file. Useful.

- conceptually easier to understand than playing tricks with awk and sed.

- don't like output? Use the following line:

for gz in `find . -type f -name '*.gz' -print`; do f=`basename $gz .gz` && d=`dirname $gz` && gunzip -c $gz | bzip2 - -c > $d/$f.bz2 && rm -f $gz ; done
echo -e "a\na\nb\nc\nd" | awk '{x[$0]++}END{for (z in x){if(x[z]==1){print z}}}'
git rev-list --all|tail -n1|xargs git show|grep -v diff|head -n1|cut -f1-3 -d' '
gst-launch-0.10 v4l2src ! ffmpegcolorspace ! warptv ! ffmpegcolorspace ! autovideosink
2009-09-18 18:56:35
User: Escher

in place of warptv use shagadelictv, edgetv, agingtv, dicetv, vertigotv, revtv or quarktv (see 'gst-inspect-0.10 effectv'. Requires gstreamer-plugins-good (or gstreamer0.10-plugins-good ).

For slow webcams use something like

gst-launch-0.10 v4l2src ! video/x-raw-yuv,width=320,height=240 ! ffmpegcolorspace ! warptv ! ffmpegcolorspace ! autovideosink


For basic webcam view via gstreamer use

gst-launch-0.10 v4l2src ! autovideosink
addman () { export MANPATH=`find $1 -xdev -type d -name man -printf %p:`${MANPATH}; }
2010-06-12 17:47:20
User: zoomgarden
Functions: export man
Tags: man function

Prepends paths containing man directories to your MANPATH variable for the given top level directory. If you build or install software with non-standard documentation locations, you can just add them to your MANPATH with this little function. -xdev prevents crossing filesystem boundaries when searching for man dirs.