what is the command to display on-line manual for touch command

Touch command in Linux

Affect command in Linux is used for changing file timestamps however i of the near common usages of touch command includes creating a new empty file.

With the impact control, you can alter access, modify and alter time of files and folders in Linux. Yous can update the timestamps or modify them to a date in the past.

The syntax for touch on command is quite simple:

            touch on [option] file          
Touch command syntax

What are file timestamps in Linux, again?

I have written well-nigh timestamps in Linux in detail in an earlier article. I would recommend reading it for a better and clearer understanding. For the sake of a quick remember, I'll list the timestamps here:

  • access time – terminal time when a file was accessed
  • modify time – last fourth dimension when a file was modified
  • change time – last fourth dimension when file metadata (file permission, ownership etc) was changed

You can see the timestamps of a file using the stat command in the following way:

            stat abhi.txt    File: abhi.txt   Size: 10        	Blocks: 8          IO Cake: 4096   regular file Device: 10305h/66309d	Inode: 11940163    Links: i Access: (0644/-rw-r--r--)  Uid: ( yard/abhishek)   Gid: ( one thousand/abhishek) Access: 2018-09-02 14:12:24.476483367 +0530 Modify: 2018-09-02 14:12:24.476483367 +0530 Change: 2018-09-02 14:12:24.476483367 +0530  Birth: -          

Stat command even shows the inode number of the file.

ix Practical examples of touch command in Linux

Now let'southward come across how to use the touch control with some simple but useful examples.

1. Create an empty  file

Equally I mentioned before, this is the most mutual use of touch control. All you have to do is to use touch with the file proper noun.

            bear on <filename>          

This will create an empty file if the file doesn't exist.

            touch empty_file ls -50 empty_file  -rw-r--r-- 1 abhishek abhishek 0 Sep  ii 14:37 empty_file          

Only what if the file already exists? In that example, it will update all three timestamps of the file to the current time.

2. Create multiple empty files

You can apply touch to create more than than ane empty file too. Just provide the names of the files you desire to create.

            touch <file1> <file2> <file3>          

If you call up it'southward tiring to write all filenames, you lot can auto-generate filenames in this way:

            bear on new-file-{1..x}.txt          

This will create new-file-1.txt, new-file-2.txt upto new-file-10.txt.

3. Avoid creating a file with affect if it doesn't exist

Touch will update the timestamps of input file if it exists and will create an empty file if the input file does non be.

Only what if you don't want bear on to create a new empty file? You want it to update the timestamps of the file but if the file doesn't exist, it should not be created.

Yous tin can apply the bear on command with -c choice in such cases:

            bear on -c <filename>          
Recall: Touch will create a new empty file if it doesn't exist else it will change the timestamps of the existing file. You can stop the creation of a new file with the -c selection.

iv. Alter all timestamps of a file

If y'all utilize affect an existing file, it volition alter access, modify and change time of that file.

For example, I have this file named sherlock.txt with the post-obit timestamps:

            stat sherlock.txt    File: sherlock.txt   Size: 356       	Blocks: 8          IO Cake: 4096   regular file Device: 10305h/66309d	Inode: 11928277    Links: 1 Access: (0777/-rwxrwxrwx)  Uid: ( k/abhishek)   Gid: ( 1000/abhishek) Admission: 2018-08-25 09:44:56.092937000 +0530 Change: 2018-08-09 09:41:05.028309000 +0530 Modify: 2018-08-25 09:44:56.096937182 +0530                      

If I apply bear on on this command, all timestamps will be changed to the current timestamps.

            touch sherlock.txt  stat sherlock.txt    File: sherlock.txt   Size: 356       	Blocks: 8          IO Cake: 4096   regular file Device: 10305h/66309d	Inode: 11928277    Links: 1 Access: (0777/-rwxrwxrwx)  Uid: ( 1000/abhishek)   Gid: ( yard/abhishek) Access: 2018-09-02 15:22:47.017037942 +0530 Modify: 2018-09-02 15:22:47.017037942 +0530 Change: 2018-09-02 15:22:47.017037942 +0530  Nascence: -                      

Note: You should not be bothered with ctime (change time). It's a system holding and cannot/shouldn't be controlled past the user. Your focus should be on access and modify time.

5. Update simply access fourth dimension of file

You may non always want to change all the timestamps of a file. If you just want to modify the access fourth dimension of a file, you can utilize the -a pick with touch.

            impact -a sherlock.txt  stat sherlock.txt    File: sherlock.txt   Size: 356       	Blocks: 8          IO Block: 4096   regular file Device: 10305h/66309d	Inode: 11928277    Links: ane Access: (0777/-rwxrwxrwx)  Uid: ( yard/abhishek)   Gid: ( 1000/abhishek) Access: 2018-09-02 15:29:08.796926093 +0530 Modify: 2018-09-02 xv:22:47.017037942 +0530 Change: 2018-09-02 15:29:08.796926093 +0530  Nascence: -          

six. Update just modify time of file

If yous only desire to update the change fourth dimension of a file to the current timestamp, apply the -m option of bear on command.

            bear upon -grand sherlock.txt  stat sherlock.txt    File: sherlock.txt   Size: 356       	Blocks: eight          IO Cake: 4096   regular file Device: 10305h/66309d	Inode: 11928277    Links: 1 Admission: (0777/-rwxrwxrwx)  Uid: ( 1000/abhishek)   Gid: ( yard/abhishek) Access: 2018-09-02 15:29:08.796926093 +0530 Modify: 2018-09-02 15:31:25.770866881 +0530 Modify: 2018-09-02 15:31:25.770866881 +0530  Birth: -          

seven. Apply timestamps of another file

You tin also apply the timestamps of another file as a reference with the -r choice in the following fashion:

            touch -r <source_file> <target_file>          

This will ready the access and modify time of the target file same as the access and change fourth dimension of the source file.

8. Fix specific access and modification time

You might accept noticed that in almost all the cases (except the reference file one), the timestamps are changed to the current timestamp.

Simply you are non bound with that. Affect allows you to set admission and modification time to a by or future engagement. You tin can use the -t option and a timestamp in the post-obit format:

[[CC]YY]MMDDhhmm[.ss]

  • CC – First two digits of a year
  • YY – 2d two digits of a year
  • MM – Calendar month of the yr (01-12)
  • DD – Day of the month (01-31)
  • hh – Hour of the day (00-23)
  • mm – Infinitesimal of the 60 minutes (00-59)
  • ss – Seconds (00-59)

In the above case, CC is optional. In fact, CCYY is optional as well, it will take the electric current yr in that example. Similarly, seconds are optional as well, information technology defaults to 00.

Let me evidence you an case by changing the timestamp to 12021301 i.due east., 12th month, second day, 13th hour and kickoff minute of the current year:

            touch -t 12021301 agatha.txt  stat agatha.txt    File: agatha.txt   Size: 457       	Blocks: 8          IO Cake: 4096   regular file Device: 10305h/66309d	Inode: 11928279    Links: 1 Access: (0777/-rwxrwxrwx)  Uid: ( 1000/abhishek)   Gid: ( grand/abhishek) Access: 2018-12-02 13:01:00.000000000 +0530 Alter: 2018-12-02 13:01:00.000000000 +0530 Change: 2018-09-02 15:59:47.588680901 +0530  Birth: -          

If you endeavour to enter an invalid engagement, you'll run into an fault. You'll also discover that change time is using the current timestamp, not the aforementioned equally admission and modify. It's considering it's system property.

You can as well use touch command with symbolic links. You just have to use the -h option while dealing with symbolic links. The rest stays the aforementioned as the regular files.

            touch -h <symbolic_link>          

I hope you notice these touch command examples in Linux helpful. If you accept any questions or suggestions, practise permit me know.

broussardequother.blogspot.com

Source: https://linuxhandbook.com/touch-command/

0 Response to "what is the command to display on-line manual for touch command"

Postar um comentário

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel