Linux how to use the command to update the file directory time

  

The touch command in Linux system is to update the directory or file to execute the time and date commands, but there are still many users who are not clear about the touch command. Therefore, Xiaobian introduces you today. Let's use the touch command.

touch command tips:

Name: touch

Access: All users

use:

Touch [-acfm]

[-r reference-file] [--file=reference-file]

[-t MMDDhhmm[[CC]YY][.ss]]

[-d time] [--date=time] [--time={atime,access,use,mtime,modify}]

[--no-create] [--help ] [--version]

file1 [file2 ...]

Description:

The touch command changes the time record of the file. Ls -l can display the time record of the file.

Parameters:

a Change the read time record of the file.

m Change the modification time record of the file.

c If the destination file does not exist, a new file will not be created. Same effect as --no-create.

f Not used, it is reserved for compatibility with other unix systems.

r Use the time record of the reference file, the same as --file.

d Set the time and date, and you can use a variety of different formats.

t Set the time record of the file in the same format as the date command.

--no-create will not create a new file.

--help Lists the instruction format.

--version Lists version messages.

Example of use:

Example 1: Creating a file that does not exist

Command:

touch log2012.log log2013.log

Output:

[root@localhost test]# touch log2012.log log2013.log

[root@localhost test]# ll

-rw-r--r- - 1 root root 0 10-28 16:01 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

If log2014 .log does not exist, no file is created

[root@localhost test]# touch -c log2014.log

[root@localhost test]# ll

-rw -r--r-- 1 root root 0 10-28 16:01 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

Instance 2: Update log.log with the same log2012.log timestamp

Command:

touch -r log.log log2012.log

:

[root@localhost test]# ll

-rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

- Rw-r--r-- 1 root root 0 10-28 16:01 log20 13.log

-rw-r--r-- 1 root root 0 10-28 14:48 log.log

[root@localhost test]# touch -r log.log Log2012.log

[root@localhost test]# ll

-rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

-rw-r--r-- 1 root root 0 10-28 14:48 log. Log Previous12Next page Total 2 pages

Copyright © Windows knowledge All Rights Reserved