How to Create New Files on Linux Using touch
If you’re new to the world of Linux, creating new files might seem like a daunting task. However, with the touch command, it’s actually quite easy. In this article, we’ll go over how to create new files on Linux using touch.
What is the touch command?
The touch command is used to create new files, as well as modify the modification and access times of existing files. When used to create a new file, touch will simply create an empty file with the specified filename.
Using touch to create a new file
To create a new file using touch, simply open up your terminal and type the following command:
$ touch filename
Replace “filename” with the desired name of your new file. For example, if you wanted to create a file called “example.txt”, you would type:
$ touch example.txt
Once you hit enter, the new file will be created in your current working directory.
Modifying the access and modification times
As mentioned earlier, touch can also be used to modify the access and modification times of existing files. This is useful when you need to set specific timestamps on files.
To modify the access and modification times of a file, use the following command:
$ touch -a -m file
The “-a” option will update the access time of the file, while the “-m” option will update the modification time. Again, replace “file” with the name of the file you want to modify.
Creating multiple files at once
If you need to create multiple files at once, you can use touch in conjunction with a wildcard. For example, let’s say you wanted to create three new files called “file1.txt”, “file2.txt”, and “file3.txt”. You could use the following command:
$ touch file*.txt
This command tells Linux to create any files that start with “file” and end with “.txt”.
In conclusion, using touch is a simple and quick way to create new files on Linux. It’s a useful command to know, and it can save you a lot of time and effort when working with Linux on a daily basis.