Files and Folder management commands in Linux Part 1 (File and folder creation)


This article is all about how to create and manage files and folders in Linux operating system by different methods. In the previous article, we learn that how to set a password on a user account in Linux and also learn that the security of your user by different methods. We also learn about how to remove a password and how to delete a password from your user account according to your need. Now in this tutorial, we learn about how to create and manage a file and folder n your Linux operating system. Here we also learn about how to delete and check the properties of your file. So, let’s start here Management of Files and folders in Linux operating system.

Now, first of all, we will learn about some information related to files and folder how many types of files will be exists in Linux operating system and how we differentiate and identify files and folders. We know that there are two types of files will be created in the Linux operating system one is empty file and another is the content-based file in which we can store any type of data like a text file, video file, mp3 file, JPG file etc. Now, in other words, we can say that a file is an object on a computer that stores data, information, settings or commands used with a computer program. In the graphical user interface, we can identify a file with its icon easily but now we learn Linux which gives you a command line interface so here we can identify a file by its extension. A file has a specific size which does not increase automatically without doing any changes in it by us.Now here we discuss what is a folder.

folder in graphical mode

Now here we discuss what is a folder.  A folder is a virtual location where programs, files, and other folders can be located. Folders do not have a specific size it is increased automatically by storing more data in it. Operating systems have folders to help users to stored different type of data and files in it by category and give your folder a name to identify which type of data a folder will be contained in it. A folder can contain any type of file and can even store other folders with their own file. In Linux operating system a folder will also be known as a directory.

Now we start here folder and file management in Linux operating system

How to identify a folder and file in Linux operating system by command line interface

First of all, we run ls -l command on your Linux operating system to check all the files and folders on your system at that place like I will check my root folder here I will saw these given below output on my screen after executing ls -l command on my system

-rw------- 1 root root   987 Jan 15 02:23 anaconda-ks.cfg
drwxr-xr-x 3 root root  4096 Jan 20 23:13 Desktop
-rw-r--r-- 1 root root 29623 Jan 15 02:22 install.log
-rw-r--r-- 1 root root  3671 Jan 15 02:21 install.log.syslog

Here we can saw that one line started with d and all other lines started with – this symbol. So now we differentiate file and folder here. If a line will be started with d then it is a folder like in above result the second line shows that Desktop is a folder and all other remaining lines show files because it is started with – not started with d. So by this method, we can differentiate a folder and file easily on your Linux containing system.

1. How to create a folder in Linux using command line interface

we can also create a folder using graphical user interface it’s quite easy so now use given below command to make folder/directory on your Linux operating system.

[root@localhost ~]# mkdir rahul

Now to check this directory/folder will be created on your system or not use given below command

-rw------- 1 root root   987 Jan 15 02:23 anaconda-ks.cfg
drwxr-xr-x 3 root root  4096 Jan 20 23:13 Desktop
-rw-r--r-- 1 root root 29623 Jan 15 02:22 install.log
-rw-r--r-- 1 root root  3671 Jan 15 02:21 install.log.syslog
drwxr-xr-x 2 root root  4096 Jan 21 04:17 rahul

Here you saw that your folder will be created successfully in the root folder and you can also check this folder by ls -l command. As the figure is shown below

folder creation in Linux

Now here we learn about how to create files in Linux with different methods. Here in Linux mainly four methods will be used for file creation and management which is touch, cat, vim editor and nano editor. Here touch command is used for creating an empty file on your system. cat command is used for creating a file with content and by cat command, you can also saw the output of your file on your screen which is given below. vim editor is also used for creating a file with any type of content in it and it can also use for saw the output of file and you can also use it to edit any type of text file in Linux. Now last file creation method is nano editor it is same as vim editor by nano editor you can create, check and edit a file in a simple way. So now here we can learn how to create a file in Linux by using these above all four methods let’s start here.

2. How to create an empty file by using touch command 

[root@localhost ~]# touch rahul.txt

Now to check this file is created on your system or not use given below command

[root@localhost ~]# ls -l
total 64
-rw------- 1 root root   987 Jan 15 02:23 anaconda-ks.cfg
drwxr-xr-x 3 root root  4096 Jan 20 23:13 Desktop
-rw-r--r-- 1 root root 29623 Jan 15 02:22 install.log
-rw-r--r-- 1 root root  3671 Jan 15 02:21 install.log.syslog
-rw-r--r-- 1 root root     0 Jan 21 04:46 rahul.txt

here you can saw that your file will be created on your system. Now if you want to create many numbers of empty files on your system which follow an algorithm like here I want to create all text files from a to z in .txt format without doing any extra efforts then use given below command to create all files from a to z

[root@localhost ~]# touch {a..z}.txt

now to check all files will be created or not then run ls -l command on your operating system. As the figure is shown below

create an empty file in Linux

3. How to create a file with content in it by using touch command 

Now we create a file with having content in it using cat command by using given below command

[root@localhost ~]# cat >hemendra.txt
hi
how are you
i am fine what about you
[root@localhost ~]#

In this process, first of all, run cat command on your system then write any content in it after that you will write all of the content in it press Ctrl+D to save this file.

Now to check file will be created or not use given below command

 [root@localhost ~]# ls -l
 total 72
 -rw------- 1 root root 987 Jan 15 02:23 anaconda-ks.cfg
 drwxr-xr-x 3 root root 4096 Jan 20 23:13 Desktop
 -rw-r--r-- 1 root root 39 Jan 21 05:02 hemendra.txt
 -rw-r--r-- 1 root root 29623 Jan 15 02:22 install.log
 -rw-r--r-- 1 root root 3671 Jan 15 02:21 install.log.syslog
 -rw-r--r-- 1 root root 0 Jan 21 04:46 rahul.txt

here you saw that your file will be created with content that is hemendra.txt

Now to check what is written in this file use given bellow command

[root@localhost ~]# cat hemendra.txt
hi
how are you
i am fine what about you

create a file with content in it in Linux

4. How to create a file with content in it by using vim editor

Now to create a file use given below command

[root@localhost ~]# vim deepika.txt

Now after executing this command on your system your vim editor will be opened. Now to write something in it first of all press I key from your keyboard to go into insert mode then type your content in it. After that to save this file on your system first of all press ESC key from your keyboard then type any of the code from the following given below codes on your screen and press enter to say your content in that file.

:wq

:wq!

For example, I am creating a file named as deepika.txt in it I write hello everyone myself rahul meena Administrator of technohelper24.com and save this file. As the figure is shown below

file creation using vim editor

Now to check content of this file use given below command and output will also be given below to the command

[root@localhost ~]# cat deepika.txt
hello everyone myself rahul meena
Administrator of technohelper24.com

Now if you want to change something in this file then type vim instead of cat then press enter to go into this file and easily edit this file by using vim editor

5. How to create a file with content in it using nano editor

Now first of all to create a file with nano editor use given below command

[root@localhost ~]# nano manu.txt

After executing this command on your system nano editor will be opened on your screen now in it simply type your content. After typing, all of the content in that file now press Ctrl+X key for save that file on your screen. Now after that, it will ask you to save your file in it simply type y key for save and then press enter to save that file on your system. As the figure is shown below

create a file with content in it using nano editor

Now to check your file will be created or not use given below command

[root@localhost ~]# ls -l
total 92
-rw------- 1 root root   987 Jan 15 02:23 anaconda-ks.cfg
-rw-r--r-- 1 root root    70 Jan 21 05:14 deepika.txt
drwxr-xr-x 3 root root  4096 Jan 20 23:13 Desktop
-rw-r--r-- 1 root root    39 Jan 21 05:02 hemendra.txt
-rw-r--r-- 1 root root 29623 Jan 15 02:22 install.log
-rw-r--r-- 1 root root  3671 Jan 15 02:21 install.log.syslog
-rw-r--r-- 1 root root     4 Jan 21 05:33 manu.txt
-rw-r--r-- 1 root root     3 Jan 21 05:32 rahul.txt

Now to check your content in file use given below command

[root@localhost ~]# cat manu.txt
technohelper24.com
rahul meena
[root@localhost ~]#

Now if you want to edit this file again from nano editor then again type nano manu.txt and then repeat above given process to create and save a file on your Linux operating system.

                                      THAT’S IT

These are the common and easy methods for creating a file and folder on your Linux operating system according to me vim editor is the best editor to create a file and edit a file also. Because of it has user-friendly interface and it is easy in use. So always use vim editor for edit and create files and use cat for saw all the content of any text file.

If you have any queries regarding this solved out through comment section in next part we will learn about file security, how to join two files and many more things.

If you want to see all this process in a video format click on given below link

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s