cd changes the current directory. Its argument is the directory to go to:
text
learner@tidepool:~$ cd /home/learner/shop
learner@tidepool:~/shop$ pwd
/home/learner/shop
learner@tidepool:~/shop$ ls
orders prices.txt reportsAfter cd, the prompt shows the new current directory. ls and tree with no argument now use it. So does a file name with no path:
text
learner@tidepool:~/shop$ cat prices.txt
tea 4.50/home/learnercurrent directory
cd ~/shop
/home/learner/shopcurrent directory
Three special forms
| Line | Goes to |
|---|---|
cd | Your home directory |
cd ~ | Your home directory |
cd - | The directory you were in before the last cd. It writes the path |
text
learner@tidepool:~/shop$ cd /etc
learner@tidepool:/etc$ cd -
/home/learner/shop
learner@tidepool:~/shop$When cd fails
cd is part of the shell, not a separate program. So its errors start with bash: cd:.
| Error | Meaning |
|---|---|
bash: cd: /home/learner/shop/order: No such file or directory | There is no item with that name |
bash: cd: notes.txt: Not a directory | The item is a file, not a directory |
When cd fails, the current directory does not change.