linux:shell_commands:up

.bashrc up

To cd up a certain number of times, add this to your .bashrc file

up() {
        local d=""
        local limit="$1"
        if [ -z "$limit" ] || [ "$limit" -le 0 ]; then
                limit=1
        fi
 
        for ((i=1;i<=limit;i++)); do
                d="../$d"
        done
 
        if ! cd "$d"; then
                echo "Path shallower than $limit";
        fi
}
  • linux/shell_commands/up.txt
  • Last modified: 2022/02/18 07:41
  • by 127.0.0.1