Skip to main content

8 essential Linux file navigation commands for new users

It's straightforward to get around your Linux system if you know these basic commands.
Image
Laptop with sticky note, phone, notepad, and coffee

Image by DarkmoonArt_de from Pixabay

The basics are, well, basic. Yet these fundamental commands and skills are critical for day-to-day work on Linux systems. Sometimes new users are overwhelmed by the details of managing Linux from the command line. What they need is a quick overview or reminder to get them going. The fancy options come later.

To that end, this article gives you eight basic filesystem navigation concepts and commands integral to file management.

What is a path?

Before learning how to navigate the filesystem, it's good to know how Linux organizes data. Navigation is based on the concept of paths. These paths specify what directories to traverse to reach a particular subdirectory or file. The path basically says: go here, go here, go here, and you'll find this.

There are two types of paths: Absolute paths and relative paths.

Absolute path

An absolute path is a complete path to a resource, beginning at the filesystem's root. The filesystem root is represented as a single forward slash: /

This path defines the directory listing from the top of the filesystem. It's best used in scripts, directory mounting commands, and when you might be confused about exactly how to get to a given destination.

Relative path

Relative paths vary by your location in the filesystem, hence the term relative. Therefore, the directories specified in the path change depending on where you are and where you're going. One of the best ways to think about it is to assume you are already partway down the absolute path, and the relative path just defines the rest of the way to the destination.

For example, if you're already in your home directory (for me, that's /home/damon), and you want to find an OGG file in the Rock subdirectory of the Music directory, then you don't have to specify /home/damon—that's already traversed. You just need to specify the rest of the path relative to where you are now. So, the relative path in that situation would be Music/Rock.

8 commands to navigate your Linux filesystem

The following commands are essential knowledge for any Linux user (not just sysadmins). Give them a try and add them to your daily routines.

Find your location

The secret to navigation, whether it's through a mountain chain or the Linux filesystem, is to know where you are. It's very difficult to get somewhere if you don't know where you're starting.

The first command to help with this is pwd. This command displays the present working directory, letting you know where you are now. From there, you could use an absolute or relative path to get to the desired directory.

Another useful command is tree. The tree command displays filesystem information in a similar manner to a graphical interface. This can be handy for new Linux users who are more used to the hierarchical filesystem display in other operating systems.

Image
output of tree command
(Damon Garn, CC BY-SA 4.0)

Go somewhere else

Now that you know where you are and how to use paths to define where you want to go, it's time to cover the cd (change directory) command. This command moves you to the specified directory, changing your present working directory location.

For example, to use an absolute path to move to the /etc/ssh directory, type the following command:

$ cd /etc/ssh

By using the absolute path, it doesn't matter where in the filesystem you currently are.

Take a shortcut

Shortcuts can be handy when it comes to navigation. Linux has been around a long time now (30+ years), and Unix even longer. Over the decades, many shortcuts have been created to make navigation easier. Three of them are:

  • Single dot, or .
  • Double dot, or ..
  • Tilde, or ~

The single dot represents the present working directory, or where you are right now. Say you're in your home directory and you want to copy the sshd_config file from /etc/ssh. You can specify it with just a dot because you're copying the file to your current directory. The command looks like this:

$ sudo cp /etc/ssh/sshd_config .

Double dots represent the parent directory, or the directory immediately above the current one in the filesystem. If there's a subdirectory named Rock in the Music directory, then Music is the parent directory of Rock. As another example, consider where log files are stored: /var/log. In that case, var is the parent directory of log (and the filesystem root / is the parent of var).

So, to move from the current Rock directory to the Music directory above it, type:

$ cd ..

This is much quicker than defining the entire absolute path:

cd /home/damon/Music

[ Keep all your essential commands at your fingertips; download the Linux common commands cheat sheet. ]

Similarly, the tilde character ~ represents the current, logged-on user's home directory. To copy the sshd_config file from /etc/ssh to your home directory (no matter where in the filesystem I'm presently located), type:

$ cp /etc/ssh/sshd_config ~
Copying a file
(Damon Garn, CC BY-SA 4.0)

Again, quicker than cp /etc/ssh/sshd_config /home/damon.

The tilde works with the cd command, too, so you can move to your home directory quickly:

$ cd ~

However, cd itself assumes your home directory if you don't specify an argument, so you can actually jump home with just cd by itself.

Know the essentials

Experienced Linux users will find this summary pretty trivial (though you may find some time-saving tricks in fundamentals writeups such as this), but for new Linux users, commands such as these are essential. They cover basic concepts and tasks that we all do daily.

Do you know other critical file navigation tricks and commands? Consider sharing them by writing an article for Enable Sysadmin; for more information or to submit an article, contact the editorial team at enable-sysadmin@redhat.com.

Check out these related articles on Enable Sysadmin

Topics:   Linux   Command line utilities  
Author’s photo

Damon Garn

Damon Garn owns Cogspinner Coaction, LLC, a technical writing, editing, and IT project company based in Colorado Springs, CO. Damon authored many CompTIA Official Instructor and Student Guides (Linux+, Cloud+, Cloud Essentials+, Server+) and developed a broad library of interactive, scored labs. He regularly contributes to Enable Sysadmin, SearchNetworking, and CompTIA article repositories. Damon has 20 years of experience as a technical trainer covering Linux, Windows Server, and security content. He is a former sysadmin for US Figure Skating. He lives in Colorado Springs with his family and is a writer, musician, and amateur genealogist. More about me

Red Hat Summit 2022: On Demand

Get the latest on Ansible, Red Hat Enterprise Linux, OpenShift, and more from our virtual event on demand.

Related Content

OUR BEST CONTENT, DELIVERED TO YOUR INBOX