Table of Contents
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.
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.
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.
As you can see, the file creation time has modified.
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.
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.
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
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.
Leave a Reply