How do I cd into a directory in the home folder?

126,198

Solution 1

cd ~/Downloads

Remember: Linux is case sensitive, so Downloads and downloads are different directories.

~ is a "shortcut" to the home directory. Another one would be $HOME. If you're already in your home directory you can just cd Downloads.

Solution 2

From the Downloads directory, you can quickly return to your home directory by simply typing cd at the prompt. cd ~ does the same thing.

There two basic ways to get around in BASH:

  1. Using absolute pathnames
  2. Using relative pathnames

Absolute pathnames start at the root directory, denoted by a leading /, and can be used from anywhere. To use the absolute path to go to Downloads, you can run:

cd /home/<username>/Downloads

where <username> is replaced with your username. You can also replace it with the environment variable $USER which usually expands to the username of the user currently running the shell. You can also replace /home/<username> with $HOME, which will usually expand to the absolute path of the home directory of the user running the shell.

A useful shortcut for this is

cd ~/Downloads

The tilde character (~) takes the place of /home/<username> - it expands to the home directory of the user currently running the shell. Note that this expansion will not be performed if the tilde character is in double or single quotes.

Relative pathnames start at the working directory (the one you're in). So if you know what directory you're in, you can use some shortcuts to get around. For example

  • . (dot) refers to the current working directory
  • .. (dot)(dot) refers to the parents directory of the current working directory

when you are in your Home folder and type cd Downloads you could also type ./Downloads The ./ is implied when you just type cd Downloads (working directory is implied if you don't include a pathname).

When you are in the Downloads directory, you could also use cd .. to return to the parent directory /home/<username>. In this case it is easiest to just type cd, because that changes the working directory your home directory immediately wherever you are. However, the .. becomes very useful when you are navigating around nested directory structures or other locations on the system.

Share:
126,198

Related videos on Youtube

sam
Author by

sam

Updated on September 18, 2022

Comments

  • sam
    sam over 1 year

    How do I change directories to downloads, from the home folder, in the latest version Ubuntu 12.10? I tried cd /downloads, but it gave an error saying that there is no such directory.

  • WinEunuuchs2Unix
    WinEunuuchs2Unix almost 6 years
    I think this conflicts with the spirit of the question. A person could have 100's of subdirectories under their $HOME and having to create 100's of acronyms and aliasing them would be cumbersome.
  • fixit7
    fixit7 almost 6 years
    No conflict. I am offering help that I have received from others.