8 Pratical Examples of Linux “Touch” Command--reference
In?Linux?every single file is associated with timestamps,and every file stores the information of last access time,last modification time and last change time. So,whenever we create new file,access or modify an existing file,the timestamps of that file automatically updated. In this article we will cover some useful practical examples of Linux?touch command. Thetouch command?is a standard program for?Unix/Linux?operating systems,that is used to create,change and modify timestamps of a file. Before heading up for touch command examples,please check out the following options. Touch Command Options
1. How to Create an Empty FileThe following touch command creates an empty (zero byte) new file called?sheena. # touch sheena 2. How to Create Multiple FilesBy using touch command,you can also create more than one single file. For example the following command will create 3 files named,?sheena,?meena?and?leena. # touch sheena meena leena 3.?Change File’s Access Time using -aWe can change the access time of a file using -a option. By default it will take the current system time and update the atime field. Before touch command is executed: $ stat tgs.txt $ touch -a tgs.txt After the above touch command (Please note that the access time is changed): $ stat tgs.txt 4. How to Avoid Creating New FileUsing?-c?option with touch command avoids creating new files. For example the following command will not create a file called?leena?if it does not exists. # touch -c leena 5. How to Change File Modification TimeIf you like to change the only modification time of a file called?leena,then use the?-moption with touch command. Please note it will only updates the last modification times (not the access times) of the file. # touch -m leena 6.?Explicitly Setting Access and Modification time using -t and -dInstead of taking the current time-stamp,you can explicitly specify the time using -t and -d options. The format for specifying -t is [[CC]YY]MMDDhhmm[.SS] $ touch -t [[CC]YY]MMDDhhmm[.SS] The following explains the above format:
For example: $ touch -a -m -t 203801181205.09 tgs.txt Verify the above change using stat command: $ stat tgs.txt File: `tgs.txt' Size: 3 Blocks: 8 IO Block: 4096 regular file Device: 801h/2049d Inode: 394283 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/lakshmanan) Gid: ( 1000/lakshmanan) Access: 2038-01-18 12:05:09.000000000 +0530 Modify: 2038-01-18 12:05:09.000000000 +0530 Change: 2012-10-19 00:40:58.763514502 +0530 You can also use a string to change the time Another example: $ touch -d "2012-10-19 12:12:12.000000000 +0530" tgs.txt For developers,touch command will be really helpful when you are working with? 7. How to Use the time stamp of another FileThe following touch command with?-r?option,will update the time-stamp of file?leena?with the time-stamp of?meena?file. So,both the file holds the same time stamp. # touch -r leena meena 8. Create a File using a specified timeIf you would like to create a file with specified time other than the current time,then the format should be. # touch -t YYMMDDHHMM.SS tecmint For example the below command touch command with?-t?option will gives the?tecmint?file a time stamp of?18:30:55 p.m. on?December 10,?2012. # touch -t 201212101830.55 tecmint 9. 批量创建文件 #!/bin/ name {..
We’ve almost covered all the options available in the touch command for more options use “man touch“. If we’ve still missed any options and you would like to include in this list,please update us via comment box. reference : http://www.tecmint.com/8-pratical-examples-of-linux-touch-command/ http://www.thegeekstuff.com/2012/11/linux-touch-command/ ?linux shell 脚本攻略 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |