Commands using cd (197)

  • Simple but useful little command to unzip all files in a directory.


    -5
    cd /example/directory && unzip \*.zip
    Paaskehare · 2009-07-12 21:45:13 3

  • 7
    ( cd SOURCEDIR && tar cf - . ) | (cd DESTDIR && tar xvpf - )
    res0nat0r · 2009-06-26 19:13:51 6
  • This command securely erases all the unused blocks on a partition. The unused blocks are the "free space" on the partition. Some of these blocks will contain data from previously deleted files. You might want to use this if you are given access to an old computer and you do not know its provenance. The command could be used while booted from a LiveCD to clear freespace space on old HD. On modern Linux LiveCDs, the "ntfs-3g" system provides ReadWrite access to NTFS partitions thus enabling this method to also be used on Wind'ohs drives. NB depending on the size of the partition, this command could take a while to complete. Show Sample Output


    8
    # cd $partition; dd if=/dev/zero of=ShredUnusedBlocks bs=512M; shred -vzu ShredUnusedBlocks
    mpb · 2009-06-21 14:17:22 6
  • Nice reading in the morning on the way to work, but sadly the .tar.gz for the whole issue 66 is not on phrack's website yet. So use wget to download.


    2
    mkdir phrack66; (cd phrack66; for n in {1..17} ; do echo "http://www.phrack.org/issues.html?issue=66&id=$n&mode=txt" ; done | xargs wget)
    masterofdisaster · 2009-06-11 21:42:42 1
  • Very simple and useful, you need to change the word "directory" for your directory


    -3
    cd <YOUR_DIRECTORY>; for i in `ls ./`; do tar czvf "$i".tar.gz "$i" ; done
    ElAlecs · 2009-06-11 18:33:27 6
  • unzips all zip files in any subdirectory under the current directory. The zip files are unzipped in their respective subdirs


    -3
    for f in `find ./ -name "*.zip"` ; do p=`pwd`; d=`dirname $f`; cd $d; b=`basename $f`; unzip $b; cd $p; done
    packetloss · 2009-05-30 03:42:53 4
  • This uses Bash's "process substitution" feature to compare (using diff) the output of two different process pipelines.


    33
    diff <(cd dir1 && find | sort) <(cd dir2 && find | sort)
    mbirk · 2009-05-21 04:44:29 7
  • I find that I create a directory and then cd into that directory quite often. I found this little function on the internets somewhere and thought I'd share it. Just copy-paste it into you ~/.bash_profile and then `source ~/.bash_profile`. Show Sample Output


    4
    function mcd() { [ -n "$1" ] && mkdir -p "$@" && cd "$1"; }
    thebillywayne · 2009-05-20 16:41:48 3
  • This command create a new temp directory using mktemp (to avoid collisions) and change the current working directory to the created directory. Show Sample Output


    8
    cd "$(mktemp -d)"
    Weboide · 2009-05-20 11:48:12 2
  • Based on linkinpark342 suggestion. Sometimes you have to browse your way through a lot of sub-directories. This command cd to the previous sub-directory in alphabetical order. For example, if you have the directories "lectures/01-intro", "lectures/02-basic", "lectures/03-advanced" and so on, and your PWD is "02-basic", it jumps to "01-intro".


    6
    cd ../"$(ls -F ..|grep '/'|grep -B1 `basename $PWD`|head -n 1)"
    gwiener · 2009-05-18 06:44:02 0
  • Another version based on linkinpark342's contribution. Sometimes you have to browse your way through a lot of sub-directories. This command cd to the next sub-directory in alphabetical order. For example, if you have the directories "lectures/01-intro", "lectures/02-basic", "lectures/03-advanced" and so on, and your PWD is "02-basic", it jumps to "03-advanced".


    3
    cd ../"$(ls -F ..|grep '/'|grep -A1 `basename $PWD`|tail -n 1)"
    gwiener · 2009-05-18 06:41:37 1
  • Sometimes you have to browse your way through a lot of sub-directories. This command cd to the next sub-directory in alphabetical order. For example, if you have the directories "lectures/01-intro", "lectures/02-basic", "lectures/03-advanced" and so on, and your PWD is "02-basic", it jumps to "03-advanced".


    4
    for d in `find .. -mindepth 1 -maxdepth 1 -type d | sort`; do if [[ `basename $d` > `basename $PWD` ]]; then cd $d; break; fi; done
    gwiener · 2009-05-16 17:33:34 9
  • It copies the entire current working directory to the destination directory with compression enabled.


    1
    gtar cpf - . | (cd /dest/directory; gtar xpf -)
    mnikhil · 2009-05-15 13:23:00 1
  • ec commits changes to etckeeper must have etckeeper installed with bzr to use this place inside bashrc can be used from any directory to commit changes


    0
    function ec() { ec_var="`pwd`" && cd /etc/ && sudo bzr commit -m "$@" && cd $ec_var; }
    professoralex · 2009-05-14 04:34:26 2
  • During this operation : # mv Joomla_1.5.10-Stable-Full_Package.zip /var/www/joomla/ I invoke /var/www/joomla/ as last command argument. To change in this directory I can use # cd !$ So I go to hob:/var/www/joomla#


    -3
    cd !$
    servermanaged · 2009-05-08 09:48:14 2
  • This command looks for a single file named emails.txt which is located somewhere in my home directory and cd to that directory. This command is especially helpful when the file is burried deep in the directory structure. I tested it against the bash shells in Xubuntu 8.10 and Mac OS X Leopard 10.5.6


    9
    cd $(dirname $(find ~ -name emails.txt))
    haivu · 2009-05-01 21:26:58 4
  • Clone a partion with tar.


    3
    cd /mnt/old && tar cvf - . | ( cd /mnt/new && tar xvf - )
    javamaniac · 2009-04-30 21:03:59 4
  • When you fill a formular with Firefox, you see things you entered in previous formulars with same field names. This command list everything Firefox has registered. Using a "delete from", you can remove anoying Google queries, for example ;-)


    19
    cd ~/.mozilla/firefox/ && sqlite3 `cat profiles.ini | grep Path | awk -F= '{print $2}'`/formhistory.sqlite "select * from moz_formhistory" && cd - > /dev/null
    klipz · 2009-04-13 20:23:37 3

  • -7
    mkdir() { /bin/mkdir $@ && eval cd "\$$#"; }
    fnando · 2009-03-30 17:24:21 7
  • 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. Show Sample Output


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

  • -24
    cd
    veganstraightedg · 2009-03-23 03:12:40 5
  • For use in scripts this command is very usefull


    1
    [[ -d dir ]] || mkdir dir ; cd dir
    voyeg3r · 2009-03-12 17:19:13 3
  • 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. Show Sample Output


    7
    function cdls { cd $1; ls; }
    joem86 · 2009-03-10 19:13:47 6
  • Add z to the flags to enable compression.


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

  • 4
    cd !$
    web_mogul · 2009-03-08 14:57:27 3
  • ‹ First  < 5 6 7 8 > 

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands



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: