Commands using cd (215)

  • The Windows Subsystem for Linux (WSL) is a compatibility layer for running binary Linux executables natively in Windows. A folder such as "C:\Program Files (x86)\Common Files" is represented as "/mnt/c/Program Files (x86)/Common Files". This function allows you to change the current directory to a Windows folder. Show Sample Output


    0
    function _cd() { local dir; dir="$(sed -e 's~\([a-z]\):~/mnt/\L\1~gi' <<< "${*//'\'/"/"}" )"; if [ -d "$dir" ]; then cd "$dir" || exit; fi; }
    mikhail · 2019-06-06 17:53:28 40
  • MacOS Solution due to lack of pidof command and procfs on MacOS Kernel. Show Sample Output


    0
    function _xterm_cwds() { for pid in $(pgrep -x zsh); do reply+=$(lsof -p $pid | grep cwd | awk '{print $9}') done }; function xcd() { cd $1 }; compctl -K _xterm_cwds xcd
    cdiehl · 2019-06-15 02:26:11 35
  • The “predictive capture” feature of Sony's Xperia camera app hides the date stamp deeply inside the filename. This command adds another date stamp at the beginning of the filename. Show Sample Output


    0
    (setopt CSH_NULL_GLOB; cd /path/to/Camera\ Uploads; for i in DSCPDC_000*; do mv -v $i "$(echo $i | perl -lpe 's/(DSCPDC_[0-9]{4}_BURST)([0-9]{4})([0-9]{2})([0-9]{2})/$2-$3-$4 $1$2$3$4/')"; done)
    langec · 2020-04-12 06:20:59 162

  • -1
    cd -
    m13a · 2009-02-06 09:35:18 11
  • only works for freeBSD where ports are installed in /usr/ports credit to http://wiki.freebsd.org/PortsTasks


    -1
    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 \|
    grep · 2009-02-16 21:07:35 8

  • -1
    (cd /Applications/Firefox.app/Contents/MacOS; ./firefox-bin -p default --no-remote)
    DEinspanjer · 2009-02-18 21:35:02 5
  • Add z to the flags to enable compression.


    -1
    tar cf - . | (cd /new/dir; tar xvf -)
    jauderho · 2009-03-09 20:30:34 12
  • This command will generate "CHECK TABLE `db_name.table_name` ;" statements for all tables present in databases on a MySQL server, which can be piped into the mysql command. (Can also be altered to perform OPTIMIZE and REPAIR functions.) Tested on MySQL 4.x and 5.x systems in a Linux environment under bash. Show Sample Output


    -1
    DD=`cat /etc/my.cnf | sed "s/#.*//g;" | grep datadir | tr '=' ' ' | gawk '{print $2;}'` && ( cd $DD ; find . -mindepth 2 | grep -v db\.opt | sed 's/\.\///g; s/\....$//g; s/\//./;' | sort | uniq | tr '/' '.' | gawk '{print "CHECK TABLE","`"$1"`",";";}' )
    atcroft · 2009-07-25 03:42:31 15
  • search argument in PATH accept grep expressions without args, list all binaries found in PATH Show Sample Output


    -1
    function sepath { echo $PATH |tr ":" "\n" |sort -u |while read L ; do cd "$L" 2>/dev/null && find . \( ! -name . -prune \) \( -type f -o -type l \) 2>/dev/null |sed "s@^\./@@" |egrep -i "${*}" |sed "s@^@$L/@" ; done ; }
    mobidyc · 2009-09-11 15:03:22 5
  • Combines a few repetitive tasks when compiling source code. Especially useful when a hypen in a file-name breaks tab completion. 1.) wget source.tar.gz 2.) tar xzvf source.tar.gz 3.) cd source 4.) ls From there you can run ./configure, make and etc. Show Sample Output


    -1
    wtzc () { wget "$@"; foo=`echo "$@" | sed 's:.*/::'`; tar xzvf $foo; blah=`echo $foo | sed 's:,*/::'`; bar=`echo $blah | sed -e 's/\(.*\)\..*/\1/' -e 's/\(.*\)\..*/\1/'`; cd $bar; ls; }
    oshazard · 2010-01-17 11:25:47 3
  • using "!$" will save another ton of typing than 'ALT+.' or ' .' Show Sample Output


    -1
    cd !$
    YCFlame · 2010-08-26 08:51:01 3
  • some other options: &delay=1000 &mode=links much more with piggybank as scraper works well with your favourite curses or non-curses http clients


    -1
    svn co http://simile.mit.edu/repository/crowbar/trunk&& cd ./trunk/xulapp/ xulrunner --install-app && Xvfb :1 && DISPLAY=:1 xulrunner application.ini 2>/dev/null 1>/dev/null && wget -O- "127.0.0.1:10000/&url=http://www.facebook.com"
    argv · 2010-10-16 05:12:11 3
  • Add dirs to list: pushd /tmp /tmp ~ then cd - /home/user cd - /tmp


    -1
    cd -
    magicjohnson_ · 2011-07-05 05:28:32 6
  • Replace the head -1 with head -n that is the n-th item you want to go to. Replace the head with tail, go to the last dir you listed. You also can change the parameters of ls.


    -1
    cd $(ls -ltr|grep ^d|head -1|sed 's:.*\ ::g'|tail -1)
    timothyhmchen101 · 2011-08-10 03:39:35 2

  • -1
    jda() { cd $(pwd | sed "s/\(\/$@\/\).*/\1/g"); }
    saibbot · 2011-10-05 21:14:57 5

  • -1
    cd /System/Library/LaunchDaemons; sudo launchctl load -w com.apple.metadata.mds.plist
    evandrix · 2012-05-16 15:42:10 4
  • Assumes you've cd'd to the folder in which all your git repos reside; you could run it from ~ without -maxdepth, although that might make find take quite a while longer. If you have several processor cores, but not that much ram, you might want to run git config --global pack.threads 1 first, since gc-ing can eat lots of ram. Show Sample Output


    -1
    find . -maxdepth 2 -type d -name '.git' -print0 | while read -d ''; do (cd "$REPLY"; git gc); done
    unhammer · 2012-11-07 08:38:33 4
  • this command will add the following two lines into the ~/.bash_aliases: alias exit='pwd > ~/.lastdir;exit' [ -n "$(cat .lastdir 2>/dev/null)" ] && cd "$(cat .lastdir)" or redirect it to the ~/.bashrc if you like Donno, I find it usefull. You may also define an alias for 'cd ~' like - alias cdh='cd ~'


    -1
    echo -e 'alias exit='\''pwd > ~/.lastdir;exit'\''\n[ -n "$(cat .lastdir 2>/dev/null)" ] && cd "$(cat .lastdir)"' >> ~/.bash_aliases
    ichbins · 2014-01-28 18:02:04 6
  • 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 Show Sample Output


    -2
    cd /d d:\Windows
    piyo · 2009-02-13 16:06:48 10
  • 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 15
  • Using tape archive create a tar file in Stdout (-) and pipe that into a compound command to extract the tar file from Stdin at the destination. This similar to "Copy via tar pipe ...", but copies across file systems boundaries. I prefer to use cp -pr for copying within the same file system. Show Sample Output


    -2
    tar cpof - src |( cd des; tar xpof -)
    davidpotter42 · 2009-09-20 20:43:30 3
  • CHANGELOG Version 1.1 removedir () { echo "You are about to delete the current directory $PWD Are you sure?"; read human; if [[ "$human" = "yes" ]]; then blah=$(echo "$PWD" | sed 's/ /\\ /g'); foo=$(basename "$blah"); rm -Rf ../$foo/ && cd ..; else echo "I'm watching you" | pv -qL 10; fi; } BUG FIX: Folders with spaces Version 1.0 removedir () { echo "You are about to delete the current directory $PWD Are you sure?"; read human; if [[ "$human" = "yes" ]]; then blah=`basename $PWD`; rm -Rf ../$blah/ && cd ..; else echo "I'm watching you" | pv -qL 10; fi; } BUG FIX: Hidden directories (.dotdirectory) Version 0.9 rmdir () { echo "You are about to delete the current directory $PWD. Are you sure?"; read human; if [[ "$human" = "yes" ]]; then blah=`basename $PWD`; rm -Rf ../$blah/ && cd ..; else echo "I'm watching you" | pv -qL 10; fi; } Removes current directory with recursive and force flags plus basic human check. When prompted type yes 1. [user@host ~]$ ls foo bar 2. [user@host ~]$ cd foo 3. [user@host foo]$ removedir 4. yes 5. rm -Rf foo/ 6. [user@host ~]$ 7. [user@host ~]$ ls bar Show Sample Output


    -2
    removedir () { echo "Deleting the current directory $PWD Are you sure?"; read human; if [[ "$human" = "yes" ]]; then blah=$(echo "$PWD" | sed 's/ /\\ /g'); foo=$(basename "$blah"); rm -Rf ../$foo/ && cd ..; else echo "I'm watching you" | pv -qL 10; fi; }
    oshazard · 2010-01-17 11:34:38 31
  • If you have a directory with many working copies of various subversion projects and you want to update them all at once, this one may be for you. Show Sample Output


    -2
    for d in $(find . -maxdepth 1 -type d -name '[^.]*'); do cd "$d"; svn up; cd ..; done
    udog · 2010-05-28 10:09:19 3
  • Run program as root by SSH key forwarding instead of sudoers. Put this alias line in .bashrc or wherever you like. Alias arguments might need extra escaping. You might wonder about security. But you'd block out root login as much as possible of course. In sshd_config you put this: PermitRootLogin no Match Address 127.0.0.1   PermitRootLogin without-password


    -2
    alias sshdo='ssh -q -t root@localhost -- cd $PWD \&\& sudo'
    darkfader · 2010-10-20 22:33:22 8
  • I think this is the cleanest way of getting the current working directory of a script. It also works on osx, Linux, and probably bsd as well..


    -2
    current_dir=$(cd $(dirname $BASH_SOURCE);pwd)
    xeor · 2011-04-18 09:24:14 3
  • ‹ First  < 5 6 7 8 9 > 

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


Check These Out

download a list of urls

Find the package that installed a command

Generate a random password 30 characters long

Generate a random left-hand password
Generates a random 8-character password that can be typed using only the left hand on a QWERTY keyboard. Useful to avoid taking your hand off of the mouse, especially if your username is left-handed. Change the 8 to your length of choice, add or remove characters from the list based on your preferences or kezboard layout, etc.

vi a new file with execution mode
$ vix /tmp/script.sh Open a file directly with execution permission. Put the function in your .bashrc You can also put this in your vimrc: $ command XX w | set ar | silent exe "!chmod +x %" | redraw! and open a new file like this: $ vi +XX /tmp/script.sh

Check reverse DNS
I'm just a simple programmer. I find dig too verbose. host tells me alias(es) and IP address in a quick to grok format with nothing special to remember for input parameters. With thanks to http://www.cyberciti.biz/faq/how-to-test-or-check-reverse-dns/

Update IP filter for qBittorrent
Downloads Bluetack's level 1 IP blocklist in .p2p format, suitable for various Bittorrent clients.

Swap a file or dir with quick resotre
This lets you replace a file or directory and quickly revert if something goes wrong. For example, the current version of a website's files are in public_html. Put a new version of the site in public_html~ and execute the command. The names are swapped. If anything goes wrong, execute it again (up arrow or !!).

Outputs a 10-digit random number

Find usb device in realtime
Using this command you can track a moment when usb device was attached.


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: