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.

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 - 469 results
ls -S -lhr
2009-04-28 01:28:57
User: rez0r
Functions: ls

This command list and sort files by size and in reverse order, the reverse order is very helpful when you have a very long list and wish to have the biggest files at the bottom so you don't have scrool up.

The file size info is in human readable output, so ex. 1K..234M...3G

Tested with Linux (Red Hat Enterprise Edition)

for img in $( ls *.CR2 ); do convert $img $img.jpg; done
ls /home | head -64 | barcode -t 4x16 | lpr
2009-04-21 22:54:45
User: flux
Functions: head ls
Tags: printing

64 elements max on 16 rows, 4 cols.

GNU Barcode will adapt automagically the width and the eight of your elements to fill the page.

Standard output format is PostScript.

find -type f -printf '%P\000' | egrep -iz '\.(avi|mpg|mov|flv|wmv|asf|mpeg|m4v|divx|mp4|mkv)$' | sort -z | xargs -0 ls -1
ls -la
ls !$
2009-04-07 12:31:06
Functions: ls

Suppose that you had change in a directory like /home/user/mycode/code, and now you need to list it, instead of type entire path again, use ls !$ to recall path and list. Useful with many commands, this is only an example. (In this case, same result can be achivied with ls .)

ls -l | grep ^l
2009-04-02 17:47:36
User: haivu
Functions: grep ls
Tags: ls

Shows all linked file and destinations. The 'ls -l' command lists the files in long (1 file per line) format, and the grep command displays only those lines that starts with an l (lower case L) -- a linked file.

Updated: Remove reference to hard links because this command does not apply to hard link as others kindly pointed out.

find . -type f -size +25000k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'
ls -Sl * | head
2009-03-27 23:20:32
User: colinpj
Functions: ls

head by default displays first ten lines of its output. Use 'head -nXX' to display the XX largest files

ls \\someserver\c$\inetpub\wwwroot -r -i web.config | Select-String "SomeMachineName"
2009-03-25 22:36:58
User: cbilson
Functions: ls

Finds all files of a certain name and reports all line with the string. Very simple.

function t { ls -ltch $* | head -20 ; }
2009-03-25 20:05:52
User: totoro
Functions: head ls

Coming back to a project directory after sometime elsewhere?

Need to know what the most recently modified files are?

This little function "t" is one of my most frequent commands.

I have a tcsh alias for it also:

alias t 'ls -ltch \!* | head -20'

ls /some/directory | sed -rn -e 's/input_file_regex/mv -v & output_file_name/p' | sh
2009-03-25 09:20:15
User: polar
Functions: ls sed
Tags: bash sed

Allows for quick mass renaming, assuming the user has some familiarity with regular expressions. Basically, it replaces the original_file_name in the output of ls with

"mv -v original_file_name new_file_name"

and passes the output to sh.

alias mux='clear && cd ~/Music/ && ls && echo -n "File> " && read msi && mplayer ~/Music/$msi'
2009-03-23 10:45:27
User: Noxn
Functions: alias cd echo ls read

An alias i made for myself to play music in a faster way.

Works great when you have Guake / Tilda installed (Console that drops down like in the game QUAKE)


I put this in my bash_alias file (I'm on ubuntu, the bash_alias file does autostart with the right config) but it works putting it in bashrc too. Or anything that autostarts when the console is opened.


Needs Mplayer and music files to work. With out music theres nothing to play!

Oh, and also, without modification, this alias will try to play stuff from your ~/Music folder! (case sensitive). Make sure that folder exists and has music OR edit this alias to fit your needs.

ls | while read ITEM; do echo "$ITEM"; done
2009-03-22 23:33:13
User: fletch
Functions: echo ls read
Tags: bash

If you want to operate on a set of items in Bash, and at least one of them contains spaces, the `for` loop isn't going to work the way you might expect. For example, if the current dir has two files, named "file" and "file 2", this would loop 3 times (once each for "file", "file", and "2"):

for ITEM in `ls`; do echo "$ITEM"; done

Instead, use a while loop with `read`:

ls | while read ITEM; do echo "$ITEM"; done
ls -hog
2009-03-21 05:24:49
User: haivu
Functions: ls
Tags: shell

I often deal with long file names and the 'ls -l' command leaves very little room for file names. An alternative is to use the -h -o and -g flags (or together, -hog).

* The -h flag produces human-readable file size (e.g. 91K instead of 92728)

* The -o suppresses the owner column

* The -g suppresses the group column

Since I use to alias ll='ls -l', I now do alias ll='ls -hog'

ls -1 static/images/ | while read line; do echo -n $line' '[; grep -rc $line *|grep -v ".svn"|cut -d":" -f2|grep -vc 0| tr "\n" -d; echo -n ]; echo ; done
2009-03-20 20:33:36
User: psytek
Functions: cut echo grep ls read tr

This command will grep the entire directory looking for any files containing the list of files. This is useful for cleaning out your project of old static files that are no longer in use. Also ignores .svn directories for accurate counts. Replace 'static/images/' with the directory containing the files you want to search for.

ls -l | sort -nk5
PLAYLIST=$(ls -1) ; mpg123 -C $PLAYLIST
2009-03-19 17:20:28
Functions: ls mpg123

On my music directory, I create variable that contains all mp3s files, then I play them with mpg123. -C options enable terminal control key, s for stop, p for pause, f for forward to next song.

ls -1 | rename 's/\ /_/'
2009-03-17 17:33:41
Functions: ls rename

Substitute spaces in filename with underscore, it work on the first space encountered.

ls -1 | grep " " | awk '{printf("mv \"%s\" ",$0); gsub(/ /,"_",$0); printf("%s\n",$0)}' | sh # rename filenames: spaces to "_"
2009-03-15 18:42:43
User: mpb
Functions: awk grep ls rename sh

This command converts filenames with embedded spaces in the current directory replacing spaces with the underscore ("_") character.

ls -l|awk '{print $6,$8}'|sort -d
2009-03-13 19:00:18
User: archlich
Functions: awk ls sort

Can pipe to tail or change the awk for for file size, groups, users, etc.

ls /home/user | xargs ls -lhR | less
ls -A
2009-03-13 05:12:01
User: haivu
Functions: ls
Tags: terminal

This command is almost the same as 'ls -a', but it does not display the current dir (.) or parent (..)

vim $( ls -t | head -n1 )
for i in $(ls *.od{tp}); do unoconv -f pdf $i; done