Introduction – You need to use the cd command to move from your present directory to another directory. You must have execute or search permission in the specified directory. This page shows basic examples of how to change directory on Linux using the cd command.
How to change directory in Linux
The procedure changes a directory or folder in Linux as follows:
- Let us change to your home directory in Linux, run: cd
- If you want to change to the /etc/security/ directory on Linux, execute: cd /etc/security/
- Want to go up one level of the directory tree in Linux? Try: cd ..
Let us see some examples and usage in details.
Changes the current directory in Linux
Let us change the current working directory to the home (login) directory in Linux, run:
cd
To print the current working directory, use the pwd command:
pwd
Next change to an arbitrary directory named /etc/ufw/, type:
cd /etc/ufw
pwd
At this stage, you may want to list the directory contents. Hence, try the ls command:
ls
ls -l
Say you need to go down one level of the directory tree (say you want to change to the applications.d), run:
cd applications.d
pwd
ls -l
How do I go back to my home folder or directory in Linux?
Simply type any one of the following command:
cd
OR
cd ~
OR
cd $HOME
Changing to another directory in Linux using the cd command
How to change a folder in Linux
Get list of directories only in the current directory using the following:
ls -d */
Once you know the directory names, change it as per your needs:
cd linux
pwd
ls
To move back to a parent directory directory, type:
cd ..
Verify it:
pwd
ls
Linux change directory using the cd command
Linux change directory and symbolic links
One can force symbolic links to be followed. The syntax is:
cd -L dir1
cd -L link2
To use the physical directory structure without following symbolic links:
cd -P link2
Force symbolic links with the -L option and he physical directory structure with the -P option
Conclusion
This page explained the cd command that allows you to change directories. For more info type the following command at the terminal:
cd --help
OR
help cd
🐧 4 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Quick question – Is the cd command depends upon my shell on Apple mac os X?
Yes, the cd is an internal command. Check your shell documentation. Regardless of operating system, the syntax remains same across Linux, *BSD, macOS and Unix-like system
cd dir
cd ..
cd /path/to/dir/
Girl, learn to read the man pages. You can thank me later.
type -a cd
command cd
man bash
man ksh
man csh
help command
help type
That is all we need:
help cd
You see full info:
1678696001603bc59031001_000000