You are here

Ksh/Bash Change Directory commands

posted on 2016-01-25

When you're working in the command-line interface, you may be going deep inside the directories and moving back and forth those directories can be a nuisance. There are built-in directory commands in ksh/bash that you can use to ease your change directory (cd) pain.

How do you use Bash Auto Completion?

A: The file and directory name completion are available by default in bash. To use the default auto completion feature of bash, you'll hit [TAB] Key once or twice.

% ls
four one three two
% ls o[TAB] will automatically match "one"
% ls t[TAB] will not match anything, pressing [TAB] once more will show more.
three two

Q: How to change to a directory from replacing a part of the current path?

A: Ksh and Bash currently don't support this functionality by default, but creating a simple function will achieve this.

Place this function in your ~/.bashrc, /etc/bashrc or /etc/profile, and you'll be able to change directory by replacing a part of the current path. For example, if you wish to change directory from /home/mary/public_html to /home/kevin/public_html, you'll perform the following command: