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 using cd from sorted by
Terminal - Commands using cd - 179 results
mkdir() { /bin/mkdir $@ && eval cd "\$$#"; }
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
-2

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.

cd
[[ -d dir ]] || mkdir dir ; cd dir
2009-03-12 17:19:13
User: voyeg3r
Functions: cd dir mkdir
1

For use in scripts this command is very usefull

function cdls { cd $1; ls; }
2009-03-10 19:13:47
User: joem86
Functions: cd
Tags: terminal
7

After typing cd directory [enter] ls [enter] so many times, I figured I'd try to make it into a function. I was surprised how smoothly I was able to integrate it into my work on the command line.

Just use cdls as you would cd. It will automatically list the directory contents after you cd into the directory. To make the command always available, add it to your .bashrc file.

Not quite monumental, but still pretty convenient.

tar cf - . | (cd /new/dir; tar xvf -)
2009-03-09 20:30:34
User: jauderho
Functions: cd tar
-1

Add z to the flags to enable compression.

cd !$
cd() { builtin cd "${@:-$HOME}" && ls; }
2009-03-05 22:37:35
User: haivu
Functions: cd
6

Often, the very next command after the cd command is 'ls', so why not combine them?. Tested on a Red Hat derivative and Mac OS X Leopard

Update: changed ${1:-$HOME} to "${@:-$HOME}" to accomodate directories with spaces in the names

alias wordpress='mkdir wordpress && cd wordpress && wget http://wordpress.org/latest.tar.gz && tar -xvzf latest.tar.gz && mv wordpress/* . && rm -rf latest.tar.gz wordpress && cp wp-config-sample.php wp-config.php'
function miso () { mkdir ~/ISO_CD && sudo mount -o loop "$@" ~/ISO_CD && cd ~/ISO_CD && ls; } function uiso () { cd ~ && sudo umount ~/ISO_CD && rm -r ~/ISO_CD; }
2009-02-25 03:41:35
User: vududevil
Functions: cd mkdir mount rm sudo umount
4

Add the functions to the .bashrc to make it work

Example: First go to the iso file directory and type:

----------------------------------------------------------------------------------------------------

user@box:~$ miso file.iso

----------------------------------------------------------------------------------------------------

It will put you into a temporary mounting point directory (ISO_CD) and will show the files

You can umount the iso file whatever the directory you are

----------------------------------------------------------------------------------------------------

user@box:~/ISO_CD$ uiso

----------------------------------------------------------------------------------------------------

It wil umount the iso file and remove the temporary directory in your home

(cd /Applications/Firefox.app/Contents/MacOS; ./firefox-bin -p default --no-remote)
cd `pwd -P`
2009-02-17 17:21:24
User: Davvolun
Functions: cd
16

If you use symlinks a lot, especially nested symlinks, this puts you back on the absolute path to command-line-fu-nirvana. (Note the backticks around pwd).

cd /source/directory; tar cf - . | tar xf - -C /destination/directory
cd !$
2009-02-16 21:33:14
User: raphink
Functions: cd
1

!$ recalls the last argument of the previous command. This is very useful when you have to operate several operations on the same file for example.

cd /usr/ports; grep -F "`for o in \`pkg_info -qao\` ; \ do echo "|/usr/ports/${o}|" ; done`" `make -V INDEXFILE` | \ grep -i \|ports@freebsd.org\| | cut -f 2 -d \|
2009-02-16 21:07:35
User: grep
Functions: cd cut grep
-1

only works for freeBSD where ports are installed in /usr/ports

credit to http://wiki.freebsd.org/PortsTasks

(cd /orignl/path tar -cf - . ) | (cd /dst/dir;tar -xvf -)
2009-02-16 09:36:34
Functions: cd tar
1

uses tar to dump files from /orignl/path to /dst/dir. i find tar's out more readable than cp, and it doesn't mess with modified dates.

cd -
2009-02-16 02:37:50
User: chmouel
Functions: cd
1

cd - would return to the previous directory of your cd command. NB: previous dir is always stored in $OLDPWD variable.

cd \
2009-02-14 21:53:51
User: VonC
Functions: cd
-33

Useful to quickly get back to the Windows root directory of the current drive from a sub-directory within that drive.

Works also without space between 'cd' and backslash: 'cd\' or 'cd \' have the same effect

cd /d d:\Windows
2009-02-13 16:06:48
User: piyo
Functions: cd
-2

In the Windows cmd.exe window, you can change the directory using cd, but if you need to go to a directory on another drive, you need to type in the drive letter and colon first (e.g. d:). With the /d on cd, you don't need this intermediate step.

cd /?

Tested on Windows XP

cd XX YY
2009-02-10 13:20:11
User: yogsototh
Functions: cd
3

If you are in /begin/path/with/XX/pattern

cd XX YY

will change your current directory to

/begin/path/with/YY/pattern

in ZSH

cd //
find ./source -depth -print | cpio -cvo> /destination/source_data.cpio; cd /destination; cpio -icvmdI ./source_data.cpio; rm -rf ./source_data.cpio
2009-02-07 18:51:49
User: mnikhil
Functions: cd cpio find rm
0

Copy data to the destination using commands such as cpio (recommended), tar, rsync, ufsdump, or ufsrestore.

Example:

Let the source directory be /source, and let the destination directory be /destination.

# cd /source

# cd ..

# find ./source -depth -print | cpio -cvo> /destination/source_data.cpio

# cd /destination

# cpio -icvmdI ./source_data.cpio

# rm -rf ./source_data.cpio

cd /some/directory \&\& tar cf - | cd /some/directory \&\& tar xvf - */
alias scd='dirs -v; echo -n "select number: "; read newdir; cd -"$newdir"'
cd -