Commands using cd (214)

  • MacOS Solution due to lack of pidof command and procfs on MacOS Kernel. Show Sample Output

    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 0
  • 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

    (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 13

  • -1
    cd -
    m13a · 2009-02-06 09:35:18 0
  • only works for freeBSD where ports are installed in /usr/ports credit to

    cd /usr/ports; grep -F "`for o in \`pkg_info -qao\` ; \ do echo "|/usr/ports/${o}|" ; done`" `make -V INDEXFILE` | \ grep -i \|[email protected]\| | cut -f 2 -d \|
    grep · 2009-02-16 21:07:35 0

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

    tar cf - . | (cd /new/dir; tar xvf -)
    jauderho · 2009-03-09 20:30:34 7
  • 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

    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 3
  • search argument in PATH accept grep expressions without args, list all binaries found in PATH Show Sample Output

    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 "[email protected]^\./@@" |egrep -i "${*}" |sed "[email protected]^@$L/@" ; done ; }
    mobidyc · 2009-09-11 15:03:22 2
  • 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

    wtzc () { wget "[email protected]"; foo=`echo "[email protected]" | 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 0
  • using "!$" will save another ton of typing than 'ALT+.' or ' .' Show Sample Output

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

    svn co cd ./trunk/xulapp/ xulrunner --install-app && Xvfb :1 && DISPLAY=:1 xulrunner application.ini 2>/dev/null 1>/dev/null && wget -O- ""
    argv · 2010-10-16 05:12:11 0
  • Add dirs to list: pushd /tmp /tmp ~ then cd - /home/user cd - /tmp

    cd -
    magicjohnson_ · 2011-07-05 05:28:32 2
  • 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.

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

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

  • -1
    cd /System/Library/LaunchDaemons; sudo launchctl load -w
    evandrix · 2012-05-16 15:42:10 0
  • 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

    find . -maxdepth 2 -type d -name '.git' -print0 | while read -d ''; do (cd "$REPLY"; git gc); done
    unhammer · 2012-11-07 08:38:33 0
  • 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 ~'

    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 0
  • 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

    cd /d d:\Windows
    piyo · 2009-02-13 16:06:48 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. Show Sample Output

    alias mux='clear && cd ~/Music/ && ls && echo -n "File> " && read msi && mplayer ~/Music/$msi'
    Noxn · 2009-03-23 10:45:27 0
  • 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

    tar cpof - src |( cd des; tar xpof -)
    davidpotter42 · 2009-09-20 20:43:30 0
  • 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. [[email protected] ~]$ ls foo bar 2. [[email protected] ~]$ cd foo 3. [[email protected] foo]$ removedir 4. yes 5. rm -Rf foo/ 6. [[email protected] ~]$ 7. [[email protected] ~]$ ls bar Show Sample Output

    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 3
  • 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

    for d in $(find . -maxdepth 1 -type d -name '[^.]*'); do cd "$d"; svn up; cd ..; done
    udog · 2010-05-28 10:09:19 0
  • 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   PermitRootLogin without-password

    alias sshdo='ssh -q -t [email protected] -- cd $PWD \&\& sudo'
    darkfader · 2010-10-20 22:33:22 5
  • 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..

    current_dir=$(cd $(dirname $BASH_SOURCE);pwd)
    xeor · 2011-04-18 09:24:14 0
  • PmWiki stores wiki pages as Group.Name. Simply split the directory listing and count frequency of group occurances. Show Sample Output

    cd /path/to/pmwiki/wiki.d;/bin/ls -1 | perl -ne 'my ($group,$name)=split(/\./);$counts{$group}++;' -e 'END { foreach $group (sort keys %counts) {printf("%d\t%s\n",$counts{$group},$group);} }'|sort -rn
    tamouse · 2011-09-14 19:33:39 0
  • ‹ First  < 5 6 7 8 9 > 

What's this? 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

ignore hidden directory in bash completion (e.g. .svn)

apt-get upgrade with bandwidth limit
in Debian-based systems apt-get could be limited to the specified bandwidth in kilobytes using the apt configuration options(man 5 apt.conf, man apt-get). I'd quote man 5 apt.conf: "The used bandwidth can be limited with Acquire::http::Dl-Limit which accepts integer values in kilobyte. The default value is 0 which deactivates the limit and tries uses as much as possible of the bandwidth..." "HTTPS URIs. Cache-control, Timeout, AllowRedirect, Dl-Limit and proxy options are the same as for http..."

List all databases in Postgres and their (byte/human) sizes, ordering by byte size descending
Get a listing of all of your databases in Postgres and their sizes, ordering by the largest size first. Requires that you give the -d parameter a valid database name that you can connect to.

print indepth hardware info
wanna know something about your hardware? how about EVERYTHING?? then this should do ya well

Adding a startup script to be run at bootup Ubuntu
This script will run each time you boot up.The script must be in /etc/init.d directory.

Take screenshots with imagemagick

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

List contents of tar archive within a compressed 7zip archive
Sometimes it is handy to be able to list contents of a tar file within a compressed archive, such as 7Zip in this instance, without having to extract the archive first. This is especially helpful when dealing with larger sized files.

list block devices
Shows all block devices in a tree with descruptions of what they are.

Batch file name renaming (copying or moving) w/ glob matching.

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.


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: