You are on page 1of 2

SOURCE: https://apple.stackexchange.

com/questions/14683/how-to-cd-to-a-directory-
with-a-name-containing-spaces-in-bash
CHANGING DIRECTORY WITH SPACES:

You can use the Tab key after pressing the first few characters (this will then
"fill in" the rest of the folder for you e.g. type cd ~/LTab fills in cd ~/Library/
then type ApTab and it will fill in the rest for you.

If there is a space between words and you don't want to use the methods above, put
a \ (backslash) before the space, e.g. cd ~/Library/Application\ Support.
OR
Use double quote to change directory with spaces
cd "c programming 2018"

COMPLETION:(WHEN YOU DON'T KNOW THE CASE-UPPER OR LOWER CASE IN FORMAT )

Pressing Tab after entering cd ~/L will probably expand it to cd ~/Library/.


Pressing Tab again after entering Ap (you now have cd ~/Library/Ap) will probably
expand it to cd ~/Library/Application\ Support/ (the shell automatically inserted
the escaping backslash).

You can use bind 'set completion-ignore-case on' to make completion case
insensitive:

cd ~/l Tab → cd ~/Library/; ap Tab → cd ~/Library/Application\ Support/

SOURCE:
https://www3.ntu.edu.sg/home/ehchua/programming/howto/Unix_SurvivalGuide.html

An absolute path begins with a "/" (root directory) or "~" (home directory);
whereas a relative path is relative to the current working directory and does NOT
begin with "/" or "~". For example,
$ cd / // Change directory (absolute) to the root
$ cd /usr/local // Change directory (absolute) to "/usr/local"
$ cd mysql // Change directory (relative) to mysql of the current
directory
$ cd myproject/bin // Change directory (relative) to myproject/bin of the
current directory

You can cd in multiple stages (e.g., one cd for each sub-directory - recommended),
or cd in a single stage with the full pathname.

$ cd / // "/"
$ cd usr // "/usr"
$ cd local // "/usr/local"
$ cd mysql // "/usr/local/mysql"
$ cd bin // "/usr/local/mysql/bin"

// Same As
$ cd /usr/local/mysql/bin

You can use "/" to denote the root; "~" to refer to your home directory; ".."
(double-dot) to refer to the parent directory; "." (single-dot) to refer to the
current directory; and "-" (dash) to refer to the previous directory. For example,

$ cd ~ // Change directory to the home directory of the current user


$ cd // same as above, default for "cd" is home directory
$ cd ~/Documents // Change directory to the sub-directory "Documents" of the home
directory of the current user
$ cd .. // Change directory to the parent directory of the current
working directory
$ cd - // Change directory to the previous working directory (OLDPWD)

ls (List Directory's Contents):


You can use command ls to list the contents of the current working directory, e.g.,

// List contents of current working directory in short format


$ ls

// List in long format


$ ls -l

Wildcard *
You can list selected files using wildcard *, which matches 0 or more (any)
characters. For examples,

$ ls *.java // List files ending with ".java" in short format (default)


$ ls -l *.java // List files ending with ".java" in long format
$ ls -ld my* // List files and directories beginning with "my" in long format

Previous Commands in Command History: You can use the up/down arrow keys to
retrieve the previous/next command in the command history.

Auto-Complete: You can type the first few characters for the pathname or filename,
and press TAB key to auto-complete.

You might also like