---
title: "Linux Directory Commands : A Complete Guide"
description: "A step-by-step guide to leveraging Linux file and Linux directory commands to administer your Linux system quickly and efficiently!"
canonical: "https://adamtheautomator.com/linux-directory-commands/"
---

# Linux Directory Commands : A Complete Guide

> A step-by-step guide to leveraging Linux file and Linux directory commands to administer your Linux system quickly and efficiently!

Source: https://adamtheautomator.com/linux-directory-commands/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Linux Directory Commands : A Complete Guide](https://adamtheautomator.com/wp-content/uploads/2021/03/Your-Guide-to-Managing-Directories-and-Files-in-Linux-Step-by-Step.jpg)

# Linux Directory Commands : A Complete Guide

[![](https://secure.gravatar.com/avatar/4147968aa2332aa682bcebf295e4e9d0eb2672dee3d9ae0523a00ac51e7d6017?s=192&d=mm&r=g)Bill Kindle](https://adamtheautomator.com/author/bill/)29 March 20219 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Linux](/tag/linux/)

Table of Contents

*   [Prerequisites](#h-prerequisites)
*   [Listing and Finding Directories](#h-listing-and-finding-directories)
*   [Finding the Current Directory With pwd](#h-finding-the-current-directory-with-pwd)
*   [Listing Files and Folders With the ls Command](#h-listing-files-and-folders-with-the-ls-command)
*   [Locating Files and Folders with find](#h-locating-files-and-folders-with-find)
*   [Searching for Files Faster with locate](#h-searching-for-files-faster-with-locate)
*   [Changing Directories with the cd Command](#h-changing-directories-with-the-cd-command)
*   [Making a New Directory With mkdir](#h-making-a-new-directory-with-mkdir)
*   [Creating a New File With touch](#h-creating-a-new-file-with-touch)
*   [Removing Directories and Files in Linux](#h-removing-directories-and-files-in-linux)
*   [Copying Directories and Files in Linux](#h-copying-directories-and-files-in-linux)
*   [Move Directories and Files](#h-move-directories-and-files)
*   [Renaming Directories and Files](#h-renaming-directories-and-files)
*   [Next Steps](#h-next-steps)

Linux skills are always in demand. Build your skill-set by learning how to use Linux directory commands and Linux file commands. This guide is written as a journey. A set of step-by-step instructions guiding you through navigating, creating, removing, moving, renaming directories and files. All from the Linux command line.

If you are ready to build practical, real-world Linux skills, you’ve come to the right place!

## Prerequisites

To practice the Linux examples in this guide, you must have a computer running Linux. The distribution of Linux does not matter. All demos in this guide will be using [RedHat Enterprise Linux 8](https://developers.redhat.com/rhel8) (RHEL).

> [Ubuntu 20.04 LTS](https://releases.ubuntu.com/20.04/) is a great alternative if you don’t want to use RedHat.

Related:[The Ultimate Guide to Windows Subsystem for Linux (Windows WSL)](https://adamtheautomator.com/windows-subsystem-for-linux/)

## Listing and Finding Directories

If you are following along, open a terminal session on your Linux computer.

### Finding the Current Directory With `pwd`

When you’re navigating a file system in a terminal, your prompt is always in a certain directory called a current directory or working directory. Depending on the terminal configuration, you may or may not see the working directory in the prompt.

The `pwd` or [print working directory](https://man7.org/linux/man-pages/man1/pwd.1.html) command displays the current directory you are in. Enter the command as shown below:

```bash
pwd
```

> _By default, the /home/<username> directory is your starting point in a terminal session unless you are signed in with the root account._

When you run the command, the working directory is returned as shown below:

![Display the current working directory path.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T173851.750.png)

Display the current working directory path.

Unlike Windows, Linux does not use drive letters (_C:\\_, _D:\\_, etc.) for disks or partitions (a logical region on a disk). In Linux, directories are preceded by a _/_.

### Listing Files and Folders With the `ls` Command

Inside of directories, you’ll find files and subfolders. The `pwd` command just displays the working directory so how do you see subdirectories and files? The `ls` command.

The `ls` or [list directory](https://man7.org/linux/man-pages/man1/ls.1.html) command is the equivalent to the [`dir` command](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/dir) in Windows. This command lists files and directories in the current directory or any alternative path specified.

> _The [`dir`](https://man7.org/linux/man-pages/man1/dir.1.html) command exists in Linux as well. Equivalent to running `ls -C -b`. Typically, `ls` is used over `dir` as more display flexibility exists._

To find files and directories in the _/home/user_ directory, run the `ls` command. The resulting output is the various files and directories (folders) contained within.

```bash
ls
```

![List contents of the current directory.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T174157.099.png)

List contents of the current directory.

The `ls` command also displays additional information about files and folders such as permissions, file size (in bytes), and file dates with the `l` option. Like in Windows, some files and folders may be hidden by the OS from normal view. View files that are not shown by default with the `a` option.

> _Dotfiles are plain text configuration files in Unix systems. Any file can be hidden when the filename is preceded with a dot `.`._

```bash
ls -la
```

You can see in the below screenshot by using the `la` options, you receive a lot more information displayed in six different columns from left to right:

*   [Permissions](https://adamtheautomator.com/linux-file-permissions/), in the [POSIX ACL format](https://man7.org/linux/man-pages/man5/acl.5.html), with the preceding `d` signifying a directory
*   Subdirectory count with directories containing only files as `1`
*   User and group that a file or folder belongs to
*   Directory or file size in bytes
*   Last modified time
*   Name of the file or folder

![Display a long list of all folders and files in current directory.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T174317.122.png)

Display a long list of all folders and files in current directory.

Related:[A Windows Guy in a Linux World: Users and File Permission](https://adamtheautomator.com/linux-file-permissions/)

You can find all of the files and folders in sub-directories with the `-R` option to display directory contents recursively.

```bash
ls -R
```

![Recursively displaying contents of a directory.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T174419.839.png)

Recursively displaying contents of a directory.

If you want to display the contents of a different directory, pass the target directory to `ls`. Shown below are the _/var/log_ directory contents without leaving the _/home/user_ directory.

```bash
ls /var/log
```

![List the contents of a specific directory.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T174538.142.png)

List the contents of a specific directory.

### Locating Files and Folders with `find`

Locating files across a large file system is difficult. Thankfully, the [`find` command](https://man7.org/linux/man-pages/man1/find.1.html) offers several ways to locate the files and folders you may need.

For example, you want to find the _/var_ directory. Given a starting point, `/`, and setting the type as `d` for directory, search the filesystem for the `var` name.

```bash
sudo find / -type d -name "var"
```

![Using the find command to look for all directories that contain the word "var".](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T174628.099.png)

Using the find command to look for all directories that contain the word “var”.

> Y_ou may see a Permission Denied error even when you run the command using [`sudo`](ttps://man7.org/linux/man-pages/man8/sudo.8.html). The `find` command attempts to search a virtual file system related to Gnome (If you use KDE, this error won’t apply) that your user doesn’t have access to. Instead, don’t [descend directories on other filesystems](https://unix.stackexchange.com/questions/77453/why-cannot-find-read-run-user-1000-gvfs-even-though-it-is-running-as-root#77592) by using the`-xdev` switch instead._

How about finding all files with the log extension? Similar to before, search the root filesystem, but this time specifying `f` for files and search for the wildcard pattern of `*.log`.

```bash
sudo find / -type f -name "*.log"
```

![Searching for all files ending in the .log extension.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T174840.228.png)

Searching for all files ending in the `.log` extension.

> _The `find` command has other options, such as `H`, `L`, and `P`, which handle how [symbolic links](https://man7.org/linux/man-pages/man1/ln.1.html) are treated._

### Searching for Files Faster with `locate`

Like `find`, the [`locate` command](https://man7.org/linux/man-pages/man1/locate.1.html) searches for files and folders but does so faster by searching a database instead of the entire filesystem.

Maybe you have a file named _MyTextFile.txt_ somewhere on your computer. You’ve forgotten where it’s located and need some help finding the path. Use the `locate` command to find the file, providing it the name of the file as shown below.

```bash
locate MyTextFile.txt
```

![Locating MyTextFile.txt on the filesystem.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T174959.352.png)

Locating _MyTextFile.txt_ on the filesystem.

> The _`locate` command finds files but will not find new files until `sudo [updatedb](https://man7.org/linux/man-pages/man1/updatedb.1.html)` runs. A cron job runs [`updatedb`](https://man7.org/linux/man-pages/man1/updatedb.1.html) once a day, but you can run this command manually at any time._

How would you find all directories named `tmp`? You could pass `*/tmp`, which tells `locate` to search the database for entries that end in `tmp`.

```bash
locate */tmp
```

![Search for all folders that end in tmp.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T175151.036.png)

Search for all folders that end in _tmp_.

### Changing Directories with the `cd` Command

Up until now, you have operated within a single directory for the most part. Operating in Linux often means changing directories, done through the [`cd` or change directory](https://man7.org/linux/man-pages/man1/cd.1p.html) command. Using the example below moves from the current home directory, _/home/user,_ to _/var/log_ while verifying your current directory.

```bash
# Show that you are in the current home directory
pwd
# Change to the /var/log directory
cd /var/log
# Verify that you are now in the /var/log directory
pwd
```

![Change directories in Linux.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T175250.034.png)

Change directories in Linux.

Now that you have learned to change to a specific directory, how do you move up a directory? To move up a directory, you will use two dots (`..`), passed to the `cd` command. Once run, as seen below, you move up a single directory, putting you back in the `/var/` directory.

```bash
# Show that you are currently in the /var/log directory
pwd
# Move up a single directory
cd ..
# Verify that you have moved up to the /var directory
pwd
```

![Moving up a single directory.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T175336.092.png)

Moving up a single directory.

When you want to change into the _/var/log_ directory again, pass the directory name to change to with a trailing `/`.

```bash
# Show that you are currently in the /var directory
pwd
# Change to the /var/log directory
cd log/
# Verify that you are back in the /var/log directory
pwd
```

As seen below, only entering the destination sub-directory with a trailing `/` removes the need to enter an absolute path every time.

![Move to a sub-directory.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T175416.135.png)

Move to a sub-directory.

> _If you are unsure of a file or directory name when using `cd`, press the `TAB` key twice to produce a list of possibilities. Example: `cd <TAB> <TAB>`_

### Making a New Directory With `mkdir`

Creating a directory in Linux is through the [`mkdir` or make directory](https://man7.org/linux/man-pages/man1/mkdir.1.html) command. To create a new directory called _MyAwesomeLinuxDir_ in your home directory (noted by the special path `~`), use the command below.

```bash
mkdir ~/MyAwesomeLinuxDir
```

If Linux creates the directory successfully, Linux will not return a message in the console. You can list the directories in your home directory with the `ls` command to verify that the directory, _MyAwesomeLinuxDir_, exists.

![Creating a directory in Linux.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T175558.518.png)

Creating a directory in Linux.

Now add some complexity and create multiple new directories with a single command. To create multiple directories, you use the `mkdir` command and pass multiple directory names separated by a space.

```bash
mkdir ~/Directory01 ~/Directory02 ~/Directory03
```

Once again, list the directories with the `ls` command. As you can see below, three more directories exist now.

![Creating multiple directories with mkdir.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T175658.223.png)

Creating multiple directories with `mkdir`.

As useful as using `mkdir` to create a single folder is, what if you need to create many folders all at once? Instead of typing each directory out, use [brace expansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html)! This technique is powerful when creating multiple directories with a similar pattern.

Brace expansion makes creating multiple directories based on a pattern quicker than if typing each by hand. To demonstrate brace expansion, append `{03..07}` after the name `Directory` to generate five directories. You may notice that _Directory03_ already exists because you created it in a previous example. Avoid an error about existing directories with the `p` option.

```bash
mkdir -p ~/Directory{03..07}
```

As seen below, _Directory03_ is not created, but four new directories ending in `04` thru `07` now exist.

![Creating multiple directories with brace expansion](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T175735.602.png)

Creating multiple directories with brace expansion

### Creating a New File With `touch`

Now that you have learned to create folders, how do you create a file? Using the Linux [`touch` command](https://man7.org/linux/man-pages/man1/touch.1.html) create an empty file, as seen in the next example.

```bash
touch ATABlog
```

Once again, list the files and folders in your home directory, to see that the new _ATABlog_ file exists.

![Creating a file with the touch command.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T175840.461.png)

Creating a file with the `touch` command.

Remember how you learned that the `mkdir` command can use brace expansion to create multiple directories? The same technique is useful with the `touch` command as well! Create five more _ATABlog_ files ending 01 through 05.

```bash
touch ATABlog{01..05}
```

After listing the files and folders with `ls`, five new files exist in your home directory.

![Creating multiple files with brace expansion and the touch command.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T175931.879.png)

Creating multiple files with brace expansion and the `touch` command.

## Removing Directories and Files in Linux

In the last section, you learned how to create directories and files in Linux. To remove directories and files, use the [`rm` command](https://man7.org/linux/man-pages/man1/rm.1.html) to remove directories and their contents.

For example, you want to remove a file called _ATABlog01._ Remove a file by passing the file name to the `rm` command. As seen below, you are removing the _ATABlog01_ file from the current directory.

```bash
rm ATABlog01
```

![Removing a file in Linux.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T180101.433.png)

Removing a file in Linux.

You can remove multiple files at once by adding a space between each filename in the current directory. Delete the remaining _ATABlog##_ files in a single `rm` command, as shown below.

```bash
rm ATABlog02 ATABlog03 ATABlog04 ATABlog05
```

Now that you have learned to remove files, it’s time to remove a directory. By default, the `rm` command does not remove directories. Remove a directory by specifying the `r` or _recursive_ option, as seen in the below example.

```bash
rm -r Directory01
```

In the screenshot below, you can see that **_Directory01_** was removed.

![Removing directory via the recursive command of rm.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T180151.412.png)

Removing directory via the recursive command of `rm`.

You can use brace expansion with the `rm` command too. Providing the 2 to 7 range within the `rm` command informs the remove command to delete all directories named _Directory02_ through _Directory07_. As shown when confirmed by an `ls` command.

```bash
rm -r Directory{02..07}
```

![Removing multiple directories using rm and sequencing](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T180232.546.png)

Removing multiple directories using `rm` and sequencing

> _To prevent accidentally removing the wrong files or folders use the `i` to prompt for each file. Make the option less onerous with the `I` option which only prompts on three or more files._

## Copying Directories and Files in Linux

Copy files in Linux with the [`cp` command](https://man7.org/linux/man-pages/man1/cp.1.html). Not only can the `cp` command copy directories and files in Linux, but also file attributes and [creating symbolic links](https://www.freecodecamp.org/news/symlink-tutorial-in-linux-how-to-create-and-remove-a-symbolic-link/).

To demonstrate copying a file from the previous examples, copy the `ATABlog` file to the _Documents/_ directory with the `cp` command. Add the `v` option to display more information about the exact copy operation.

```bash
cp -v ATABlog Documents/
```

![Copy a file in Linux with the cp command.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T180358.417.png)

Copy a file in Linux with the `cp` command.

Now, copy the folder, _MyAwesomeLinuxDir_, to the _Documents_ directory. Here, as with the `rm` command, be sure to add the `r` or recursive option to copy the directory, as seen in the below example.

```bash
cp -r MyAwesomeLinuxDir/ Documents/
```

![Copy the folder using the recursive option.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T180505.806.png)

Copy the folder using the recursive option.

### Move Directories and Files

In the previous section, you copied files and folders using the `cp` command. To _move_ directories and files in Linux, use the [`mv` command](https://man7.org/linux/man-pages/man1/mv.1p.html). To move directories in Linux, use the `mv` command. The `mv` command is similar to that of the `cp` command you learned about in previous examples.

```bash
mv [options] [source] [destination]
```

The `mv` command is like cutting and pasting in Windows, with a bonus of being able to rename files simultaneously. The next sections will show you how to use `mv` for both scenarios.

> U_se the `-i` option to prompt before each move or the `-f` option to forcefully move items without prompting._

To demonstrate, move the file _Documents/ATABlog_ to the _Desktop_ directory with the [`mv` command](https://man7.org/linux/man-pages/man1/mv.1p.html). Move the folder, _Documents/MyAwesomeLinuxDir_ to the _Desktop_ as well, as shown below.

```bash
mv Documents/ATABlog Desktop/
mv Documents/MyAwesomeLinuxDir Desktop/
```

Your commands should look like the example below. Remember, you are moving the file and directory (source) to another directory (destination).

![Using the mv command to move files and folders](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T180639.146.png)

Using the mv command to move files and folders

Use the `ls` command to see that both are now located in the **Desktop** directory.

![Moving a file and folder in Linux.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T180707.874.png)

Moving a file and folder in Linux.

### Renaming Directories and Files

Although there is not a rename command, the `mv` command plays the same role. Instead of only passing a destination to the `mv` command, specify the resulting file or folder without a trailing slash to move and rename.

Move the file and folder back to your home directory while renaming the file to _ATABlog\_Renamed_. Similarly, do the same with the _MyAwesomeLinuxDir_, and rename the directory to _MyAwesomeLinuxDir\_Renamed_ in the home directory, as shown below.

```bash
mv Desktop/ATABlog ~/ATABlog_Renamed

mv Desktop/MyAwesomeLinuxDir ~/MyAwesomeLinuxDir_Renamed
```

![Moving files and folders with mv command](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-24T180745.666.png)

Moving files and folders with mv command

## Next Steps

In this article, you have learned many of the common Linux directory commands, such as how to traverse a Linux filesystem along with creating, moving, and deleting files.

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Flinux-directory-commands%2F&text=Linux%20Directory%20Commands%20%3A%20A%20Complete%20Guide)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Flinux-directory-commands%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Flinux-directory-commands%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/09/Practical-Linux-Unix-Tee-Commands-for-the-Linux-Admin.jpg)

### [Master Unix tee Commands for Real-World Linux Admin Tasks](/unix-tee/)

Simplify Linux output management and streamline your workflow with the “Unix tee” command. This tutorial guides you through its practical applications.

![](https://adamtheautomator.com/wp-content/uploads/2024/03/openldap-4.jpg)

### [How to Install and Configure an OpenLDAP Ubuntu Server](/openldap/)

Unlock the power of OpenLDAP on Ubuntu for centralized user authentication, seamless access control management, and enhanced directory services!

![](https://adamtheautomator.com/wp-content/uploads/2024/03/pipe-command-in-linux-1.jpg)

### [Unleashing the Power of the Pipe Command in Linux](/pipe-command-in-linux/)

Unlock the prowess of the pipe command in Linux to streamline tasks, boost productivity, and simplify complex operations effortlessly!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
