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





Commands using ls from sorted by
Terminal - Commands using ls - 463 results
grep -oP '"url":"\K[^"]+' $(ls -t ~/.mozilla/firefox/*/sessionstore.js | sed q)
2009-12-09 20:34:32
User: sputnick
Functions: grep ls sed

Require "grep -P" ( pcre ).

If you don't have grep -P, use that :

grep -Eo '"url":"[^"]+' $(ls -t ~/.mozilla/firefox/*/sessionstore.js | sed q) | cut -d'"' -f4
ls -l `locate your_search_here`
2009-11-27 05:53:46
User: tjcertified
Functions: ls

This command lists extended information about files, i.e. whether or not it is a true file or link, who owns it, etc. without having to 'ls' from the specific directory. If you know the filename, but not the location, this helps with finding other information about the file. It can be truncated by creating an alias for 'ls -l'. The sample output shows difference in regular locate vs. ls + locate.

ls -la /dev/disk/by-id/usb-*
2009-11-25 16:02:06
User: casidiablo
Functions: ls

This command lists the names of your USB devices connected and what file in /dev they are using. It's pretty useful if you don't have an automount option in your desktop or you don't have any graphical enviroment.

ls *[^p][^a][^t]* ; # or shopt -s extglob; ls !(*pattern*)
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.