# Unlocking the CLI: File and Directory Essentials for Every User

Anyone dealing with a computer, whether they are an experienced IT expert, a software developer, or just an average user, has to be familiar with file and directory commands. You can effectively navigate, work with, and manage files and directories with these commands in a command-line environment. In this article, we'll look at several crucial file and directory commands that will teach you how to master the command line.  
1\. pwd (Print Working Directory)

**<mark>pwd</mark>** command is used to know your current directory. This command shows the full path to your current location in the file system.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696127473057/c584923c-a381-41de-a0d9-4b2bb59e3a94.png align="center")

**2\. cd (Change Directory)**

Use `cd` followed by a directory path to change your current location. For instance, to move to the "**Downloads**" directory, type cd Downloads

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696127668627/b3d299c5-04b6-4a36-819e-460869d382df.png align="center")

Here we can see we moved from the **Home** directory to the <mark>Downloads</mark> directory. And again using **<mark>cd ..</mark>** we are back to the *Home* directory again.

**3\. ls (List)**

The `ls` command lists the contents of the current directory. Adding options like `-l` a detailed list or `-a` to show hidden files can provide more information. For more options, we can navigate the manual page of the list using the command <mark>man ls</mark>.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696127932903/0343e933-bddc-4d67-b38f-bcc5849f38b9.png align="center")

We can see all the files in detail along with hidden files represented by **.** and **.. .**

**Manipulating Files and Directories**

**touch**

The `touch` the command creates an empty file. For example, `touch demo.txt` will create a file named <mark>"demo.txt."</mark>

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696128328144/edafbd65-48c3-477b-837c-397be3cd8482.png align="center")

**mkdir (Make Directory)**

To create a new directory, use `mkdir`. For instance, `mkdir demofolder` creates a directory named <mark>"demofolder."</mark>

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696128443684/5acb47f2-f7d1-40b9-bca9-6589434721b8.png align="center")

**cp (Copy)**

`cp` allows you to copy files or directories. Use it with the source and destination paths to specify what to copy and where to copy it.

```plaintext
cp source_file destination_path
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696128738469/3609ab6a-dcfc-4ff0-adda-044f158dc12d.png align="center")

Here we copied the <mark>demo.txt </mark> to the <mark>demofolder,</mark> we can see the *demo.txt* file in the *demofolder.*

**mv (Move/Rename)**

The `mv` command can be used to move files or directories to a different location or rename them.

```plaintext
mv source_Files destination_path
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696129106813/4031b8bf-b487-472e-8d70-dcd2902d75d5.png align="center")

Using the ***mv*** command, we moved all the files and directories i.e. <mark>demo.txt, movefile.txt, movefolder </mark> to the **demofolder.**

**rm (Remove)**

To delete files or directories, use `rm`. Be cautious when using it, as deleted items are not typically recoverable. For files, we can use **rm** and for directories, we can use **rmdir** to delete them.

> options used with the **rm** command:
> 
> \-r: Allows the removal of directories and their contents recursively.
> 
> \-f: delete the files forcefully and do not prompt for confirmation.
> 
> \-v: Provides detailed information about the removal process.
> 
> \-d: Removes empty directories.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696129894742/b4e414c3-d612-4df2-9847-77bfac9fd127.png align="center")

First, we deleted the **movefolder** using <mark>rmdir</mark> command and then we deleted the **demo.txt** file using the <mark>rm</mark> command. When we tried to delete the **demofolder** we got the error: "***Directory not empty"*** since **movefile.txt** was still there. So using the <mark>-r </mark> (recursively) option, we deleted the **demofolder** folder. Since we deleted all the contents of the *TEST* directory, the **ls** command gives no output as nothing is there to show.

**Tab Completion**

Save time by using tab completion. Start typing a file or directory name, then press the **Tab** key to auto-complete it. If there are multiple matches, it will display options.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696130368978/fdddb361-d43c-4304-939b-0e532e45f11f.png align="center")

On pressing the Tab key after typing ***Do*** we see the multiple files that are matching **Do.**

Being proficient with file and directory commands can boost your productivity and give you more control over the file system on your computer. In a command-line environment, these commands provide you the freedom to swiftly navigate, manipulate, and manage files and directories. You'll improve your confidence and skill in using these crucial commands with practice. So, start experimenting and opening your terminal to unleash the command line's potential!

Happy Learning!!
