Questions tagged [touch]

touch is a command line utility to change file timestamps.

131 questions
84
votes
15 answers

What are the legitimate uses of the `touch` command?

What's the point of the touch command? I know I can create empty files with it, but so is also the case with echo -n. Otherwise, why would someone need to change the timestamps of a file? Unless to create the false impression about the age of a…
Quora Feans
  • 3,806
  • 7
  • 29
  • 46
69
votes
1 answer

How to create a file and parent directories in one command?

Is there a flag/option for touch, mkdir, >, or some other command that will allow me to create a file and any non-existent parent directories at the same time? For instance, let's say I'm in an empty folder. Now I can create parent directories if…
Jeff Puckett
  • 859
  • 1
  • 8
  • 12
55
votes
11 answers

Use of touch and vi?

Is there a benefit of creating a file with touch prior to edit.. like: touch foo vi foo versus getting it to editor straight-away? Like: vi foo I see quite a few tutorials using the former (touch then vi).
Fawix
  • 779
  • 2
  • 8
  • 14
38
votes
4 answers

touch: cannot touch file: No such file or directory

I am getting the error: touch: cannot touch `/opt/tsrm/compliance/cme/log/20121207.log`: No such file or directory on the touch command: touch $LOGFILE I also checked the link: touch: cannot touch `foo': No such file or directory, But I didn't…
Swagatika
  • 863
  • 3
  • 11
  • 18
34
votes
4 answers

When creating an empty file, why might one prefer 'touch file' over ': >> file'?

Never realized that you could do this until just now: : >> file It seems to be functionally similar to: touch file Is there a reason why most resources seem to prefer touch over this shell builtin?
Harold Fischer
  • 1,914
  • 1
  • 16
  • 29
29
votes
4 answers

touch: cannot touch `foo': No such file or directory

What could cause touch to fail with this error message? touch: cannot touch `foo': No such file or directory Note that an error due to incorrect permissions looks different: touch: cannot touch `foo': Permission denied
Lorin Hochstein
  • 8,077
  • 17
  • 50
  • 56
24
votes
1 answer

What happens if we use touch command while the file already exists

I already have a file named param.txt with some data on it. If I run touch param.txt in the same folder will my data get lost?
Rajesh
  • 249
  • 1
  • 2
  • 3
24
votes
4 answers

What is the use of the -f option for `touch`?

From man touch: -f (ignored) But I don't get what is meant by ignored. I've tried following: $ ls -l file -rw-rw-r-- 1 pandya pandya 0 Mar 20 16:17 file $ touch -f file $ ls -l file -rw-rw-r-- 1 pandya pandya 0 Mar 20 16:18 file And noticed…
Pandya
  • 23,898
  • 29
  • 92
  • 144
23
votes
2 answers

How to set file permissions with touch command

It seems that whenever I create a file with touch the permissions are set to: -rw-r--r--. Is there some way that I can configure the permissions with touch or does this have to be done after with a different command?
chackerian
  • 341
  • 1
  • 2
  • 7
22
votes
10 answers

How do I change folder timestamps recursively to the newest file?

I was wondering if anyone knows how to change the timestamps of folders recursively based on the latest timestamp found of the files in that folder. So for example: jon@UbuntuPanther:/media/media/MP3s/Foo Fighters/(1997-05-20) The Colour and The…
MonkeyWrench32
  • 353
  • 1
  • 2
  • 6
19
votes
6 answers

touch all folders in a directory

I am trying to update the timestamps of all folders in the cwd using this: for file in `ls`; do touch $file; done But it doesn't seem to work. Any ideas why?
javamonkey79
  • 369
  • 2
  • 3
  • 11
17
votes
3 answers

How do I set a file's mtime in epoch format?

I know how to get a file's mtime in epoch format: stat --format=%Y But I have not been able to figure out how to set a file's mtime in epoch format. The touch(1) man page appears to only accept a "timestamp" value (more-or-less fixed format…
eil
  • 363
  • 1
  • 3
  • 9
13
votes
2 answers

Why does touch create new files?

I am aware that the touch command is used to update the date of last modification on a file. It is also used to create a new file if requested file does not exist on file system. Since touch (as it's name implies), should just update last mod date,…
Alex McCourt
  • 149
  • 1
  • 3
12
votes
4 answers

touch: cannot touch ‘test’: Permission denied

I am trying to create a file in a directory but I am getting: `touch`: cannot touch ‘test’: Permission denied Here are my commands: [user@xxx api]$ ls -l total 184 ... drwxrwxr-x 2 root root 4096 2016-04-12 14:38 public .. [user@xxx api]$ cd…
Edgaras Karka
  • 2,447
  • 5
  • 15
  • 14
11
votes
2 answers

What does 'touch' stand for?

My question is not so much a question of computer science as it is a question of etymology. The command touch changes file access and modification times. What does 'touch' stand for?
Remi.b
  • 1,125
  • 2
  • 11
  • 18
1
2 3
8 9