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:



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.

Top Tags



Commands using ls from sorted by
Terminal - Commands using ls - 459 results
ls | grep -vi pattern
ls -F | sed -n 's/@$//p'
ls -l `ls -l |awk '/^l/ {print $8}'`
2009-11-23 16:02:18
User: yooreck
Functions: awk ls

ls -l may vary depending on operating system, so "print $8" may have to be changed

ls -d .*
ls -l | awk '$5 > 1000000' | sort -k5n
for f in $(ls *.xml.skippy); do mv $f `echo $f | sed 's|.skippy||'`; done
2009-11-19 21:36:26
User: argherna
Functions: ls mv sed
Tags: sed ls mv for

For this example, all files in the current directory that end in '.xml.skippy' will have the '.skippy' removed from their names.

video=$(ls /tmp | grep -e Flash\w*); ffmpeg -i /tmp/$video -f mp3 -ab 192k ~/ytaudio.mp3
function lsless() { ls "$@" | less; }
2009-11-13 17:28:06
User: argherna
Functions: ls
Tags: less ls function

This is useful for paging through long directories, mulitple directories, etc. I put this in my ~/.bash_aliases file and alias 'lsl' to it.

slice(){ cut -c$((${#1}+1))-; }; ls -l | slice "-rw-r--r--"
slice="-rw-r--r-- "; ls -l | cut -c $(echo "$slice" | wc -c)-
ls -al
2009-11-12 12:27:32
User: eastwind
Functions: ls

it does provide much more information , the owner , group , the size in byte , and the last modified time a file or directory was

ls -al : list all in long format

ls -a | egrep "^\.\w"
2009-11-11 18:19:56
User: kulor
Functions: egrep ls
Tags: egrep ls dotfiles

trying to copy all your dotfiles from one location to another, this may help

ls -1rSA | tail
2009-10-27 15:34:59
User: rbossy
Functions: ls

This will only work on files since ls won't tell the size of a directory contents.

Note that the first switch is the digit one, not the letter ell.

pushd .> /dev/null; cd /; for d in `echo $OLDPWD | sed -e 's/\// /g'`; do cd $d; echo -n "$d "; ls -ld .; done; popd >/dev/null
2009-10-22 12:32:11
User: syladmin
Functions: cd echo ls sed
Tags: permissions

Can easily be scripted in order to show permission "tree" from any folder. Can also be formated with

column -t

{ pushd .> /dev/null; cd /; for d in `echo $OLDPWD | sed -e 's/\// /g'`; do cd $d; echo -n "$d "; ls -ld .; done; popd >/dev/null ; } | column -t

from http://www.commandlinefu.com/commands/view/3731/using-column-to-format-a-directory-listing

ls | xargs -n1 gzip
a=($(ls *html)) && a=${a[$(expr ${#a[@]} - 1)]} && rm $a
2009-10-12 16:40:06
Functions: expr ls rm

plays with bash arrays. instead of storing the list of files in a temp file, this stores the list in ram, retrieves the last element in the array (the last html file), then removes it.

ls -d */
2009-10-08 22:07:22
User: brianmuckian
Functions: ls

-d: list directory entries instead of contents, and do not dereference symbolic links

ls -F|grep /
2009-10-08 16:35:15
User: romulusnr
Functions: grep ls

No need for -l and the output can be sent directly into another function expecting directory names.

(printf "PERMISSIONS LINKS OWNER GROUP SIZE MONTH DAY HH:MM PROG-NAME\n" \ ; ls -l | sed 1d) | column -t
ls -alh #mycomment
2009-10-06 13:55:06
Functions: ls

Comments can be used directly on the command line so I can save in the history a brief description of what command does.

ls [FILENAME] | xargs openssl sha1
2009-10-03 02:05:43
User: m00dimus
Functions: ls xargs

List files and pass to openssl to calculate the hash for each file.

ls -A
ls .??*
2009-09-29 14:40:37
User: Paula
Functions: ls

Works 99.9% of the time; so far never required a more complex expression in manual input.

ls .[!.]*
2009-09-29 13:50:13
User: danam
Functions: ls

Although rm is protected against it, there are many commands that would wreak havoc on entering the obvious ".*" to address "dot-files". This sweet little expression excludes the dirs "." and ".." that cause the problems.

enscript jrandom.txt -o - | ps2pdf - ~/tmp/jrandom.pdf (from file) or: ls | enscript -o - | ps2pdf - ~/tmp/ls.pdf (from stdout)