Back
This is the function used for Bash, but something similar could be done for others, for example:
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$
/some/dirs/and/subdirs$ cdn 3
/some/dirs/and/subdirs /some/dirs/and/subdirs
/some
/some$ popd
/some/dirs/and/subdirs$
Here is a function that will cd to a named subdirectory above the current working directory:
cdu () { cd "${PWD%/$1/*}/$1"; }
/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
/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
Want to be a Linux expert? Come and join this Linux course
31k questions
32.8k answers
501 comments
693 users