|
Home | Switchboard | Unix Administration | Red Hat | TCP/IP Networks | Neoliberalism | Toxic Managers |
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and bastardization of classic Unix |
News | Books | Minitutorial | Recommended Links | Examples | |
date | rm | Unix cp command | Unix mv command | ln command | |
Admin Horror Stories | Unix History | Humor | Etc |
|
The touch command changes timestamp of the file and it file does not exits create zero length file with specified name and current timestamp (you can change timestamp from current to specified or the identical to the timestamp of the other file.
By default, the touch command updates the access and modification times of each file specified by the File or Directory parameter (you can mix files and directories in list of supplied arguments).
Syntax
touch [-acm] [-r ref_file | -t time] file...
Important options are as follows:
- -a, --time=atime, --time=access, or --time=use Changes access time only
- -c, or --no-create Doesn't create files that don't exist
- -m, --time=mtime, or --time=modify Changes modification time only
- -r file or --reference=file Uses the times from file instead of the current time
- -t Uses time instead of current time allows reset timestamps. Format is [[CC]YY]MMDDhhmm [.SS]. For example, to reset time to Jan 13, 2013 14:25 you can use:
touch -t 201301101425 usr_restore.diff- -d, --date=STRING parse STRING and use it instead of current time or --date=time. Similar -t but allows more flexible format for date (GNU touch only)
|
If you do not specify a value for the Time variable, the touch command uses the current time. If you specify a file that does not exist, the touch command creates the file unless you specify the -c flag. Creation of zero length files is probably the most common usage of the command. Another common use of touch is to create a large number of files quickly for testing scripts that read and process filenames. The touch command may also be used to assist in backup operations by manipulating access or modification times of files.
Few administrators know that the touch command also can be used for selective modification of the modification and access times using -a and -m options. If neither the -a nor -m options are specified, touch updates both the modification and access times.
Option -t allows reset timestamps. Format is [[CC]YY]MMDDhhmm [.SS]. For example, to reset time to Jan 13, 2013 14:25 you can use:
touch -t 201301101425 usr_restore.diff
The time used can be specified not only using specific time via -t time option, but also by referencing to an exiting file (with -r ref_file ).
The time used can be specified not only using specific time via -t time option, but also by referencing to an exiting file (with -r ref_file ). |
For example:
touch -r usr_restore.lst usr_restore.diff
A user with write access to a file, but who is not the owner of the file or a super-user, can change the modification and access times of that file only to the current time. Attempts to set a specific time with touch will result in an error. There is also a settime utility which is equivalent to touch -c [date_time] file.
The return code from the touch command is the number of files for which the times could not be successfully modified (including files that did not exist and were not created).
For example:
# touch foo bar blatz
If either foo, bar, or blatz does not exist, touch tries to create the file. touch cannot change files that the current user does not own or for which the user does not have write permissions.
touch - change file timestampstouch [OPTION]... FILE...
Update the access and modification times of each FILE to the current time.
A FILE argument that does not exist is created empty, unless -c or -h is supplied.
A FILE argument string of - is handled specially and causes touch to change the times of the file associated with standard output.
Mandatory arguments to long options are mandatory for short options too.
- -a
- change only the access time
- -c, --no-create
- do not create any files
- -d, --date=STRING
- parse STRING and use it instead of current time
- -f
- (ignored)
- -h, --no-dereference
- affect each symbolic link instead of any referenced file (useful only on systems that can change the timestamps of a symlink)
- -m
- change only the modification time
- -r, --reference=FILE
- use this file's times instead of current time
- -t STAMP
- use [[CC]YY]MMDDhhmm[.ss] instead of current time
- --time=WORD
- change the specified time: WORD is access, atime, or use: equivalent to -a WORD is modify or mtime: equivalent to -m
- --help
- display this help and exit
- --version
- output version information and exit
Note that the -d and -t options accept different time-date formats.
Date String
The --date=STRING is a mostly free format human readable date string such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or even "next Thursday". A date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers. An empty string indicates the beginning of the day. The date string format is more complex than is easily documented here but is fully described in the info documentation.Author
Written by Paul Rubin, Arnold Robbins, Jim Kingdon, David MacKenzie, and Randy Smith.
touch, settime- change file access and modification timestouch [-acm] [-r ref_file| -t time] file...
touch [-acm] [date_time] file...
settime [-f ref_file] [date_time] file...
The touch utility sets the access and modification times of each file. The file operand is created if it does not already exist.
The time used can be specified by -t time, by the corresponding time fields of the file referenced by -r ref_file, or by the date_time operand. If none of these are specified, touch uses the current time (the value returned by the time(2) function).
If neither the -a nor -m options are specified, touch updates both the modification and access times.
A user with write access to a file, but who is not the owner of the file or a super-user, can change the modification and access times of that file only to the current time. Attempts to set a specific time with touch will result in an error.
The settime utility is equivalent to touch -c [date_time] file.
The following options are supported for the touch utility:
- -a
- Changes the access time of file. Does not change the modification time unless -m is also specified.
- -c
- Does not create a specified file if it does not exist. Does not write any diagnostic messages concerning this condition.
- -m
- Changes the modification time of file. Does not change the access time unless -a is also specified.
- -r ref_file
- Uses the corresponding times of the file named by ref_file instead of the current time.
- -t time
- Uses the specified time instead of the current time. time will be a decimal number of the form:
[[CC]YY]MMDDhhmm [.SS]
where each two digits represent the following:
- MM
- The month of the year [01-12].
- DD
- The day of the month [01-31].
- hh
- The hour of the day [00-23].
- mm
- The minute of the hour [00-59].
- CC
- The first two digits of the year.
- YY
- The second two digits of the year.
- SS
- The second of the minute [00-61].
Both CC and YY are optional. If neither is given, the current year will be assumed. If YY is specified, but CC is not, CC will be derived as follows:
If YY is: CC becomes: 69-99 19 00-38 20 39-68 ERROR The resulting time will be affected by the value of the TZ environment variable. If the resulting time value precedes the Epoch, touch will exit immediately with an error status. The range of valid times is the Epoch to January 18, 2038.
The range for SS is [00-61] rather than [00-59] because of leap seconds. If SS is 60 or 61, and the resulting time, as affected by the TZ environment variable, does not refer to a leap second, the resulting time will be one or two seconds after a time where SS is 59. If SS is not given, it is assumed to be 0.
settime
The following option is supported for the settime utility:
- -f ref_file
- Uses the corresponding times of the file named by ref_file instead of the current time.
OPERANDS
The following operands are supported for the touch and settime utilities:
- file
- A path name of a file whose times are to be modified.
- date_time
- Uses the specified date_time instead of the current time. This operand is a decimal number of the form:
MMDDhhmm[YY]
where each two digits represent the following:
- MM
- The month of the year [01-12].
- DD
- The day of the month [01-31].
- hh
- The hour of the day [00-23].
- mm
- The minute of the hour [00-59].
- YY
- The second two digits of the year.
YY is optional. If it is omitted, the current year will be assumed. If YY is specified, the year will be derived as follows:
YY Corresponding Year 69-99 1969-1999 00-38 2000-2038 39-68 ERROR
If no -r option is specified, no -t option is specified, at least two operands are specified, and the first operand is an eight- or ten-digit decimal integer, the first operand will be assumed to be a date_time operand; otherwise, the first operand will be assumed to be a file operand.
USAGE
See largefile(5) for the description of the behavior of touch when encountering files greater than or equal to 2 Gbyte ( 231 bytes).
ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of touch: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES, and NLSPATH.
- TZ
- Determine the timezone to be used for interpreting the time option-argument or the date_time operand.
EXIT STATUS
The following exit values are returned:
- 0
- The touch utility executed successfully and all requested changes were made.
- >0
- An error occurred. The touch utility returned the number of files for which the times could not be successfully modified.
ATTRIBUTES
See attributes(5) for descriptions of the following attrib
Updates the access and modification times of a file.
touch [ -a ] [ -c ] [ -m ] [ -f ] [ -r RefFile ] [ Time | -t Time ] { File ... | Directory ... }
The touch command updates the access and modification times of each file specified by the File parameter of each directory specified by the Directory parameter. If you do not specify a value for the Time variable, the touch command uses the current time. If you specify a file that does not exist, the touch command creates the file unless you specify the -c flag.
The return code from the touch command is the number of files for which the times could not be successfully modified (including files that did not exist and were not created).
Note: Any dates beyond and including the year 2038 are invalid.
-a Changes the access time of the file specified by the File variable. Does not change the modification time unless -m is also specified. -c Does not create the file if it does not already exist. No diagnostic messages are written concerning this condition. -f Attempts to force the touch in spite of read and write permissions on a file. -m Changes the modification time of File. Does not change the access time unless -a is also specified. -r RefFile Uses the corresponding time of the file specified by the RefFile variable instead of the current time. Time Specifies the date and time of the new timestamp in the format MMDDhhmm[YY], where:
- MM
- Specifies the month of the year (01 to 12).
- DD
- Specifies the day of the month (01 to 31).
- hh
- Specifies the hour of the day (00 to 23).
- mm
- Specifies the minute of the hour (00 to 59).
- YY
- Specifies the last two digits of the year. If the YY variable is not specified, the default value is the current year.
-t Time Uses the specified time instead of the current time. The Time variable is specified in the decimal form [[CC]YY]MMDDhhmm[.SS] where:
- CC
- Specifies the first two digits of the year.
- YY
- Specifies the last two digits of the year.
- MM
- Specifies the month of the year (01 to 12).
- DD
- Specifies the day of the month (01 to 31).
- hh
- Specifies the hour of the day (00 to 23).
- mm
- Specifies the minute of the hour (00 to 59).
- SS
- Specifies the second of the minute (00 to 59).
Notes:
- The touch command calls the utime () subroutine to change the modification and access times of the file touched. This may cause the touch command to fail when flags are used if you do not actually own the file, even though you may have write permission to the file.
- Do not specify the full path name /usr/bin/touch if you receive an error message when using the touch command.
Exit Status
This command returns the following exit values:
0 The command executed successfully. All requested changes were made. >0 An error occurred. Examples
- To update the access and modification times of a file, enter:
touch program.cThis sets the last access and modification times of the program.c file to the current date and time. If the program.c file does not exist, the touch command creates an empty file with that name.
- To avoid creating a new file, enter:
touch -c program.c
- To update only the modification time, enter:
touch -m *.o
This updates the last modification times (not the access times) of the files that end with a .o extension in the current directory. The touch command is often used in this way to alter the results of the make command.- To explicitly set the access and modification times, enter:
touch -c -t 02171425 program.c
This sets the access and modification dates to 14:25 (2:25 p.m.) February 17 of the current year.- To use the time stamp of another file instead of the current time, enter:
touch -r file1 program.c
This gives the program.c file the same time stamp as the file1 file.- To touch a file using a specified time other than the current time, enter:
touch -t 198503030303.55 program.c
This gives the program.c file a time stamp of 3:03:55 a.m. on March 3, 1985.Files
/usr/bin/touch Contains the touch command. Related Information
The date command, locale command.
The utime subroutine.
Directory Overview in AIX 5L Version 5.1 System User's Guide: Operating System and Devices describes the structure and characteristics of directories in the file system.
Files Overview in AIX 5L Version 5.1 System User's Guide: Operating System and Devices describes files, file types, and how to name files.
File and Directory Access Modes in AIX 5L Version 5.1 System User's Guide: Operating System and Devices introduces file ownership and permissions to access files and directories.
Understanding File Types in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs introduces the commands that control files.
Society
Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers : Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism : The Iron Law of Oligarchy : Libertarian Philosophy
Quotes
War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda : SE quotes : Language Design and Programming Quotes : Random IT-related quotes : Somerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose Bierce : Bernard Shaw : Mark Twain Quotes
Bulletin:
Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 : Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law
History:
Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds : Larry Wall : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOS : Programming Languages History : PL/1 : Simula 67 : C : History of GCC development : Scripting Languages : Perl history : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history
Classic books:
The Peter Principle : Parkinson Law : 1984 : The Mythical Man-Month : How to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite
Most popular humor pages:
Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor
The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D
Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.
This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...
|
You can use PayPal to to buy a cup of coffee for authors of this site |
Disclaimer:
The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.
Last modified: March 12, 2019