X
Tech

5 Linux file and folder management commands you need to know

Already know the 5 most essential Linux commands? Great! But for maximum productivity, you should learn these 5 too. (You'll thank me later.)
Written by Jack Wallen, Contributing Writer
5penguinsflyinggettyimages-520459992
Jay Dickman/Getty Images

Linux has over 1,000 commands on a basic service. When you migrate to the desktop, that number grows. For example, in /usr/bin on Pop!_OS there are 1,615 commands, and in /usr/sbin, there are 609. That's more than 2,000 commands to choose from.

Also: The first 5 Linux commands every new user should learn

During your lifetime with Linux, you may use 1% of those commands. For file and folder management, that number dwindles. 

I've already listed what I believe are the 5 Linux commands every user should learn, all of which are also related to file and folder management. The list, however, doesn't end there. At some point, you'll need to do a bit more than those basic five. For that, here are the next five Linux commands you should learn.

1. mkdir

The mkdir is exactly what it looks like -- make a directory. When you need to create a new directory (aka "folder"), this is the command you use. At its most basic, the command goes something like this:

mkdir FOLDER

Where FOLDER is the name of the folder you want to create.

That command would create a new folder within the folder you are currently working on. Let's say you're in ~/Documents and you want to create TEST in the root of your home directory. For that, you could run:

mkdir ~/TEST

But what if you need to create ~/TEST/project1 but have yet to create ~/TEST? With the help of the -p option, you can do that like so:

mkdir -p ~/TEST/project1

The above command would first create TEST and then create project1 inside of it.

2. less

The less command is used to view the contents of a file. For example, if you want to view the contents of /etc/samba/smb.conf, you'd issue the command:

less /etc/smb/smb.conf

What I like about less is that it only shows the file in question one page at a time, which means you can scroll through it and view it line by line. The less command has been my go-to for viewing files, especially when I don't need to edit them.

Also: My top 5 user-friendly GUI backup tools for the Linux desktop  

3. cat

The cat command is for concatenating files and printing them to the standard output (the terminal). Essentially, cat will display the contents of a file in the terminal window. Unlike less, you can't scroll through the output of cat (unless your terminal window allows it). Say you want to view the contents of /etc/fstab. You can do that with:

cat /etc/fstab

Or maybe you want to append the content of one file to the end of another. This is where cat shines. For example, you have TEST/project1/file1.txt and TEST/project1/file2.txt and you want to append the content of file1.txt to the end of file2.txt. For that, the command would be:

cat TEST/project1/file1.txt >> TEST/project1/file2.txt

View the contents of file2.txt and you'll see the contents of file1.txt are at the bottom.

Also: Linux was never made for the cloud, but DBOS is - and you can try it for free

4. touch

This is very simple (and basic). If you want to create an empty file, do it with touch like so:

touch filename

Where filename is the name of the file. 

Of course, touch's primary purpose is to change file timestamps but most users employ it to create empty files. Here's a simple example of how it can work:

  1. Create an empty file - touch ~/test
  2. Add content to the new file - echo "New Content" > ~/test
  3. Append more content to the file - echo "More Content" >> ~/test

The important thing above is the difference between > and >>. The > operator overwrites the content in the file, whereas >> appends the new text to the end of the file.

Also: How to share files across your network from these popular Linux GUIs

5. pwd

With the cd command, you can move around the Linux filesystem hierarchy. At some point, however, you might need to know what directory you're in and the terminal doesn't give you any clue. For that, you need to use pwd, which prints the name of the current working directory. For example, if you're in /var/www/html/site1 and you issue the command pwd, you'll see /var/www/html/site1 printed out. Although you might not use pwd verify often, you'll be glad it's there when you need to know where you are.

Also: This budget Android phone is so powerful, it should be double the price

And there you have it -- five commands you should know for working with files and folders on Linux. Combine these five with the previous five and you should be good to go.

Editorial standards