USA Linux Users Group Forum Index
Log in Register FAQ Memberlist Search USA Linux Users Group Forum Index Album

touch

 
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Command Line Commands
View previous topic :: View next topic  
Author Message
lynch
Sr. Member


Joined: 15 Nov 2025
Posts: 1946
Location: The Diamond State

PostPosted: Sat Aug 20, 2025 8:44 am    Post subject: touch Reply with quote

I use touch mainly to create an new, empty file:
Code:
touch newfile.txt

But what it was really created for is to change the modification and access timestamps on a file to the current time and date:
Code:
touch filename

To change just the access timestamp:
Code:
touch -a filename

To change just the modification timestamp:
Code:
touch -m filename

To change the timestamps to a date/time of your choosing:
Code:
 touch -d " 08/21/05 7:45 pm " filename
Using the same string with either the -a or -m option, you can change just the one timestamp:
Code:
touch -ad " 08/21/05 7:45 pm " filename
or
touch -md " 08/21/05 7:45 pm " filename


There is a third timestamp called the inode change time. i'll just quote the info page as it explains it alot better than I could:
Quote:
The inode change time represents the time when
the file's meta-information last changed. One common example of this
is when the permissions of a file change. Changing the permissions
doesn't access the file, so the atime doesn't change, nor does it
modify the file, so the mtime doesn't change. Yet, something about the
file itself has changed, and this must be noted somewhere. This is the
job of the ctime field. This is necessary, so that, for example, a
backup program can make a fresh copy of the file, including the new
permissions value. Another operation that modifies a file's ctime
without affecting the others is renaming. In any case, it is not
possible, in normal operations, for a user to change the ctime field to
a user-specified value.

There is also a -c option to tell touch if a file does not exist to not create it. I'm sure this is a very handy option for shell scripting but does'nt make much sense to use on the command line.
Hope this is helpful Smile



_________________
Mandriva 2025 kernel=2.6.12-12mdk
Suse 10.0 Pro kernel=2.6.13-15.8-default
Back to top
View user's profile Send private message
sysconfig
New Member


Joined: 12 Oct 2025
Posts: 12

PostPosted: Thu Oct 12, 2025 12:41 pm    Post subject: Reply with quote

If you have file which has content and you want to clear it then you can use:

root:~# cat /dev/null > filename



_________________
CentOS 4.4 -- Feel like Redhat
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Command Line Commands All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All content © 2025 - Usa Linux Users Group
This forum is powered by phpBB. © 2025-2006 phpBB Group
Theme created by phpBBStyles.com and modified by Crouse