With a handful of commands and a trick or two, you can move around the Linux file system with ease and never get lost. Credit: Thinkstock One of the first things Linux users need to learn is how to move around the Linux file system and, eventually, how to make it even easier to move around the file system. This post describes both the basic commands you need and some smart moves to make navigating easier. Absolute and relative paths Before we get moving, it’s important to understand the difference between absolute paths (like /home/jdoe) and relative paths (like images/photos and ..). Absolute paths always begin with a / that, of course, represents the base of the file system. If the specified path doesn’t start with a /, it’s relative. Here are some examples of both relative and absolute paths: /tmp /home/jdoe/poems reports .. . Fortunately, getting back home is about the easiest thing you can ever do. You just type cd (change directory) without any arguments and you’ll end up there. Using pwd No matter where you’re headed, it always helps to know where you’re starting from. The pwd command tells you where you are right now. If you just logged in, that will be your home directory. If you’ve been exploring the file system for a while, it could be anywhere that your user account allows you to go. After all, you can’t enter a directory if you don’t have read access. When you use the pwd command to determine your current location, it will tell you where you are situated in the file system using an absolute path. $ pwd /home/justme/images The only complication is that, if you move into a directory using a symbolic link and ask where you are, cd will show you the location using the link. $ ln -s /tmp/test testdir $ cd testdir $ pwd /home/shs/testdir You can, however, try a command like the one below to see where you really are in the file system: $ pwd /home/shs/testdir $ echo $( dirname $(realpath "symlink") ) /tmp/test Using the tree command To get a bigger picture of where you are at any point in time, you can use the tree command. It will display a multi-level view of the files and directories in your current location, providing you with insights into the directory and its contents. $ tree . ├── bin ├── file1 ├── file2 ├── file3 ├── myfile ├── mypipe0 └── testdir -> /tmp/test Using cd The cd (change directory) command will move you into any directory you ask to move to as long as 1) it exists and 2) you have the execute permission. You can only list files if you have read access. The requested location might be a specific full path, a directory relative to your current location or a location that is pointed to by a symbolic link. Here are some examples: $ cd /tmp $ pwd /tmp $ cd $ pwd /home/justme $ cd .. $ pwd /home Using ~ Another way to move back into your home directory is to type cd ~ and, of course, press return. This works because the ~ (tilde) key represents your home directory. That said, this use of ~ isn’t the only thing it’s good for. You can also use ~ to reference your home directory when you’re somewhere else. Here’s an example: $ pwd /tmp $ cp report ~ This command will copy the file named “report” into your home directory quicker than you could type "/home/justme". Making it easier If there are locations in the file system that you need to move into fairly frequently, don’t sit there typing command like "cd /development/docs/reports" to get there. Instead, create a symbolic link with a command like that shown below to move yourself there faster and more easily. $ ln -s /development/docs/reports ~/reports Afterwards, you can get to the directory by typing “cd reports” (or "cd ~/reports if you're not starting from your home directory) and copy files from it with a command like one of these: $ cp reports/latest . The first command copies the file to your current location. The second copies it to your home directory. You can also use the symbolic link to move into the directory whenever you need to and regardless of where you are: $ cd ~/reports $ ls -ltr | tail -1 -rw-rw----. 1 justme justme 22 Aug 22 11:11 report Wrap-up It’s relatively easy (that’s not meant as a pun!) to move around the Linux file system, but good to know that you don’t need to rely on absolute pathnames to get you where you want to go or to copy files to or from other directories. Related content how-to How to examine files on Linux Linux provides very useful options for viewing file attributes, such as owners and permissions, as well as file content. By Sandra Henry Stocker Oct 24, 2024 6 mins Linux how-to 8 easy ways to reuse commands on Linux Typing the same command again and again can become tiresome. Here are a number of ways you can make repeating commands – or repeating commands but with some changes – a lot easier than you might expect. By Sandra Henry-Stocker Oct 15, 2024 5 mins Linux news SUSE Edge upgrade targets Kubernetes and Linux at the edge SUSE Edge 3.1 includes a new stack validation framework and an image builder tool that are aimed at improving the scalability and manageability of complex Kubernetes and Linux edge-computing deployments. By Sean Michael Kerner Oct 15, 2024 6 mins Edge Computing Linux Network Management Software how-to Lesser-known xargs command is a versatile time saver Boost your Linux command line options and simplify your work with xargs, a handy tool for a number of data manipulation tasks. By Sandra Henry Stocker Oct 11, 2024 6 mins Linux PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe