How to open a file in a directory in Linux and how to open a directory in Linux using terminal. You can open directory from terminal Ubuntu.
The cd Command
The cd command is used to navigate through files and directories.
cd Command: The cd command allows you to change directories.
Note that when you open a terminal you will be in your home directory. The tilde (~) symbol stands for your home directory. If you are user, then the tilde (~) stands for /home/user
To navigate or move around the file system you will use various cd commands, such as:
- Use “cd /” to navigate into the root directory.
- Use “cd” or “cd ~” to navigate to your home directory.
- Use “cd ..” to navigate up one directory level.
- Use “cd -” to navigate to the previous directory or navigate to back.
If you want to navigate and go directly to a specific directory at once, you will have to specify the full directory path where you want to go to.
For example, if you want to navgate to applications folder in usr/share folder, run the command “cd /usr/share/applications” to go directly to the /applications subdirectory of /usr/share/.
Similarly, you can use “cd ~/Desktop” to go to the Desktop.
Using cd Command
- The / symbol with the cd command helps you in directly opening the root folder.
- The ‘..’ symbol with the cd command helps you in navigating up one directory level:
- The ‘-’ symbol with the cd command takes you in back to the previous folder you were in.
You can use the pwd command to know in which directory you’re located. Note that pwd stands for “print working directory”.
The ls command shows the ‘list’ of the files in your current directory. The “ls ~” command will show you the files that are in your home directory.