Linux file management from terminal

As we all know, Linux is an operating system primarily used by geeks and developers who mainly work on the keyboard and like to write commands instead of using a graphical user interface (GUI). Unlike the Windows operating system, where most of the work is done with a few clicks of the mouse, while on Linux we have commands for everything, for example, for working with main files, compressing or extracting files, etc. These commands are executed in Linux command line, known as Terminal or Shell, A terminal or shell is a utility in Linux that is responsible for running commands.

Due to the large data in the system are tons of files. Thus, it becomes difficult for the user to find and manage a specific file. Typically, users use a graphical interface to manage the file. These commands provide the flexibility of managing files at a higher speed with much more options, and the user will get a more meaningful result efficiently. In this tutorial, we will see various commands for managing files.

List files with ls command

“Ls” is mainly used to list files. The ls command can be used with different parameters that provide different results. We will use the ls command to search for files.

Step 1: First of all, open the terminal by clicking on Ubuntu Launcher and find the terminal.

Serach for the Terminal app

Step 2: Now click on Terminal and wait for the terminal to open.

Open Linux terminal

Step 3After opening the terminal, you will have the following screen:

Linux Terminal is ready to use

Step 4: We can use the ls command differently in part 1, we used it without any option to see the result. While the following two commands contain specific options to show the file / directory size and the other to view hidden files.

List of files using ls:

We use the ls command without any options, so here we will not be able to view detailed information about the file type, its size and directory. We just walk in “LS”

List files with ls command

As a result, we get a list of files without any specific details.

List ls

List of files with the –l option:

Here we used the –l option to see the details of the file. It includes the file directory, its size, date modified, time, details about credentials, etc. We just write the option as “Ls –l”.

Linux command ls -l

As a result, we get a list of files with specific information about the file.

List of files as shown when using ls -l

View hidden files:

We can also find out a list of all hidden files. Hidden files start with “”We just write “ls –a”To find hidden files.

option -a of ls command

The result shows a list of all hidden files.

Show hidden files in Linux

We can use any of the listing methods depending on the user’s requirements.

Changing a directory using the cd command

To do this, use the “cd” command, which allows the user to change the current folder or directory. We can change the current directory by specifying the new directory in the cd command as “compact disc [directory-name]For example, here is the new “Desktop” directory, so we write it as:

Linux cd command

Now the directory we are in Desktop

Cd command result

Further, if we want to move and change the directory to any other, for example, home, we will write the path “CD / house” a new directory next to the current directory.

Using CD s / path

Now our current directory, which was previously Desktop, has been changed to “house” catalog.

Linux file management from terminal

The file directory can be modified with these commands.

Using the rm command:

To delete / delete a file, we must be in the same directory as our file that we want to delete. The file we are about to delete is located in “home”, and the following is a method for changing the directory. We want to move and change the directory to any other, for example, home, we will write the path “CD / house” a new directory next to the current directory. Because our file is “abc.txt » which we want to delete is in the home directory.

Enter the directory using the cd command

Now our current directory, which was previously Desktop, has been changed to “house” catalog.

We are currently in the / home directory

So, to delete the file, we use the command “rm abc.txt”, Where abc.txt is the file of our interest. It can be any file based on our requirement.

Delete file with rm command

The file “abc.txt” is now deleted from home.

File List in Desktop File Viewer

Thus, with this command we can delete the file that we want to delete / delete.

using the rmdir command

We use the rmdir command when we want to delete an empty directory. We use the team “Rmdir directory name“. Here we have an empty directory named “EmptyDirectory” at home. We will remove this in this part of the lesson.

Here “emptyDirectory » placed at home.

Create directory

The command used to delete an empty directory The name of the rmdir directory. Here is the name of the directory emptyDirectory.

Delete directory

The empty directory has been deleted.

The empty directory has been deleted.

Move files using mv

To move a file from one place to another, we use MB command. Here we want to move the sample.txt file, which is currently on the desktop.

List of files for our example

We will use the “mv” command to move the sample.txt file from the desktop to the “Downloads” section. To do this, write a command “Mv sample.txt / new directory.”

Move file using mv command in linux shell

Here we wanted to move our file for download, so the directory for download “/ Home / sleeve / boot.”

File moved successfully

With the mv command, we moved our file to load.

Copy files using cp

We use the cp command to copy the file to another directory. We will use the cp command to copy the file from source to destination. File.txt this is the file that we copy to the desktop from the current directory, which is home in our case. Command “Cp file.txt / Destination.”

Copy the file using the CP command

If the destination to which we are copying the file already contains the same file, it asks us to overwrite the file or not to use “–I option”, The user is prompted to overwrite the file or not.

Confirm team action

In case we do not want the file to be overwritten, we use option “-n”.

cp command -n

The above commands are just a few examples related to the cp command.

We will create a new directory named “ABC“In the current working directory using”MkDir » command. To do this, we write the command “mkdir newDirectory”, I.e. in our case, abc, and we write it to the current working directory to create a new directory in the same place.

Linux mkdir team

Then we will go to the desktop to see the newly created abc directory.

Directory successfully created

Here’s how we can create a new directory using the mkdir command on the terminal command line.

Change file permissions with the chmod command

To set the permission for the file and folder, we can use the chmod command. Chmod uses the following symbolic representation for three different roles:

  • you for the user
  • g for the group
  • about for others.

Below are a few symbolic representations of three different resolutions:

  • g for read permission
  • w for write permission
  • x for permission to execute.

The following example uses the chmod command to change the resolution. Where the plus sign “+” means that we are adding permission. The following example gives the user the right to execute without even specifying anything else. Thus, the user is allowed to perform all kinds of actions. We use chmod u + x file name.

chmod u + x

We can also allow multiple permissions for a file / directory. A comma is used to separate multiple permissions. Here g is for the group, x is again for execution, while u is for the specific user and r is for reading. So, several permissions are allowed in one command. This may be a group of users, and a specific user may be allowed to read the file at any time.

Extended chmod example

We can also remove read and write permissions using chmod “chmod u-rx file name » The command is as follows.

Another example of chmod

This will remove read and write permissions in the specific file.

A touch command can be used to change and change timestamps for accessing / changing certain files. It is used to quickly create an empty file. It uses a simple touch command as follows.

Linux touch command

We just created a file. abc.txt using this command.

Touch result team

File when you open, you can see this is an empty file abc.txt

Empty file created by touch command

Multiple files can also be created using a touch command. We created 3 files at the same time using this command. The names of the files we created “Abc.txt”, “cde.txt”, “xyz.txt”.

Create multiple files using touch command

Three empty files were created. If the file already exists, its access time is updated.

Files created successfully using touch


In this tutorial, we discussed several commands for managing files in a Linux terminal. First, we discussed commands for listing files, then commands for changing directories, and thirdly, we saw commands for deleting files / directories. Then we watched how to copy and move files from one place to another. The next part contains commands for creating new directories. Later we discussed how to change file permissions and how to create empty files on the Linux command line.

Linux file management from terminal