by vigneshwaran on 9/1/13, 9:22 AM with 49 comments
How to use:
If you are in this path /home/user/project/src/org/main/site/utils/file/reader/whatever and you want to go to site directory quickly, then just type: 'bd site'
In fact, You can simply type 'bd <starting few letters>' like 'bd s' or 'bd si'
If there are more than one directories with same name up in the hierarchy, bd will take you to the closest. (Not considering the immediate parent.)
Using bd within backticks (`bd <letter(s)>`) prints out the path without changing the current directory.
You can take advantage of that by combining `bd <letter(s)>` with other commands such as ls, ln, echo, zip, tar etc..
Check out the screenshot.
by philfreo on 9/1/13, 2:47 PM
"cd -" will jump back to the last directory you were at, regardless of where it is.
Add this to your .bashrc / .zshrc / whatever:
alias cdg='cd $(git rev-parse --show-cdup)'
And then type "cdg" to keep going up directories until you reach whichever folder contains your git repo. Useful when going from "/Users/philfreo/Projects/myproject/myproject/src/assets/js/views/" back up to "/Users/philfreo/Projects/myproject/"
by tytso on 9/1/13, 12:31 PM
function bd () {
OLDPWD=`pwd`
NEWPWD=`echo $OLDPWD | sed 's|\(.*/'$1'[^/]*/\).*|\1|'`
index=`echo $NEWPWD | awk '{ print index($1,"/'$1'"); }'`
if [ $index -eq 0 ] ; then
echo "No such occurrence."
else
echo $NEWPWD
cd "$NEWPWD"
fi
}That way you don't have to execute a separate shell script and source its output. Also note that the "export OLDPWD" wasn't necessary in your script, either. Why pollute the environment of future processes spawned by your shell?
by logn on 9/1/13, 12:55 PM
cd -
That goes to previous dir. A utility that follows this convention but adds some more features would be nice. For instance, maybe typing 'cd -2' could take me back two spots in history, like a web browser.by cygni on 9/1/13, 2:36 PM
alias ..="cd .."
alias ...="cd ../.."
For moving around to other directories I use autojump (https://github.com/joelthelion/autojump).by B-Con on 9/1/13, 7:08 PM
$ pwd
/dir1
$ pushd /some/other/dir
/some/other/dir /dir1
$ pwd
/some/other/dir
$ popd
/dir1
$ pwd
/dir1
by nkuttler on 9/1/13, 7:06 PM
wget -O /usr/bin/bd https:[snip]
chmod +rx /usr/bin/bd
Really? Run wget as root to get a random script, and put it into every user's PATH and a directory that should only be used by the system? :-|by ck2 on 9/1/13, 12:07 PM
by taeric on 9/1/13, 12:16 PM
by Skunkleton on 9/1/13, 3:58 PM
by tobr on 9/1/13, 2:20 PM
by mtdewcmu on 9/1/13, 9:36 PM
by VaucGiaps on 9/1/13, 3:24 PM
alias ..1='cd ..'
alias ..2="cd ../.."
alias ..3="cd ../../.."
alias ..4="cd ../../../.."
alias ..5="cd ../../../../.."
by jvehent on 9/1/13, 6:51 PM
# go up X directories
up_dir() {
num_of_dirs=$1
for i in $(seq 1 $num_of_dirs)
do
cd ..
done
}
alias up=up_dir
Usage: $ pwd
/home/user/svn/automation/puppet/trunk/modules/ossec/templates
$ up 4
$ pwd
/home/user/svn/automation/puppet
by typicalbender on 9/1/13, 1:40 PM
by imurray on 9/1/13, 4:18 PM
function up () { if test $# = 1 ; then s=$( printf "%$1s" ); s=${s// /..\/}; cd $s ; else cd .. ; fi; }
by DiabloD3 on 9/1/13, 11:53 AM
by jmulder on 9/1/13, 8:47 PM
by wicknicks on 9/1/13, 7:50 PM
by helpermethod on 9/2/13, 7:13 AM
by MetaCosm on 9/1/13, 10:12 AM
by Tarrasch on 9/3/13, 11:19 AM
by paulkroka on 9/1/13, 4:39 PM
bind -x '"\C-h":"cd ../;ls"'
(putting it into .bashrc) and then using control-h as a command on the shell to move a directory upwards. very useful for me.
by ballard on 9/1/13, 1:53 PM
by D9u on 9/1/13, 3:37 PM
`whereis -sq <dirname>`
No extra software necessary.
by jostmey on 9/1/13, 3:50 PM