Site icon TestingDocs.com

Common File Commands in Linux

Introduction

In this post, we will learn some commonly File commands on Linux operating system.  We can use these commands in the bash terminal or in bash scripts.

Create Directory

mkdir command is used to create a directory in Linux. To create a directory called ubuntu, type the following command in the terminal window:

$ mkdir ubuntu

The new directory would be created under the present working directory. To navigate we can use the cd command.

 

Remove Directory

rmdir command is used for removing the directory.

:~$ rmdir ubuntu

Common errors while using this command is: providing a non-existent directory name or trying to remove a directory that is not empty.

Create File

There are so many ways to create a file in Linux. Using touch command, cat command, etc.

touch command creates a new file if it doesn’t exist in the directory. If the file already exists then it will change the modification timestamp of the file. To learn more about touch command use

$ man touch

To create a new file with touch, use the following command:

$ touch sample.txt

Copy File

cp command is used in Linux to copy the file. This command copies the file to the new location.

Format of the command is

cp  file <new location>

$ cp toBecopied.txt ubuntu/

Move File

mv command can be used to move the file to a new location.

Remove File

We can use the rm command to remove a file.

$ rm -rf sample.txt

To know the flags and to learn more about the command, use the below command:

$ man rm

Linux Commands

Linux Basic Commands Tutorial page:

https://www.testingdocs.com/linux-basic-commands-tutorial/

More Information on Ubuntu Linux:
https://ubuntu.com/

Exit mobile version