in general we use
cd ..
for going to the parent directory
cd ../../
to go to the parents parent directory. and
cd ../../../../../
for 5th parent directory.
is there any simplified way of doing this?
shell i am using is ksh.
To go up one level of the directory tree, type the following: cd .. The special file name, dot dot ( .. ), refers to the directory immediately above the current directory, its parent directory.
To change your current working directory to its parent folder (move one branch down the directory tree): > cd .. To move the file data.
You can go back to the parent directory of any current directory by using the command cd .. , as the full path of the current working directory is understood by Bash . You can also go back to your home directory (e.g. /users/jpalomino ) at any time using the command cd ~ (the character known as the tilde).
And I thought I was lazy...
Long ago, I got tired of typing cd ..
so, since roughly 1988 one of my standard aliases (and batch files for MSDOS/Windows) is up
. Perhaps I should extend the concept:
alias up='cd ..'
alias up2='cd ../..'
alias up3='cd ../../..'
alias up4='cd ../../../..'
alias up5='cd ../../../../..'
alias up6='cd ../../../../../..'
This function is for Bash, but something similar could be done for others (this may work as-is in ksh and zsh):
cdn () { pushd .; for ((i=1; i<=$1; i++)); do cd ..; done; pwd; }
Example usage:
/some/dirs/and/subdirs$ cdn 3
/some/dirs/and/subdirs /some/dirs/and/subdirs
/some
/some$ popd
/some/dirs/and/subdirs$
Here's a function that will cd
to a named subdirectory above the current working directory:
cdu () { cd "${PWD%/$1/*}/$1"; }
Example usage:
/usr/share/atom/resources/app/apm/src/generator$ cdu apm
/usr/share/atom/resources/app/apm$ cdu resources
/usr/share/atom/resources$ cd -
/usr/share/atom/resources/app/apm$ cdu share
/usr/share
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With