Linux Commands Syntax: The cd Command

Linux Commands Syntax: The cd Command
Page content

History

The “cd” command is one of those commands that would make your command line administration life quite challenging if you had to do without it. Why? The “cd” command allows you to change directories (hence the “cd”) within the Linux directory hierarchy. The “cd” command comes from the old POSIX system call “chdir”. As with many Linux commands “cd” is available for use in shell scripts and bash files.

Usage

As you would expect, the “cd” command is used to change from the current working directory to another directory. Since the “cd” command is a global command (the executable “cd” binary is in /usr/bin so all users have access to the command) you can use the “cd” command within any directory, no matter where you are in the filesystem hierarchy.

In order to use the “cd” command you have to have a terminal window (such as gnome-terminal, konsole, or aterm) open. All commands will be entered at the bash prompt.

Let’s say, for example, you are in your home directory (in our example we’ll use /home/jack) and you want to be in the /etc directory. To change to the /etc directory you would type the command cd /etc and hit enter to change to /etc. Now let’s say you are in the /usr/share/e16/themes directory and you want to go back to your home directory. There are three ways you can do this: cd /home/jack, cd ~/, or cd. No matter which method you use, you will be in your home directory.

Now let’s say you are in /usr/share/e16/backgrounds and you want to move up a level to /usr/share/e16. Instead of typing cd /usr/share/e16 you could just enter cd ../ which moves you up one directory. If you wanted to move up two directories you would type cd ../../ and so on.

Final Thoughts

You will find that in order to administer a Linux machine, the cd command will become an indispensable tool in your toolkit. Fortunately the cd command is a simple command to use. And don’t worry about that “~” character. Eventually your fingers will get used to where it is and you’ll be typing cd ~/ in your sleep.

This post is part of the series: Linux Command Line

If you ever plan on doing any administration on a Linux machine, you would be well served to get to know the command line interface. In this Bright Hub series you will be introduced to various concepts surrounding one of the most powerful admin tools around.

  1. Linux Command Line: Introduction
  2. Linux Command Line: ls
  3. Linux Command Line: cd
  4. Linux Command Line: mkdir
  5. Linux Command Line: df
  6. Linux Command Line: ln
  7. Linux Command Line: top
  8. Linux Command Line: mount/umount
  9. Linux Command Line: Cron/Crontab
  10. Linux Command Line: chmod
  11. Linux Command Line: wget
  12. Linux Command Line: cat
  13. Linux Command Line: grep
  14. Linux Command Line: dd
  15. Linux Command Line: sudo
  16. Linux Command Line: startx
  17. Linux Command Line: adduser
  18. Linux Command Line: at
  19. Linux Command Line: aterm
  20. Linux Command Line: nano
  21. Linux Command Line: hostname