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 tagged cd from sorted by
Terminal - Commands tagged cd - 51 results
function cdb() { select dir in $(find -type d -name "$1" -not -path '*/\.*' -prune); do cd "${dir}" && break; done }
cd -P .
dd bs=1M if=/dev/scd0 of=./filename.iso OR readom -v dev='D:' f='./filename.iso' speed=2 retries=8
2013-10-23 15:53:27
User: scotharkins
Functions: dd

This example is taken from Cygwin running on Win7Ent-64. Device names will vary by platform.

Both commands resulted in identical files per the output of md5sum, and ran in the same time down to the second (2m45s), less than 100ms apart. I timed the commands with 'time', which added before 'dd' or 'readom' gives execution times after the command completes. See 'man time' for more info...it can be found on any Unix or Linux newer than 1973. Yeah, that means everywhere.

readom is supposed to guarantee good reads, and does support flags for bypassing bad blocks where dd will either fail or hang.

readom's verbosity gave more interesting output than dd.

On Cygwin, my attempt with 'readom' from the first answer actually ended up reading my hard drive. Both attempts got to 5GB before I killed them, seeing as that is past any CD or standard DVD.


'bs=1M' says "read 1MB into RAM from source, then write that 1MB to output. I also tested 10MB, which shaved the time down to 2m42s.

'if=/dev/scd0' selects Cygwin's representation of the first CD-ROM drive.

'of=./filename.iso' simply means "create filename.iso in the current directory."


'-v' says "be a little noisy (verbose)." The man page implies more verbosity with more 'v's, e.g. -vvv.

dev='D:' in Cygwin explicitly specifies the D-drive. I tried other entries, like '/dev/scd0' and '2,0', but both read from my hard drive instead of the CD-ROM. I imagine my LUN-foo (2,0) was off for my system, but on Cygwin 'D:' sort of "cut to the chase" and did the job.

f='./filename.iso' specifies the output file.

speed=2 simply sets the speed at which the CD is read. I also tried 4, which ran the exact same 2m45s.

retries=8 simply means try reading a block up to 8 times before giving up. This is useful for damaged media (scratches, glue lines, etc.), allowing you to automatically "get everything that can be copied" so you at least have most of the data.

for i in {1..6};do c=;d=;for u in `eval echo {1..$i}`;do c="$c../";d="$d..";eval "$d(){ cd $c;}"; eval "$d.(){ cd $c;}";done;done
2013-09-04 20:12:45
User: bbbco
Functions: echo eval
Tags: cd eval dot

Use dots to cd down directories instead of having to remember all of the pesky back slashes!

Better yet, works on even and odd number of dots! Now, just estimate how far down you want to traverse.

function mkdcd () { mkdir "$1" && cd "$1" }
cd -
2013-05-07 14:50:18
User: techie
Functions: cd
Tags: cd

if you cd into a directory then cd into another directory somewhere else then you run the cd - command you will go to the previous directory you was in!! To go back to the other directory just run it again. So if you are working in 2 different directories then this is the perfect command for you.

mkdir -p /path/to/folder.d; \cd $_
dd if=/dev/cdrom bs=1 skip=32808 count=32 conv=unblock cbs=32 2>/dev/null
2013-04-14 20:50:58
User: mlk
Functions: dd
Tags: dd cd iso9660

The comp.unix.shell posting by St?phane Chazelas also lists the following offsets:

type 32768 (1 byte)

id 32769 (5 bytes)

version 32774 (1 byte)

system_id 32776 (32 bytes)

volume_id 32808 (32 bytes)

volume_space_size 32848 (8 bytes)

escape_sequences 32856 (32 bytes)

volume_set_size 32888 (4 bytes)

volume_sequence_number 32892 (4 bytes)

logical_block_size 32896 (4 bytes)

path_table_size 32900 (8 bytes)

type_l_path_table 32908 (4 bytes)

opt_type_l_path_table 32912 (4 bytes)

type_m_path_table 32916 (4 bytes)

opt_type_m_path_table 32920 (4 bytes)

root_directory_record 32924 (34 bytes)

volume_set_id 32958 (128 bytes)

publisher_id 33086 (128 bytes)

preparer_id 33214 (128 bytes)

application_id 33342 (128 bytes)

copyright_file_id 33470 (37 bytes)

abstract_file_id 33507 (37 bytes)

bibliographic_file_id 33544 (37 bytes)

creation_date 33581 (17 bytes)

modification_date 33598 (17 bytes)

expiration_date 33615 (17 bytes)

effective_date 33632 (17 bytes)

file_structure_version 33649 (1 byte)

application_data 33651 (512 bytes)

FULLPATH=$(perl -e "use Cwd 'abs_path';print abs_path('$0');")
2013-02-01 20:09:34
User: follier
Functions: perl

Since none of the systems I work on have readlink, this works cross-platform (everywhere has perl, right?).

Note: This will resolve links.

function up { cd $(eval printf '../'%.0s {1..$1}) && pwd; }
2013-01-21 12:57:45
User: michelsberg
Functions: cd eval printf
Tags: cd directory


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

function map() { [ -n "$1" ] && alias $1="cd `pwd`" || alias | grep "'cd "; }
alias md='mkdir -p'; alias rd='rmdir'; mcd () { mkdir "$@" && cd "$_"; }
2012-08-12 12:54:51
User: expelledboy
Functions: alias cd mcd mkdir

I realise that this is just a reiteration of another entry (regardless of whether I came up with all this all by myself), but I would like present my additional alias' in context as a method of managing your directories. Rather convenient.

dvdisaster -vr --defective-dump . --internal-rereads 5 --raw-mode 20 --read-attempts 1-23 --read-raw --speed-warning 12 --adaptive-read --auto-suffix --read-medium 2 && dvdisaster -vc -mRS02 --raw-mode 20 --read-raw --auto-suffix
dd if=/dev/cdrom of=~/cdrom_image.iso
2012-07-10 06:03:25
User: o0110o
Functions: dd
Tags: dd cd iso dvd convert

An easy method to generate ISOs from CD/DVD media.

cd -
shopt -s cdspell
2012-06-26 17:28:57
User: ankush108
Tags: cd shopt spell

Use shopt -s cdspell to correct the typos in the cd command

pushd path/to/dir/
cd -
2012-06-26 17:20:54
User: ankush108
Functions: cd
Tags: cd

switch to previous directory or toggle

function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }
2012-06-26 17:19:16
User: ankush108
Functions: cd eval mkdir
Tags: cd mkdir

Creates a directory and then cds into it directly

up() { [ $(( $1 + 0 )) -gt 0 ] && cd $(eval "printf '../'%.0s {1..$1}"); }
2012-06-15 17:10:45
User: Mozai
Functions: cd eval
Tags: bash cd

`up 3` will climb the directory tree by three steps. `up asdf` will do nothing, and returns exit code 1 as an error should.

up() { local x='';for i in $(seq ${1:-1});do x="$x../"; done;cd $x; }
2012-05-16 04:21:41
User: evil
Functions: cd seq
Tags: cd

I wrote this a long time ago, wondering why this wasn't floating around somewhere out there (at least not where I could find).. this seems much more simple than multiple aliases and can cd out of directories easier.

up () { if [ "${1/[^0-9]/}" == "$1" ]; then p=./; for i in $(seq 1 $1); do p=${p}../; done; cd $p; else echo 'usage: up N'; fi }
2012-04-19 08:16:34
Functions: cd echo seq
Tags: alias cd

Change n directories up, without parameters change one up

2012-04-16 21:18:27
User: khopesh
Functions: cd
Tags: cd

This is like `cd -` but doesn't echo the new directory name, which is preferable (to me) for an alias, e.g.

alias cdo="cd $OLDPWD"
dirname $(readlink -f ${BASH_SOURCE[0]})