Hello everyone In this Article we are going to learn how to work with files in Linux in a very simple and easy step-by-step approach
touch command
The touch command is used to make the files in the Linux kernel.
This command also creates blank files in Linux.
With the touch command, we can also update the timestamp of a file in Linux.
Before Jumping on the command we should know the syntax of the touch command
touch [Option]… File …
1 ) How to Create File
To create only one File in the current location then we can run the touch command.
$ touch File.txt
2) How to Create File In Different Location
To Create the File in some other location then we have to specify the full path of the location where we want to create the directory.
In this example, We are creating the directory inside /tmp directory.
$ touch /tmp/File2.txt
3) How to Create Multiple Files in A single Command
To create the 10 Files using the single command then we can add the curly braces {} and define the number of files that we want to create.
$ touch MultipleFiles{1..10}
5) How to Create Hidden File
To create the hidden file using the touch command then we can add the ( . ) symbol before the name of the file.
$ touch .HiddenFile
6) How to create a file with customized timestamp
To create the File with a customized timestamp then we add the ( – t ) option in the touch command
$ touch -t 2102180521 CustomTimeFile.txt
The arguments are as follow
- 21 – This is the year
- 02 – This is the month
- 18 – This is the date
- 05 – This is the time
- 21 – This is the minutes .
February 18 2021 is the date that we define above for creation of a file.
- touch command is also use to update the timestamp of the file
7) How to view the status of a file
To see the status of any file which includes all the detailed information of any file then we can use the stat command.
$ stat File1.txt
# touch File1.txt -If we again run the touch command on tutdevops.txt its timestamp will not be changed to the current time.
In above examples earlier the time stamp is different not it is different.
8) How to Create Multiple Directories With Different Names
To create multiple files using the touch command then simply add the file names after the touch command
If you don’t specify the location then the file will create in the current location only.
$ touch File1.txt File2.txt File3.txt
9) How to check version Of the touch command
To check what is the version of the touch command then we can execute the below command.
$ touch --version
10) How to View the Most useful Options in the touch command
To know the most useful options with the touch command then we can execute the below command.
$ touch--help
Conclusion
If you want to learn Linux in the most simple language then please click on this link.
If you want to see the man page of touch command online then click on this link
This is the complete knowledge of how we can work with files in the Linux kernel if you have any doubts please feel free to comment below. Please don’t forget to join our email subscription to get the latest updates on the DevOps post.