Navigating your filesystem in the Linux terminal (2023)

Posted: June 11, 2019 | | by Seth Kenlon (Editorial Team, Red Hat)

Image

Navigating your filesystem in the Linux terminal (1)

You probably learned how to interact with a computer using a GUI, and you're probably very good at it. You may be surprised to learn, then, that there's a more direct way to use a computer: a terminal, or shell, which provides a direct interface between you and the operating system. Because of this direct communication without the intervention of additional applications, using a terminal also makes it easy to script repetitive tasks, and design workflows unique to your own needs.

There's a catch, however. As with any new tool, you have to learn the shell before you can do anything useful with it.

This article compares navigating a computer desktop without the desktop. That is, this article demonstrates how to use a terminal to move around and browse your computer as you would on a desktop, but from a terminal instead.

While the terminal may seem mysterious and intimidating at first, it's easy to learn once you realize that a terminal uses the same information as all of your usual applications. There are direct analogs for everything you do in a GUI to most of the everyday activities you do in a terminal. So instead of starting your journey with the shell by learning terminal commands, begin with everyday tasks that you're already familiar with.

View file lists

Navigating your filesystem in the Linux terminal (2)

Navigating your filesystem in the Linux terminal (3) To list the files on your computer or device, you generally open a file manager application, whether it's called Explorer (Windows), Finder (Mac), Nautilus (GNOME), Amaze (Android), or anything else.

Navigating your filesystem in the Linux terminal (4) The ls (list) command lists all files in the current directory.

The pwd (print working directory) command tells you what directory you're currently in. From there, the ls (list) command shows you what's in that (or any other) directory:

$ pwd/home/seth$ ls...binDesktopdespacer.shdocumentation.zipDocumentsMusicpeoplePicturesPublic

The first items listed are dots. The single dot is a meta-location, meaning the folder you are currently in.

The double dot is an indicator that you can move back from this location. That is, you're in a folder inside of another folder. Once you start moving around within your computer, you can use that information for reference.

You may also notice that it's hard to tell a file from a folder. Some Linux distributions have colors pre-programmed so that folders are blue, files are white, binary files are green, and so on. If you don't see those colors, you can use ls --color to try and activate that feature. Colors don't always transmit over remote connections to distant servers, though, so a common and generic method to make it clear what are files and what are folders is the --classify (-F) switch:

$ ls --classify ...bin/Desktop/despacer.shdocumentation.zip*Documents/Music/people/Pictures/Public/

Folders are given a trailing slash (/) to denote that they are directories. Binary entities, like ZIP files and executable programs, are indicated with an asterisk (*). Plain text files are listed without additional notation.

If you're used to the dir command from Windows, you can use that on Linux as well. It works exactly the same as ls.

[Free download: Advanced Linux commands cheat sheet.]

Open a folder

Navigating your filesystem in the Linux terminal (5)

Navigating your filesystem in the Linux terminal (6) Double-click on a folder. When it opens, you are "in" that folder.

Navigating your filesystem in the Linux terminal (7) The cd (change directory) command opens a folder and makes it your new current working directory.

To open—or enter—a folder on the command line, use the cd (change directory) command as follows:

$ pwd/home/seth$ cd bin$ pwd/home/seth/bin$ lscrossfade.shfopnormy.sh

Close a folder

Navigating your filesystem in the Linux terminal (8)

Navigating your filesystem in the Linux terminal (9) Close the desktop window you're in, or press the Back button in your file manager to leave the folder.

Navigating your filesystem in the Linux terminal (10) You don't so much close a folder on the command line, as you leave it.

On a desktop, you judge your current location by what window you have open. For instance, when you open a window and click on the Documents folder icon, you think of yourself as being in your Documents folder.

In a terminal, the closest thing to this concept is the shell prompt. In most shells, your prompt is a dollar sign ($), and its location within the computer can change depending on where you tell your terminal to go. You can always learn your current location with the pwd (print working directory) command:

$ pwd/home/seth

If you're in one location because you used the cd command, you can "close" that location by going back to your home directory. This directory is, more or less, your terminal's desktop—it's the place you find yourself staring at when you first open the terminal.

The command for returning home is the cd command with no location specified (shorthand for cd ~):

$ cd$ pwd/home/seth

Navigate directories

Navigating your filesystem in the Linux terminal (11)

Navigating your filesystem in the Linux terminal (12) Open a window, double-click on a folder, and then double-click on a sub-folder. Use the Back button to backtrack.

Navigating your filesystem in the Linux terminal (13) The cd (change directory) command moves you into a different directory. To move out of that directory, use cd along with the path to some other location, or use double dots to backtrack, or return home to navigate from there.

Navigating a Linux computer is like navigating the internet. The very concept of a URL is pulled directly from UNIX. When you navigate to a specific page on a website, like https://www.redhat.com/en/topics/linux, you're actually changing directory to /var/www/redhat.com/en/topics/linux (this isn't exactly true for pages built by PHP and other dynamic languages, but even they are essentially building a virtual file system).

To go back a page in this example, delete the linux part of the URL. You're taken to a new location, the parent directory, containing a different file for you to view. Because this happens inside your web browser, you probably don't think of it as navigating a computer, but you use the same principle in a Linux terminal.

Think of your computer as the internet (or the internet as a computer, more appropriately). If you start in your home folder, then all of your personal files can be expressed using your home as the starting point. Think of your home folder as a web URL's domain. Instead of a URL, the term directory path or file path is used. Here are some example paths:

  • /home/seth/bin
  • /home/seth/despacer.sh
  • /home/seth/documentation.zip*
  • /home/seth/people

Because you return home often, your home directory can be abbreviated as ~. For instance:

  • ~/bin
  • ~/despacer.sh
  • ~/documentation.zip*
  • ~/people

To navigate directly to the people folder, use the cd command along with the entire directory path:

$ cd ~/people$ pwd/home/seth/people

Suppose that inside the people folder, there are the directories developers and marketing.

Now that you're inside the people directory, you can move out of it in one of three different ways.

One option is to navigate into a different directory from where you are now. This method uses a dot as your starting point.

Remember that a dot is a meta-location, meaning "where I am right now." This method is akin to, for instance, manually adding a level in a URL, such as changing https://www.redhat.com/en/topics to https://www.redhat.com/en/topics/linux. So, to change to the developers directory from your current location, do the following:

$ cd ./developers$ pwd/home/seth/people/developers

You could move through all of your directories this way: change directory to one folder, list its contents, and then move into the next one, and so on. However, if you know the path of where you want to go, you can transport yourself there instantly all in one command. To reach the to /home/seth/people/developers directory instantly from anywhere, instantly:

$ cd ~/people/developers$ pwd/home/seth/people/developers

Once in a directory, you always have the option to backtrack out of your current location using the meta-location .. to tell cd to take you up one folder:

$ cd ..$ pwd/home/seth/people

You can keep using this trick until you have nowhere left to go:

$ cd ..$ pwd/home/seth$ cd ..$ pwd/home$ cd ..$ pwd/

You can also always return to your home directory instantly using this shortcut:

$ cd ~$ pwd/home/seth

Because users go home often, most shells are set to go back home should you type cd with no destination:

$ cd$ pwd/home/seth

Absolute paths

File paths technically start at the very root of your computer's file tree. Even your home directory starts at the very bottom of the tree. This fact is significant because system administrators deal with lots of data that exists outside of their own home directory.

When you go as far back in a file path you can go, you reach the root directory, represented by a single slash (/). You see the root directory at the beginning of all absolute paths:

  • /home/seth
  • /etc/apache2/apache.conf
  • /var/www/htdocs

When in doubt, you can always use the absolute path to any location:

$ cd ~/people/developers$ pwd/home/seth/people/developers

To find where you want to go, use the ls command to "open" a directory and look inside:

$ ls --classify ~/people/developers/marketing/$ cd /home/seth/people/developers$ pwd/home/seth/people/developers

Conclusion

Try navigating through your system using the terminal. As long as you restrict yourself to the cd, ls, and pwd commands, you can't do any harm, and the practice will help you get comfortable with the process. On most systems, the Tab key auto-completes file paths as you type, so if you're changing to ~/people/marketing, then all you need to type is cd ~/people/m and then press Tab. If Tab is unable to complete the path, you know that you either have the wrong path or there are several directories with similar names, so your shell is unable to choose which to use for auto-completion.

Navigating in the terminal takes practice, but it is far faster than opening and closing windows, and clicking on Back buttons and folder icons, especially when you already know where you want to go. Give it a try!

Topics: Linux

FAQs

How do I navigate a file in Linux terminal? ›

To navigate to your home directory, use "cd" or "cd ~" To navigate up one directory level, use "cd .." To navigate to the previous directory (or back), use "cd -" To navigate through multiple levels of directory at once, specify the full directory path that you want to go to.

Which commands are used to navigate through the Linux filesystem? ›

Navigate the Linux File system with more basic commands
  • cp. cp stands for copy. ...
  • mv. mv: move, similar to copy but moves the file, and removes the original. ...
  • cd. cd: change directory. ...
  • mkdir. mkdir: Create a new directory. ...
  • rm. rm: remove. ...
  • df. df: Disk Free. ...
  • du. du: This at times may be called “Disk Usage”. ...
  • ln -s.
Sep 18, 2019

How to find files in Linux by filesystem? ›

You can use the find command to search for a file or directory on your file system. By using the -exec flag ( find -exec ), matches, which can be files, directories, symbolic links, system devices, etc., can be found and immediately processed within the same command.

How do I navigate a file and folder in Linux? ›

The cd (change directory) command moves you into a different directory. To move out of that directory, use cd along with the path to some other location, or use double dots to backtrack, or return home to navigate from there. Navigating a Linux computer is like navigating the internet.

How do I navigate a file in command prompt? ›

How to run a file in command prompt
  1. Open command prompt. There are several ways to open the command prompt app. ...
  2. Open the file pathway. To open the correct file, direct the command prompt app to the correct file path in your Windows by using this command template: cd [file path]. ...
  3. Execute the file. ...
  4. Launch and use your file.
Jun 24, 2022

What is navigation command in Linux? ›

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.

What command is used to navigate the file system? ›

cd Change Directory

The shell command cd is used to move throughout the filesystem of a computer. It accepts a variety of arguments: Full file paths.

How do I access files in Linux? ›

To open a file using a file manager, follow the steps below:
  1. Step 1: Open the file manager by clicking on the File Manager icon in the Application menu.
  2. Step 2: Move to the location (file path) where the source file is already stored.
  3. Step 3: Click on the file to open it.
Feb 27, 2023

How do I list all file systems in Linux? ›

The ls command is used to list files or directories in Linux and other Unix-based operating systems. Just like you navigate in your File explorer or Finder with a GUI, the ls command allows you to list all files or directories in the current directory by default, and further interact with them via the command line.

How to check file system terminal? ›

Checking the integrity of a file system (fsck command)
  1. To check all the default file systems, type the following: fsck. ...
  2. To fix minor problems automatically with the default file systems, type the following: fsck -p.
  3. To check the /dev/hd1 file system , type the following: fsck /dev/hd1.

How to create filesystem in Linux? ›

To create a filesystem, there are three steps:
  1. Create partitions using fdisk or Disk Utility. ...
  2. Format the partitions using mkfs or Disk Utility.
  3. Mount the partitions using the mount command or automate it using the /etc/fstab file.
Jan 24, 2022

How do I mount a file system in Linux? ›

Mounting a file system on Linux is generally a straightforward two-step process: create a mount point directory, and use the mount command to mount the device at the mount point. Unless the file system is in use, unmounting is even simpler, requiring only the umount command.

How do I move a text file in Linux? ›

To move files, use the mv command (man mv), which is similar to the cp command, except that with mv the file is physically moved from one place to another, instead of being duplicated, as with cp.

How do I find where a file is stored in Linux? ›

/path/to/file is the directory in which you want to search for the file. For example, to search the current directory, use . as the path. To search your entire Linux file system, use / as the path.

How do I navigate to a folder? ›

Type cd followed by a space in the command prompt window. Drag and drop the folder you want to browse into the window. Press Enter.

How do I navigate to a folder in files? ›

Displaying Subfolders
  1. Click on a folder if it's listed in the Navigation pane.
  2. Click on a folder in the Address bar to display its subfolders.
  3. Double-click on a folder in the file and folder listing to display any subfolders.

How do I open a file in Terminal? ›

To open any file from the command line with the default application, just type open followed by the filename/path.

How do I change directory in Linux command line? ›

Using the cd command in Linux allows you to change the current working directory.
...
Linux CD Command Syntax
  1. cd : Invokes the cd command.
  2. [options] : Adding options changes the way the command executes.
  3. [directory] : Path to the directory you want to move into.
Dec 8, 2021

What are the 4 types of navigation commands? ›

There are four different navigation commands in Selenium WebDriver:
  • > driver.navigate().to(“URL”) > To navigate to the provided page URL.
  • > driver.navigate().back() > To navigate back to the previous page. ...
  • > driver.navigate().forward() > To navigate forward to the page. ...
  • > driver.navigate().refresh() > To refresh the page.

How do I navigate more in Linux? ›

Interactive Commands
  1. Enter key : To scroll down page line by line.
  2. Space bar : To go to next page. ...
  3. d or ^D : To scroll k lines of text forward. ...
  4. b or ^B : To skip backwards k screenfuls of text. ...
  5. s : Skip forward k lines of text. ...
  6. /pattern : Lets you search for kth occurrence of regular expression.

How do I open a file in a directory in Linux? ›

Following are some useful ways to open a file from the terminal:
  1. Open the file using cat command.
  2. Open the file using less command.
  3. Open the file using more command.
  4. Open the file using nl command.
  5. Open the file using gnome-open command.
  6. Open the file using head command.
  7. Open the file using tail command.

How do I navigate to home directory in Linux? ›

How to change directory in Linux terminal
  1. To return to the home directory immediately, use cd ~ OR cd.
  2. To change into the root directory of Linux file system, use cd / .
  3. To go into the root user directory, run cd /root/ as root user.
  4. To navigate up one directory level up, use cd ..
Apr 4, 2023

How do I navigate in Unix? ›

Navigation in Unix is the same thing as pointing and clicking in a typical graphical user interface. For example, if you have the folder “ExperimentFolder” on my Desktop, you can point and double-click to open it.

How do I navigate a program file? ›

How to open Program Files folder
  1. Open File Explorer.
  2. Select This PC or Computer.
  3. Open the C: drive.
  4. Open the Program Files or Program Files (x86) folder.
Aug 16, 2021

How to find all 777 files in Linux? ›

find /home/ -perm 777 -type f

This command will list all the files inside the home directory with 777 permissions.

How do I move all files in Linux? ›

Using mv Command

The mv command is used to move files and directories from one place to another. We can also use it to rename files and directories. This will move all the files from /path/subfolder to /path/ except for hidden files and directories.

What is the Linux file system? ›

What is the Linux File System? Linux file system is generally a built-in layer of a Linux operating system used to handle the data management of the storage. It helps to arrange the file on the disk storage. It manages the file name, file size, creation date, and much more information about a file.

How do I change the file system type in Linux? ›

Formatting Disk Partition with NTFS File System
  1. Run the mkfs command and specify the NTFS file system to format a disk: sudo mkfs -t ntfs /dev/sdb1. ...
  2. Next, verify the file system change using: lsblk -f.
  3. Locate the preferred partition and confirm that it uses the NFTS file system.
Dec 2, 2020

How do I mount a disk to a directory in Linux? ›

To mount a disk using the Mount command:
  1. In the Terminal window, type sudo mount /dev/
  2. Type the name of your drive that you noted down earlier.
  3. Press Space and type /media/
  4. Type the name of the directory you created above.
  5. Your full command should now look something like this: sudo mount dev/sdb2 /media/mydrivename.
Mar 1, 2023

How do I create a file in a directory in Linux terminal? ›

The basic syntax for using this command is mkdir {dir} (replace {dir} with the desired name of your directory). Before creating any directory or file, remember that most Linux filesystems are case-sensitive.

How do I find the path of a file in Linux terminal? ›

Get the Full Path of a File in Linux
  1. Using the readlink command. The “readlink” command is used to resolve symbolic links. ...
  2. Using the realpath command. The “realpath” command is used for resolving the absolute file names. ...
  3. Using the ls command. ...
  4. Using the find command.
Dec 19, 2022

How do I navigate to a file in bash? ›

If you want to navigate to a different directory, you use the “cd” command, followed by the directory you want to go to. So, if you want to change your current directory to the “Documents” folder, you have to type in “cd Documents”. To go back to the previous directory, you type “cd” followed by two dots (“cd ..”).

How do I open and edit a file in Linux terminal? ›

How to edit files in Linux
  1. Press the ESC key for normal mode.
  2. Press i Key for insert mode.
  3. Press :q! keys to exit from the editor without saving a file.
  4. Press :wq! Keys to save the updated file and exit from the editor.
  5. Press :w test. txt to save the file as test. txt.

How do I access a folder in Linux? ›

To open a directory on a computer with a graphical interface, you double-click on a folder. It opens, and you are now "in" that folder. To open a directory in a terminal, you use the cd command to change your current directory. This essentially opens that folder and places you in it.

How do I open a file in terminal with code? ›

Enable VS Code in your terminal
  1. Open Visual Studio Code.
  2. Press command + shift + p to open the command palette, then type "install code", and then click Shell command: Install 'code' command in PATH.
  3. In your terminal, type code YOUR_FILENAME` to open that file in VS Code.

How to open a file in Linux? ›

Step 1: Open the file manager by clicking on the File Manager icon in the Application menu. Step 2: Move to the location (file path) where the source file is already stored. Step 3: Click on the file to open it. If the file is a text file, it will be opened in the default text editor.

How to read a file in Linux? ›

Following are some useful ways to open a file from the terminal:
  1. Open the file using cat command.
  2. Open the file using less command.
  3. Open the file using more command.
  4. Open the file using nl command.
  5. Open the file using gnome-open command.
  6. Open the file using head command.
  7. Open the file using tail command.

What is the full path of a file in Linux? ›

Get Absolute File Path in Linux
  1. Use readlink to get file path.
  2. Use realpath to get full file path.
  3. Use the find command to get the absolute file path.
  4. Print full path with the ls command.
  5. Conclusion.
Sep 13, 2022

What is the Bash command in Linux? ›

A bash script is a file containing a sequence of commands that are executed by the bash program line by line. It allows you to perform a series of actions, such as navigating to a specific directory, creating a folder, and launching a process using the command line.

References

Top Articles
Latest Posts
Article information

Author: Rubie Ullrich

Last Updated: 11/26/2023

Views: 6678

Rating: 4.1 / 5 (52 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Rubie Ullrich

Birthday: 1998-02-02

Address: 743 Stoltenberg Center, Genovevaville, NJ 59925-3119

Phone: +2202978377583

Job: Administration Engineer

Hobby: Surfing, Sailing, Listening to music, Web surfing, Kitesurfing, Geocaching, Backpacking

Introduction: My name is Rubie Ullrich, I am a enthusiastic, perfect, tender, vivacious, talented, famous, delightful person who loves writing and wants to share my knowledge and understanding with you.