# Navigate Linux and read file content

In this reading, you’ll review how to navigate the file system using Linux commands in Bash. You’ll further explore the organization of the Linux Filesystem Hierarchy Standard, review several common Linux commands for navigation and reading file content, and learn a couple of new commands.

## Filesystem Hierarchy Standard (FHS)

Previously, you learned that the **Filesystem Hierarchy Standard** **(FHS)** is the component of Linux that organizes data. The FHS is important because it defines how directories, directory contents, and other storage is organized in the operating system.

This diagram illustrates the hierarchy of relationships under the FHS:

<div class="rc-CML" dir="auto" id="bkmrk-"><div><div data-track="true" data-track-action="click" data-track-app="open_course_home" data-track-component="cml" data-track-page="item_layout" role="presentation"><div data-track="true" data-track-action="click" data-track-app="open_course_home" data-track-component="cml_link" data-track-page="item_layout"><div class="css-1k5v0wb" data-testid="cml-viewer"><div><figure contenteditable="false" role="figure">![Flowchart starts with the root directory at the top and branches down into multiple subdirectories.](https://d3c33hcgiwev3.cloudfront.net/imageAssetProxy.v1/j0RYvFG7TpGNNfni5SSa0Q_012d7d577b564b4fa3ead21d3f69ebf1_Dvcfull14z4M8iWFX3SE6wnrTefQLql8gas9ICAiKpixcG31SsHLbQmACjE1B4qfpEwTcHfkiD1hxEVGhjyYngw0-fXASC-TSuTgXTBpz_qS4pmXtp-Y7i7giD3GJKCkvajg0PzNebmAf6wDKOBNL-SrMDhBJhsE4yH5Es2_bKRVPC0goRafLVPJs81beg?expiry=1688688000000&hmac=wJrU0NP40u2Z7UeZDqrJNIT6IBHtLTixNycjNUzUfJA)</figure></div></div></div></div></div></div>Under the FHS, a file’s location can be described by a file path. A **file path** is the location of a file or directory. In the file path, the different levels of the hierarchy are separated by a forward slash (<var>/</var>).

### **Root directory**

The **root directory** is the highest-level directory in Linux, and it’s always represented with a forward slash (<var>/</var>). All subdirectories branch off the root directory. Subdirectories can continue branching out to as many levels as necessary.

### Standard FHS directories

Directly below the root directory, you’ll find standard FHS directories. In the diagram, <var>home</var>, <var>bin</var>, and <var>etc</var> are standard FHS directories. Here are a few examples of what standard directories contain:

<div class="rc-CML" dir="auto" id="bkmrk-%2Fhome%3A-each-user-in-"><div><div data-track="true" data-track-action="click" data-track-app="open_course_home" data-track-component="cml" data-track-page="item_layout" role="presentation"><div data-track="true" data-track-action="click" data-track-app="open_course_home" data-track-component="cml_link" data-track-page="item_layout"><div class="css-1k5v0wb" data-testid="cml-viewer">- <var>/home</var>: Each user in the system gets their own home directory.
- <var>/bin</var>: This directory stands for “binary” and contains binary files and other executables. Executables are files that contain a series of commands a computer needs to follow to run programs and perform other functions.
- <var>/etc</var>: This directory stores the system’s configuration files.
- <var>/tmp</var>: This directory stores many temporary files. The <var>/tmp</var> directory is commonly used by attackers because anyone in the system can modify data in these files.
- <var>/mnt</var>: This directory stands for “mount” and stores media, such as USB drives and hard drives.

</div></div></div></div></div>**Pro Tip**: You can use the <var>man hier</var> command to learn more about the FHS and its standard directories.

### **User-specific subdirectories**

Under <var>home</var> are subdirectories for specific users. In the diagram, these users are <var>analyst</var> and <var>analyst2</var>. Each user has their own personal subdirectories, such as <var>projects</var>, <var>logs</var>, or <var>reports</var>.

**Note:** When the path leads to a subdirectory below the user’s home directory, the user’s home directory can be represented as the tilde (<var>~</var>). For example, <var>/home/analyst/logs</var> can also be represented as <var>~/logs</var>.

You can navigate to specific subdirectories using their absolute or relative file paths. The **absolute file path** is the full file path, which starts from the root. For example, <var>/home/analyst/projects</var> is an absolute file path. The **relative file path** is the file path that starts from a user's current directory.

**Note:** Relative file paths can use a dot (<var>.</var>) to represent the current directory, or two dots (<var>..</var>) to represent the parent of the current directory. An example of a relative file path could be <var>../projects</var>.

## Key commands for navigating the file system

The following Linux commands can be used to navigate the file system: <var>pwd</var>, <var>ls</var>, and <var>cd</var>.

### **pwd**

The <var>pwd</var> command prints the working directory to the screen. Or in other words, it returns the directory that you’re currently in.

The output gives you the absolute path to this directory. For example, if you’re in your <var>home</var> directory and your username is <var>analyst</var>, entering <var>pwd</var> returns <var>/home/analyst</var>.

**Pro Tip**: To learn what your username is, use the <var>whoami</var> command. The <var>whoami</var> command returns the username of the current user. For example, if your username is <var>analyst</var>, entering <var>whoami</var> returns <var>analyst</var>.

### **ls**

The <var>ls</var> command displays the names of the files and directories in the current working directory. For example, in the video, <var>ls</var> returned directories such as <var>logs</var>, and a file called <var>updates.txt</var>.

**Note**: If you want to return the contents of a directory that’s not your current working directory, you can add an argument after <var>ls</var> with the absolute or relative file path to the desired directory. For example, if you’re in the <var>/home/analyst</var> directory but want to list the contents of its <var>projects</var> subdirectory, you can enter <var>ls /home/analyst/projects</var> or just <var>ls projects</var>.

### **cd**

The <var>cd</var> command navigates between directories. When you need to change directories, you should use this command.

To navigate to a subdirectory of the current directory, you can add an argument after <var>cd</var> with the subdirectory name. For example, if you’re in the <var>/home/analyst</var> directory and want to navigate to its <var>projects</var> subdirectory, you can enter <var>cd projects</var>.

You can also navigate to any specific directory by entering the absolute file path. For example, if you’re in <var>/home/analyst/projects</var>, entering <var>cd /home/analyst/logs</var> changes your current directory to <var>/home/analyst/logs</var>.

**Pro Tip**: You can use the relative file path and enter <var>cd ..</var> to go up one level in the file structure. For example, if the current directory is <var>/home/analyst/projects</var>, entering <var>cd ..</var> would change your working directory to <var>/home/analyst</var>.

## Common commands for reading file content

The following Linux commands are useful for reading file content: <var>cat</var>, <var>head</var>, <var>tail</var>, and <var>less</var>.

### **cat**

The <var>cat</var> command displays the content of a file. For example, entering <var>cat updates.txt</var> returns everything in the <var>updates.txt</var> file.

h.l.

The `cat` command in Linux is short for "concatenate", which means to link things together in a series or chain. The `cat` command is one of the most commonly used commands in Unix-like operating systems like Linux. It reads data from files and outputs their contents. It can also concatenate and display the contents of more than one file.

### **head**

The <var>head</var> command displays just the beginning of a file, by default 10 lines. The <var>head</var> command can be useful when you want to know the basic contents of a file but don’t need the full contents. Entering <var>head updates.txt</var> returns only the first 10 lines of the <var>updates.txt</var> file.

**Pro Tip**: If you want to change the number of lines returned by <var>head</var>, you can specify the number of lines by including <var>-n</var>. For example, if you only want to display the first five lines of the <var>updates.txt</var> file, enter <var>head -n 5 updates.txt</var>.

### **tail**

The <var>tail</var> command does the opposite of <var>head</var>. This command can be used to display just the end of a file, by default 10 lines. Entering <var>tail updates.txt</var> returns only the last 10 lines of the <var>updates.txt</var> file.

**Pro Tip**: You can use <var>tail</var> to read the most recent information in a log file.

### **less**

The <var>less</var> command returns the content of a file one page at a time. For example, entering <var>less updates.txt</var> changes the terminal window to display the contents of <var>updates.txt</var> one page at a time. This allows you to easily move forward and backward through the content.

Once you’ve accessed your content with the <var>less</var> command, you can use several keyboard controls to move through the file:

<div class="rc-CML" dir="auto" id="bkmrk-space-bar%3A-move-forw"><div><div data-track="true" data-track-action="click" data-track-app="open_course_home" data-track-component="cml" data-track-page="item_layout" role="presentation"><div data-track="true" data-track-action="click" data-track-app="open_course_home" data-track-component="cml_link" data-track-page="item_layout"><div class="css-1k5v0wb" data-testid="cml-viewer">- <var>Space bar</var>: Move forward one page
- <var>b</var>: Move back one page
- <var>Down arrow</var>: Move forward one line
- <var>Up arrow</var>: Move back one line
- <var>q</var>: Quit and return to the previous terminal window

</div></div></div></div></div>note to future NaruZkurai, this control scheme is ascinine, i will be ripping this command then creating one called  
nzkread

## Key takeaways

It’s important for security analysts to be able to navigate Linux and the file system of the FHS. Some key commands for navigating the file system include <var>pwd</var>, <var>ls</var>, and <var>cd</var>. Reading file content is also an important skill in the security profession. This can be done with commands such as <var>cat</var>, <var>head</var>, <var>tail</var>, and <var>less</var>.