touch command in linux allows you to create a file and modify or change time stamp and also to create files with extension.
linux touch command with syntax and examples
![]() |
linux touch command |
Hello, guys welcome to the next session on linux command line tutorial. In this session, we will learn how to use "touch command" in Linux.
The "touch" command is used to change the "timestamps" on existing files or directories.
It is also used to create new empty files in Linux.
So let's see how you can use it. First of all, I will open my terminal and as you can see on the desktop I have a directory called dir.
![]() |
Preview of dir |
let's list all the contents of the directory. So I will just do "ls -l" for a long list and you can see this directory contains 4 files.
And you can see the time of the files. Which is the "timestamp" at which they are created or updated.
Create a simple file
![]() |
create an empty file using touch command |
$touch fileName
Now I want to create a new empty file. We can use a "touch" command to create a new empty file.
And to create a new empty file you just need to write "touch" and give the name of the file.
So you can see the directory already contains 4 files and I want to create a "fifth file".
So I can just say "touch file5" and press ENTER.
Create a file with an extension
![]() |
Create a txt file using the touch command |
$touch filename.extension
Now earlier with touch command, I have only used the name of the file.
I can even give the "extension of the file".
For example "touch file6.txt" you can give any other extension and it will create it.
Create or modify the time stamp
![]() |
Modify the time stamp using touch command |
$touch fileName
Now the second use of touch command is to change the timestamp of a file.
For example, I want to change the timestamp on "file1" at which they are modified or created.
Then what I can do is I can use the "touch command" on them.
So if the file doesn't exist and if you use "touch" command then it's going to create a file.
If I use the "touch" command on the file which already exists it's going to update the "timestamp" of this file to the current time.
I can just say "touch file1" and press ENTER.
So in this way you can update the timestamp of the file using the touch command.
Conclusion
So these are the two basic uses of "touch command".
- First is to create empty files.
- The second is to update the timestamp of a given file.
So I hope you enjoyed this tutorial please rate your comment and bye for now.
HAVE A NICE DAY💗
Related,