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

Files and Folders management commands in Linux Part 1. Here in this article, we learn about how to create and manage files and folders in Linux operating systems by different methods. In the previous articles, we also learn things such as how to set a password on a user account in Linux and also learn that the security of your user account by different methods. Now in this tutorial, we learn about how to create and manage a file and folder in your Linux operating system. So you can create files and folders on your system simply and easily.

Now, first of all, we will learn about some information related to files and folders such as how many types of files can be created in the Linux operating system and how can we differentiate and identify them with ease. We know that there are two types of files present that can be created in the Linux operating system one is an 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 in the Linux, we generally use a command-line interface so here we can identify a file only by its extension. A file has a specific size that does not increase automatically without doing any changes in it by the user. Now here we discuss what is a folder.

folder logo

A folder is a virtual location where programs, files, and other subfolders can be stored. 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 store 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.

How to add extensions in the Microsoft Edge browser? Read Here

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

First of all, execute ls -l command on your Linux operating system to check all the files and folders on your system at your present working directory. Like here my present working directory is root. and the output which is shown below is the result of executing ls -l command on my system.

[[email protected] ~]# 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

Here we can see that one line started with the letter d and all other lines are started withthis symbol. So according to both of these, we can differentiate files and folders in Linux operating system. Such as if a line will be started with d then it is a folder like in the above result the second line shows that Desktop is a folder and all other remaining lines show files because it is started with not with d. So by this method, we can differentiate folders and files easily on your Linux operating system.

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

we can also create a folder using the graphical user interface it’s quite easy. But if you want to create a folder using command line interface use given below command to make folder/directory on your Linux operating system.

[[email protected] ~]# mkdir rahul

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

[[email protected] ~]# 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
drwxr-xr-x 2 root root  4096 Jan 21 04:17 rahul

Here in the output, you can see 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

create a folder

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 that are touch, cat, vim editor, and nano editor. In Linux, the touch command is used for creating an empty file on your system. The cat command is used for creating a file with content and you can also saw the output of your file on your screen by the cat command. The vim editor is also used for creating a file with any type of content in it and it can also be used for saw the output of the file and you can also use it to edit any type of text file in Linux. Now the last file creation method is nano editor it works the same as the vim editor. By nano editor tool 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.

How to Format a Write Protected Pen drive? (Unformattable USB drive) Read Here

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

[[email protected] ~]# touch rahul.txt

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

[[email protected] ~]# 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 see 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

[[email protected] ~]# touch {a..z}.txt

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

create an empty file using touch command in linux

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

Create a file with having content in it using the cat command.

[[email protected] ~]# cat >peanut.txt
hi
how are you
i am fine what about you
[[email protected] ~]#

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

Now to check that the file is created or not use given below command

[[email protected] ~]# 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 peanut.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 can see that your file will be created having content in it named peanut.txt

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

[[email protected] ~]# cat peanut.txt
hi
how are you
i am fine what about you

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

Create a file using vim editor

[[email protected] ~]# 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 so you can 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 one code from both of the given below codes on your screen and then press enter to save your content in the file.

:wq

:wq!

For example, I am creating a file named 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

how to use vim editor

Now check the content of this file using cat command that is given below and output will also be given below to the command

[[email protected] ~]# 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 you can easily edit this file by using vim editor.

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

Now to create a file using nano editor follow given below steps.

[[email protected] ~]# 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 the file press Ctrl+X key to save that file on your screen. Now after that, it will ask you to save your file in it simply type y then press enter to save that file on your system. As the figure is shown below

nano editor

Now to check that the file is created or not follow given below steps

[[email protected] ~]# 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 peanut.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 below-given command

[[email protected] ~]# cat manu.txt
technohelper24.com
rahul meena
[[email protected] ~]#

Now if you want to edit this file again from nano editor then again type nano manu.txt and then repeat the 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 and edit a file. Because it has a user-friendly interface and it is easy to use. So always use vim editor for edit and create files and use cat to saw all the content of any text file.

Comment your thoughts.

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: