Linux Commands Examples

A great documentation place for Linux commands

touch

change file timestamps

Synopsis

touch [OPTION]... FILE...


add an example, a script, a trick and tips

: email address (won't be displayed)
: name

Step 2

Thanks for this example ! - It will be moderated and published shortly.

Feel free to post other examples
Oops ! There is a tiny cockup. A damn 404 cockup. Please contact the loosy team who maintains and develops this wonderful site by clicking in the mighty feedback button on the side of the page. Say what happened. Thanks!

examples

1
Modify timestamp (YYMMDDhhmm):



touch -t 1311240733 file
example added by LeBerger
0
Modify timestamp (YYMMDDhhmm):



touch -t 1311240733 file
example added by LeBerger
0
source
            
touch ldap-todo.touch
0
source
            
touch Makefile
0
source
            
touch palladius.it-todo.touch
0
source

How do I recursively touch files matching a pattern

With find:

find ~/docs -name "*.txt" -exec touch {} \;

  • You search in ~/docs
  • The name option will match all txt files - exec will execute the command touch on the file name, which is substituted in {}
  • \; ends the command and touch will be called once for each file found

Note:

  • A slight variation, \+ at the end constructs one single command to run touch on all of these files at once. This is not possible with all commands, but it works for touch and saves you a few calls if you have a lot of files that are affected.
0
source

Touch Change Access, Modify AND Change

The what? The modified time is the time the file was last changed.

$ touch test
$ stat test
  File: `test'
  Size: 749             Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d    Inode: 33          Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/      me)   Gid: ( 1000/      me)
Access: 2012-03-06 18:43:19.000000000 -0600
Modify: 2012-03-06 18:43:19.000000000 -0600
Change: 2012-03-06 18:43:19.000000000 -0600
$ touch test
$ stat test
  File: `test'
  Size: 749             Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d    Inode: 33          Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/      me)   Gid: ( 1000/      me)
Access: 2012-03-06 18:43:23.000000000 -0600
Modify: 2012-03-06 18:43:23.000000000 -0600
Change: 2012-03-06 18:43:23.000000000 -0600

0
source

How can I change the creation time of all a folder's files to the current time?

Navigate to the folder in question, let's say, ~/Documents/myfiles.

$ cd ~/Documents/myfiles

Then do:

$ touch *

This will change the modification time to whenever you executed that command.

Obviously you can make this more specific depending on your use case, e.g.

$ touch *.doc

will only alter the modification time for files with the string '.doc' in their name.

0
source

Debian - LAMP Install

That command creates an empty file called "info.php". The next step is probably to edit the file, and add something like this to it:

<?php phpinfo();

What this does is allow you to see all information about your Apache/PHP installation through your browser, usually to see if you have all the PHP libraries you need.

When you have done installing, you should delete "info.php".

0
source

time stamp XXXX s in the future issue - touch command (Linux)

It did not work because you changed the timestamp of the archive, not of the files it contains. If you run stat on the tar.gz file you will find that the time was changed correctly. touch cannot access the files stored within the archive until you extract them so they were left unchanged.

In any case, this should not be a problem, just untar the archive, then change the timestamp of the files:

mkdir foo
mv openssl-1.0.1e.tar.gz foo/
cd foo/
tar xvvzf openssl-1.0.1e.tar.gz
find . -exec touch -am '{}' \;

0
source

Recursively touching directories' last modified datetime as the same datetime of the last modified file inside

Maybe something like this:

find . -type d -print0 | while read -r -d '' dir; do file="$(find "$dir" -maxdepth 1 -type f  -printf '%T+ %p\n' | sort -r | head -1 | cut -d' ' -f2-)";if [ -n "$file" ]; then touch "$dir" -mr "$file"; fi; done

Explanation:

To pass modification date from one file to another we have to run:

touch file1 -mr file2

First we have to find subdirectories:

find . -type d -print0 | while read -r -d '' dir; do echo "$dir"; done

In this case -exec option would get too complex so I use while-read approach. You need to make sure to pipe the output from find with NUL as record separator, and tell read to split on that (-d '').

To find files with last modification date I can use:

find ./  -maxdepth 1 -type f  -printf '%T+ %p\n' | sort -r | head -1 | cut -d' ' -f2-

Combining it:

find . -mindepth 1  -type d -print0 | while read -r -d '' dir; do file="$(find "$dir" -maxdepth 1 -type f  -printf '%T+ %p\n' | sort -r | head -1 | cut -d' ' -f2-)";echo "$dir <- $file"; done

Finally, adding touch:

find . -mindepth 1  -type d -print0 | while read -r -d '' dir; do file="$(find "$dir" -maxdepth 1 -type f  -printf '%T+ %p\n' | sort -r | head -1 | cut -d' ' -f2-)";touch "$dir" -mr "$file"; done

I use -mindepth option here because I launched this command from directory containing dir_a which does not have any file to read date from. To eliminate this problem I can use if-else to ensure i do not try to read time from non existing file:

find . -type d -print0 | while read -r -d '' dir; do file="$(find "$dir" -maxdepth 1 -type f  -printf '%T+ %p\n' | sort -r | head -1 | cut -d' ' -f2-)";if [ -n "$file" ]; then touch "$dir" -mr "$file"; fi; done

0
source

Linux weird problem touch : command not found?

Try the following command:

type touch

It may tell you that the touch command is at /usr/bin/touch and if so:

/usr/bin/touch ...

0
source

How do I add permissions to my tomcat.sh?

The simple answer to this is probably that you need to start the Tomcat service as root. Try sudo tomcat start instead (assuming that tomcat start is correct); that will run the starter process as root.

It's either that, or you aren't executing what you think you are. Remember that in Linux, you must give the full name of the file you want to execute; tomcat and tomcat.sh are distinctly different. This is because unlike on Windows, file extensions in Linux (and other Unixes) are essentially devoid of meaning to the OS.

description

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.

copyright

Copyright © 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

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.

reporting bugs

Report touch bugs to bug-coreutils[:at:]gnu[:dot:]org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
Report touch translation bugs to <http://translationproject.org/team/>


see also

The full documentation for touch is maintained as a Texinfo manual. If the info and touch programs are properly installed at your site, the command

info coreutils 'touch invocation'

should give you access to the complete manual.


author

Written by Paul Rubin, Arnold Robbins, Jim Kingdon, David MacKenzie, and Randy Smith.

How can this site be more helpful to YOU ?


give  feedback