The touch
command comes as part of the GNU Core-utilities and creates a new file in Linux using the terminal.
The GNU Core-utilities package can be installed and run on any Unix-like operating system.
The touch
command is capable of performing multiple tasks. A different argument is loaded for each function. In this shot, we will go through the most frequently used arguments.
We can use the touch
command to create new files by giving file names as the input. Multiple file names may be input at once:
touch filename1 filename2
The -a
argument is used to change the access time of a file. The name of the file which we wish to modify is given as the second argument.
The -c
argument is used to check if a file with the given filename exists or not.
The -c-d
argument is used to change a given file’s access and modification times.
The -m
argument is used to alter only the modification time.
Note that filename(s) is mandatory for all types of arguments.
In the example below, we create two files using the touch
command. Subsequently, we use the -a
, -c
, and -m
arguments to see if these files we created actually exist or not, and then modify their timestamps.
We use the ls -l
command to observe how the details of the two files change.
Free Resources