One Linux command per day (4) Touch command

Source: Internet
Author: User
Tags touch command

The Touch command has two functions: one is to update the time tags of existing files to the current time of the system (the default), their data will remain intact, and the second is to create new empty files.

(1) Usage

Usage: Touch [options] ... File...

(2) function

1) Change the access time and modification time of each file to the current time;

2) files that do not exist will be created as empty files unless you use the-C or-h option;
(3) option parameters
1)-F,--force ignore nonexistent files, never give hints
2)-I,--interactive for interactive deletion
3)-R,-R,--recursive instructs RM to recursively delete all directories and subdirectories listed in the parameters
4)-V,--verbose detailed display of the steps performed
5)--help Display this help message and exit
6)--version output version information and exit
7)-A only change access time
8)-D,--date= string represents the time instead of the current time using the specified string
9)-T STAMP replaces the current time with [[CC]YY]MMDDHHMM[.SS] Format time
(4) Example:
1) [[email protected]/]# touch/home/sunjimeng/document/touch_test_file Create a file at the specified moment, if not specified, the default is under the current folder (if the file already exists, Can be viewed as a re-change of file archive time)

[Email protected]/]# ls-l/home/sunjimeng/Total Document Usage0DRWXRWXR-X.3Sunjimeng Sunjimeng -May1 Geneva: -BINDRWXRWXR-X.3Sunjimeng Sunjimeng -May1 Geneva: +Father[[email protected]/]# touch/home/sunjimeng/document/Touch_test_file[[email protected]/]# CD home/sunjimeng/Document[[email protected] document]# ll total dosage0DRWXRWXR-X.3Sunjimeng Sunjimeng -May1 Geneva: -BINDRWXRWXR-X.3Sunjimeng Sunjimeng -May1 Geneva: +Father-rw-r--r--.1Root root0May1  -: -Touch_test_file//time of first creation [[email protected] document]#

[email protected] document]# Touch touch_test_file
[email protected] document]# LL
Total dosage 0
Drwxrwxr-x. 3 Sunjimeng Sunjimeng 17 May 1 03:13 Bin
Drwxrwxr-x. 3 Sunjimeng Sunjimeng 18 May 1 03:21 Father
-rw-r--r--. 1 root root 0 May 1 18:35 touch_test_file//The second time the file is changed is the current time, the content is unchanged if the contents are present in the file

2) [[email protected] document]# touch-t 06061806 touch_test_file do not create a file, just change the document time (here Plus-C operation is the same)

[Email protected] document]# touch-t06061806Touch_test_file[[email protected] document]# ll total dosage0DRWXRWXR-X.3Sunjimeng Sunjimeng -May1 Geneva: -BINDRWXRWXR-X.3Sunjimeng Sunjimeng -May1 Geneva: +Father-rw-r--r--.1Root root0June6  .Touch_test_file

3) [[email protected] document]# Touch touch_test_file1 touch_test_file2 Change touch_test_file2 time to Touch_test_ File1 the same time.

[[email protected] document]# Touch Touch_test_file2[[email protected] document]# ll total dosage0DRWXRWXR-X.3Sunjimeng Sunjimeng -May1 Geneva: -BINDRWXRWXR-X.3Sunjimeng Sunjimeng -May1 Geneva: +Father-rw-r--r--.1Root root0June6  .touch_test_file//Two files time is different-rw-r--r--.1Root root0May1  -: thetouch_test_file2 [[email protected] document]# Touch-R touch_test_file Touch_test_file2[[email protected] document]# ll total dosage0DRWXRWXR-X.3Sunjimeng Sunjimeng -May1 Geneva: -BINDRWXRWXR-X.3Sunjimeng Sunjimeng -May1 Geneva: +Father-rw-r--r--.1Root root0June6  .touch_test_file//Two files in the same time-rw-r--r--.1Root root0June6  .Touch_test_file2

4) [[email protected] document]# touch-d "days ago" Touch_test_file2 Change the current specified file time to relative current past or future time

[Email protected] document]# touch-d"Ten days ago"Touch_test_file2[[email protected] document]# ll total dosage0DRWXRWXR-X.3Sunjimeng Sunjimeng -May1 Geneva: -BINDRWXRWXR-X.3Sunjimeng Sunjimeng -May1 Geneva: +Father-rw-r--r--.1Root root0June6  .Touch_test_file-rw-r--r--.1Root root0April +  -: -Touch_test_file2//Not 10 days before June 6, but 10 days before the current time

5) [email protected] document]# Touch--help and Touch--version

[email protected] document]# touch--Help usage: touch [options] ... File... Update the access and modification times of each FILE to the current time. A FILE argument that does not exist isCreated empty, unless-c or-h issupplied. A FILE Argumentstringof- ishandled specially and causes touch tochange The times of the file associated with standard output. Mandatory arguments toLongOptions are mandatory for  Shortoptions too. -A Change access time only-C,--no-create creates no files-D,--date=string representing time instead of current time using the specified string-f (Ignore)-H,--no-dereference affects the symbolic link itself, not the destination indicated by the symbolic link (this option is useful when the system supports changing the owner of a symbolic link)-m change modification time only-R,--reference=file use ThisFile's times instead of current time-t STAMP use [[CC]YY]MMDDHHMM[.SS] instead of the current time--time=WORD Change the specified Time:word isAccess, Atime, or use:equivalent to-a WORD isModify or Mtime:equivalent to-m--Help displays this information and exits--version displays release information and exits please note thatThe-D and-t options can accept different times/date format. GNU coreutils online Help://www.gnu.org/software/coreutils/>Please refer to //translationproject.org/team/zh_cn.html> report Touch translation ErrorsTo get the complete document, run: info coreutils'Touch Invocation'[[email protected] document]# Touch--Versiontouch (GNU coreutils)8.22Copyright (C) -Free Software Foundation, Inc. License: GPLv3+:GNU General Public License version 3rd or later //gnu.org/licenses/gpl.html>. This software is free software: You are free to modify and republish it. There is no other guarantee within the scope of the law. Written by Paul Rubin, Arnold Robbins, Jim Kingdon, David MacKenzie, and Randy Smith. 

(5) Other

Description

-T time uses the value specified as a new value for the corresponding time stamp of the specified file. The time specified here is a decimal number in the following form:

[[Cc]yy] mmddhhmm[. SS]

Here, CC is the first two digits of the number of years, that is, "century"; yy is the last two digits of the number of years, that is, the number of years in a century. If the value of CC is not given, touch will limit the number of years Ccyy to 1969--2068. MM for the number of months, DD for the day will be the number of years Ccyy limited to 1969--2068 within. MM is the number of months, DD is the number of days, HH is the number of hours (several), MM is the number of minutes, SS is the number of seconds. The set range of seconds here is 0--61, which can handle leap seconds. These numbers consist of a time in the time zone specified by the environment variable TZ. Due to system limitations, the time earlier than January 1, 1970 was wrong.

One Linux command per day (4) Touch command

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.