Hide

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.

Hide

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:

Hide

News

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.
Hide

Tags

Hide

Functions

Commands tagged directory from sorted by
Terminal - Commands tagged directory - 37 results
eval `ls -1d * | awk '{print "zip -r "$1".zip "$1";"}'`
function up { cd $(eval printf '../'%.0s {1..$1}) && pwd; }
2013-01-21 12:57:45
User: michelsberg
Functions: cd eval printf
Tags: cd directory
5

Usage:

up N

I did not like two things in the submitted commands and fixed it here:

1) If I do cd - afterwards, I want to go back to the directory I've been before

2) If I call up without argument, I expect to go up one level

It is sad, that I need eval (at least in bash), but I think it's safe here.

eval is required, because in bash brace expansion happens before variable substitution, see http://rosettacode.org/wiki/Repeat_a_string#Using_printf

wipe -rfqQ 10 directory/
2012-09-20 01:12:33
User: slashbang
0

wipes directory/ "recursively" "w/o confirming" deletion in "quick" mode for "10" passes.

pushd path/to/dir/
find . -printf "%s %p\n" | sort -n
find . -ls | sort -k 7 -n
tree -ifs --noreport .|sort -n -k2
2012-05-04 09:18:39
User: knoppix5
Functions: sort
1

or

tree -ifsF --noreport .|sort -n -k2|grep -v '/$'

(rows presenting directory names become hidden)

cp -auv /SorceDirectory/ /ParentDestination/
2012-03-04 13:04:03
User: joeseggiola
Functions: cp
1

Backup a whole directory copying only updated files.

ls -ltr --directory $(find . -regex "./.*[^/]*\'" -type f | xargs -n 1 dirname | sort | uniq)
2012-03-02 03:48:47
User: pdkl95
Functions: dirname find ls sort xargs
0

This let me find some a set of modifications that were made to a rather large tree of files, where the file-names themselves were not unique (actually: insanely redundant and useless. "1.dat 2.dat ..."). Pruning down to last-branch brough things back to the "project-name" scope, and it's then easy to see which branches of the tree have recently changed, or any other similar search.

Ideally, it should sort the directories by the mtime of the most recent *file* *inside* the directory, but that's probably outside the scope of a (sane...) command line.

ls -t1 $* | head -1 ;
2012-02-10 22:13:24
Functions: head ls
0

Returns the most recently modified file in the current (or specified) directory. You can also get the oldest file, via:

ls -t1 $* | tail-1 ;

rgrep <searchterm> *
grep -r <searchterm> .
2012-02-08 11:59:17
Functions: grep
Tags: grep directory
0

You don't need to use "*", it will fail if the working directory has too many fails due parameter extension, you can simply pass the working directory using ".".

grep -r <searchterm> .
2012-02-08 11:58:21
Functions: grep
Tags: grep directory
0

You don't need to use "*", it will fail if the working directory has too many fails due parameter extension, you can simply pass the working directory using ".".

grep -r <searchterm> *
ls -ad */
2011-12-10 17:08:07
User: tbekolay
Functions: ls
Tags: ls directory
3

Like normal ls, but only lists directories.

Can be used with -l to get more details (ls -lad */)

upto() { cd "${PWD/\/$@\/*//$@}" }
jd() { cd **/"$@"; }
2011-10-05 11:47:57
User: sharfah
Functions: cd
-3

Usage: jd dir

Requires globstar. To set globstar use:

shopt -s globstar
du -h /path | sort -h
SEARCHPATH=/var/; find $SEARCHPATH -type d -print0 | xargs -0 du -s 2> /dev/null | sort -nr | sed 's|^.*'$SEARCHPATH'|'$SEARCHPATH'|' | xargs du -sh 2> /dev/null
2011-07-06 08:21:58
User: moogmusic
Functions: du find sed sort xargs
-2

This command lists all the directories in SEARCHPATH by size, displaying their size in a human readable format.

find . -maxdepth 1 -type d | grep -Pv "^.$" | sort -rn --field-separator="-" | sed -n '3,$p' | xargs rm -rf
svnradd() { for i in $1/*;do if [ -e "$i" ];then if [ -d "$i" ];then svn add $i;svnradd $i;else svn add $i;fi; fi;done }
2011-02-16 03:33:57
User: lkjoel
0

This will recursively add files/directories in SVN.

Usage:

svnradd yourfile

or

svnradd yourdirectory

then:

svn commit

Notice: It might not work properly, and not all files could get added.

Since there is a limit on characters, I couldn't add failure/success notices.

If you want failure/success notices, download Terminal Enhancements (http://tenhancements.tk/ )

It is included on Base Features

for i in $(ls *.flv); do ffmpeg2theora -v 6 --optimize $i; done
2010-12-01 14:13:31
User: joenjeru
Functions: ls
0

Do you have a large library of flv's you have picked up over the years using FlashGot Firefox plugin?

Do you want to be able to convert them to Ogg Theora (video) at once?

Try out this script...

bm () { ... see description }
bm() { export BM${1?"bookmark name missing"}="$PWD" ; }; forget() { unset BM${1?"bookmark name missing"} ; }
2010-11-19 12:15:11
User: unefunge
Functions: export unset
1

pushd and popd are your friends, but sometimes they're just incompatible with the way one works...

Two shell functions:

bm bookmarkname - "bookmarks" the current directory, just 'cd $BMbookmarkname' to return to it.

forget bookmarkname - unsets the 'bookmarkname' variable. It isn't mandatory, they cease to exist when the session ends.

watch -n <time_interval> "du -s <file_or_directory>"