Navigating Directories
Tarih: 2026-06-09 | Kategori: Linux
Etiketler: Linux
In a typical graphical interface (desktop environment), you can browse directories using a mouse, but on the Linux terminal, you need to use various commands to navigate, interact with files, and directories.
This section is designed to teach the basics of Linux navigation, including navigating directories, listing files, managing files, and using shortcuts for efficiency.
Linux File System Structure
The Linux file system is hierarchically organized, starting with the root directory `/`. Understanding this structure is key to effectively navigating in Linux.
Getting Started with Linux Navigation
First, it's important to know which directory/location you're in. The `pwd` (print working directory) command will show you your current location in the file system.
user@hackerbox:~$ pwd
/home/user
In the example above, the user is in the `/home/user` directory. The home folder contains individual home directories for users. Each user typically has a home directory, and the terminal starts in the user's home directory when it is first opened.
To list the files and folders in your current directory, you can use the `ls` command.
user@hackerbox:~$ ls
Desktop Documents Downloads Music Pictures Videos
The above example shows the output of the `ls` command. As seen, there are 6 folders in the current location. You can detail the output of the `ls` command using the `-l` option, which shows details such as permissions, ownership, and modification times.
user@hackerbox:~$ ls -l
total 24
drwxr-xr-x 2 user users 4096 Jul 29 08:24 Desktop
drwxr-xr-x 2 user users 4096 Jul 29 08:24 Documents
drwxr-xr-x 2 user users 4096 Jul 29 08:24 Downloads
drwxr-xr-x 2 user users 4096 Jul 29 08:24 Music
drwxr-xr-x 2 user users 4096 Jul 29 08:24 Pictures
drwxr-xr-x 2 user users 4096 Jul 29 08:24 Videos
The output with the `-l` option includes columns with the following structure:
We have listed the contents of the directory, but there might be hidden files/directories we don't see. In Linux, files and directories starting with `.` are considered hidden files (e.g., `.bashrc` file). These won't be listed by default with the `ls` command. To include hidden files in the list, use the `-a` option with `ls`.
user@hackerbox:~$ ls -a
. .. .bashrc Desktop Documents Downloads Music Pictures Videos
As seen, the previously hidden `.bashrc` file is now listed in the output of the `ls` command. You can combine the `-l` and `-a` options with `ls -la`.
user@hackerbox:~$ ls -la
total 36
drwxr-xr-x 8 user users 4096 Jul 29 08:24 .
drwxr-xr-x 3 root root 4096 Jul 28 10:00 ..
-rw-r--r-- 1 user users 3771 Jul 28 10:05 .bashrc
drwxr-xr-x 2 user users 4096 Jul 29 08:24 Desktop
drwxr-xr-x 2 user users 4096 Jul 29 08:24 Documents
drwxr-xr-x 2 user users 4096 Jul 29 08:24 Downloads
drwxr-xr-x 2 user users 4096 Jul 29 08:24 Music
drwxr-xr-x 2 user users 4096 Jul 29 08:24 Pictures
drwxr-xr-x 2 user users 4096 Jul 29 08:24 Videos
As seen, combining the `-l` and `-a` options allows for both detailed listing and inclusion of hidden files.
Navigating to Other Directories
You don't need to be in a directory to list its contents. You can provide the path to a directory as a parameter to the `ls` command:
user@hackerbox:~$ ls -l /var/log
To change your current directory, use the `cd` (change directory) command:
user@hackerbox:~$ cd /tmp
user@hackerbox:/tmp$
If you wish to go back to the previous directory, simply type `cd -`.
user@hackerbox:/tmp$ cd -
/home/user
user@hackerbox:~$
Another feature you should know about while navigating directories is auto-completion. It speeds up your navigation and prevents typos. Type `cd /usr/s` and press the `Tab` key twice, which will suggest directories starting with "s" in the `/usr/` location, allowing you to effortlessly write the path you want to navigate to.