Intro To 'touch' Command In Linux
2023-04-30 - By Robert Elder
I use the touch command to create empty files or update timestamps. For example, I can use the touch command to quickly create an empty '__init__.py' file to indicate that this directory should be treated as a python package:
touch __init__.py
and the output is:
ls -l
and the output from the 'ls' command now shows the following:
total 0
-rw-rw-r-- 1 robert robert 0 May 1 22:46 __init__.py
You can also use the touch command to create multiple files at once, like this:
touch main.py README.txt text.csv
ls -l
Now the output from running 'ls' shows the following:
total 0
-rw-rw-r-- 1 robert robert 0 May 1 22:46 __init__.py
-rw-rw-r-- 1 robert robert 0 May 1 22:47 main.py
-rw-rw-r-- 1 robert robert 0 May 1 22:47 README.txt
-rw-rw-r-- 1 robert robert 0 May 1 22:47 text.csv
The touch command can also be used on an existing file to update its last modified timestamp. For example, if we focus on the last modified timestamp of the 'main.py' file:
ls -l main.py
-rw-rw-r-- 1 robert robert 0 May 1 22:47 main.py
Now, if I run the 'touch' command on this file again:
touch main.py
ls -l main.py
The output from the 'ls' command shows an updated last modified timestamp:
-rw-rw-r-- 1 robert robert 0 May 1 22:53 main.py
As you can see from the above output, the last modified timestamp was updated to 'May 1, 22:53' which is different from the value of 'May 1, 22:47' that it had previously.
This feature of the 'touch' command is useful since some programs like GNU make or rsync will change their behavior according to the last modified timestamps of certain files.
And that's why the touch command is my favorite Linux command.
Intro To 'stty' Command In Linux
Published 2023-10-04 |
$1.00 CAD |
Intro To 'nproc' Command In Linux
Published 2023-07-15 |
Intro To 'comm' Command In Linux
Published 2023-09-06 |
How To Force The 'true' Command To Return 'false'
Published 2023-07-09 |
A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21 |
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01 |
Intro To 'chroot' Command In Linux
Published 2023-06-23 |
Join My Mailing List Privacy Policy |
Why Bother Subscribing?
|