Linux Create File: Linux touch Command

linux-touch-command-linux-file-create

Linux Create File

In Linux, sometimes we need to create files. To create a file in Linux, we use Linux touch command. In this Linux lesson, we will learn Linux create file operation with the help of Linux touch. We will give Linux touch example to learn this important command quickly.  As a Linux administrator, you will use touch command a lot in your career.

 

Let’s firstly start with Linux create file operation. To create an empty file in Linux, we use touch command. With Linux touch, we can create an empty file with a given name.

 

Let’s create xyz file with touch command. To do this, we will use firstly the command and the name of the new file like “touch xyz” command.

 

root@kali:/home/kali# touch xyz

 

After using this linux create file command, now, let’s check files with ls -l command and see our new xyz file. I will use tail -5 option also to see only the latest created 5 files.

 

root@kali:/home/kali# ls -l | tail -5

-rw-r--r-- 1 kali    kali       0 Jun 11  2021 ppp.php

drwxr-xr-x 2 kali    kali    4096 Jan 27  2020 Public

drwxr-xr-x 2 kali    kali    4096 Jan 27  2020 Templates

drwxr-xr-x 2 kali    kali    4096 Jan 27  2020 Videos

-rw-r--r-- 1 root    root       0 Sep 29 16:46 xyz

 


 

Linux touch Command Examples

There are different options used with Linux touch command. One of them is -m. With touch -m, we can change a file’s modification time.

 

As you can see above, xyz file creation time is 16:46. Now, we will use “touch xyz -m” command, and this time will be updated.

 

root@kali:/home/kali# touch xyz -m

 

As you can see, the file creation time has modified.

 

root@kali:/home/kali# ls -l | tail -5

-rw-r--r-- 1 kali    kali       0 Jun 11  2021 ppp.php

drwxr-xr-x 2 kali    kali    4096 Jan 27  2020 Public

drwxr-xr-x 2 kali    kali    4096 Jan 27  2020 Templates

drwxr-xr-x 2 kali    kali    4096 Jan 27  2020 Videos

-rw-r--r-- 1 root    root       0 Sep 29 16:50 xyz

 

The other option is touch -a option. This option changes the access time of a file. In other words, we modify the access time of a file with -a option.

 

root@kali:/home/kali# touch xyz -a

 

We can also use one file’s time as reference. To do this, we use touch -r option. Below, we will use directory Videos’s creation time also for file xyz. You can also use –reference option for this purpose. It is similar to -r option.

 

root@kali:/home/kali# touch xyz -r Videos

 

As you can see below, xyz file creation time has changed as Videos. In other words, we have modified the creataion time of our file, xyz, as directory videos

 

root@kali:/home/kali# ls -l | tail -5

-rw-r--r-- 1 kali    kali       0 Jun 11  2021 ppp.php

drwxr-xr-x 2 kali    kali    4096 Jan 27  2020 Public

drwxr-xr-x 2 kali    kali    4096 Jan 27  2020 Templates

drwxr-xr-x 2 kali    kali    4096 Jan 27  2020 Videos

-rw-r--r-- 1 root    root       0 Jan 27  2020 xyz

 

Especially file management is very imporant for Linux system administrators. As a Linux admin, you will work with files too much. SO, you will create files, modify them or delete them during your job. So, you will use the commands of this lesson a lot.

 

Linux touch command is an important command and it is one of the most useful commands for Linux system administrators. To create a file in Linux, you will use this command a lot too.

 

Lesson tags: linux create file
Back to: Kali Linux Course

Leave a Reply

Your email address will not be published.

IPCisco is the Winner of 2019 “Best Certification Study Journey” Category! We are also Finalist of 2020 & 2021 in Cisco IT Blog Awards!

Cisco-ITBlogAwards-2019-Winner-IPCisco-k
ITBlogAwards_2020_Badge-Finalist-BestCertStudy-ipcisco
ITBlogAwars-2021-ipcisco
IPCisco on Social Media!