14

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.

22
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.

5

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.

0

You can also shorten typing by using aliases in .bash_aliases which is in your home directory. In this example, typing dwn would take you to your Download directory.

alias dwn='cd /home/andy/Downloads'
  • 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. – WinEunuuchs2Unix Jun 13 '18 at 2:44
  • No conflict. I am offering help that I have received from others. – fixit7 Jun 13 '18 at 2:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.