Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 that it changes timestamps in spite of -f.

So, I want to know what -f stands for, or what it does.

share|improve this question
2  
I assume that -f as option is just ignored. Maybe mangled through the argument parser and that's it. – Thomas Mar 20 at 11:17
1  
(ignored) means that the flag is ignored, not the command. – QPaysTaxes Mar 21 at 21:09
up vote 45 down vote accepted

For GNU utilities, the full documentation is in the info page, where you can read:

-f
Ignored; for compatibility with BSD versions of `touch'.

See historic BSD man pages for touch, where -f was to force the touch.

If you look at the source of those old BSDs, there was no utimes() system call, so touch would open the file in read+write mode, read one byte, seek back and write it again so as to update the last access and last modification time.

Obviously, you needed both read and write permissions (touch would avoid trying to do that if access(W_OK|R_OK) returned false). -f tried to work around that by temporarily changing the permissions temporarily to 0666!

0666 means read and write permission to everybody. It had to be that as otherwise (like with a more restrictive permission such as 0600 that still would have permitted the touch) that could mean during that short window, processes that would otherwise have read or write permission to the file couldn't any more, breaking functionality.

That means however that processes that would not otherwise have access to the file now have a short opportunity to open it, breaking security.

That's not a very sensible thing to do. Modern touch implementations don't do that. Since then, the utime() system call has been introduced, allowing changing modification and access time separately without having to mingle with the content of the files (which means it also works with non-regular files) and only needs write access for that.

GNU touch still doesn't fail if passed the -f option, but just ignores the flag. That way, scripts written for those old versions of BSD don't fail when ported to GNU systems. Not much relevant nowadays.

share|improve this answer
3  
According to developer.apple.com/library/mac/documentation/Darwin/Reference/… -f still functions in Mac OS X. (But no doubt there are at least 57 different ways of performing the same functionality "better," using the GUI!) – alephzero Mar 20 at 19:49
19  
Using the GUI isn't neccesarily "better". The point of using scripts is automating stuff, which includes ensuring your script runs unmodified on as many unixy dialects as possible, or at least on most dialects you're likely to encounter, and this is where these old, deprecated compatibility issues become a concern. – Guntram Blohm Mar 20 at 21:19
    
@alephzero That's because the version in OS X is the BSD version, which GNU is maintaining compatibiility with. – Barmar Mar 23 at 17:30

-f does nothing. It's kept for historic compatibility (with BSD touch according to info touch), so that applications that expect it to exist don't pass it and get back an error message saying it doesn't exist. Assuming that this is GNU coreutils, you can see in the source that this just does a break out of the option processing switch without doing anything.

As an ignored option, -f is present from the very first version of the GNU touch command added in 1992 (see diff). It seems that, at least in FreeBSD v9, -f "attempt[s] to force the update, even if the file permissions do not currently permit it" (as found by Sukminder, thanks).

share|improve this answer
2  
info page says Ignored; for compatibility with BSD versions of `touch'. – heemayl Mar 20 at 11:19
    
@heemayl Except for I couldn't find a BSD that seems to ship with an "-f" argument to touch, so it must be quite old. – Chris Down Mar 20 at 11:21
    
Hmm.. I've just checked Coreutils manual, which say: "Ignored; for compatibility with BSD versions of touch. " – Pandya Mar 20 at 11:22
3  
-f is/was used to try to force update even if file permissions did to permit it on BSD. Not in V10, but v9 : freebsd.org/cgi/… (of FreeBSD at least). – Runium Mar 20 at 11:22
    
@sukminder Ace, thanks! I'll add your information into the answer. – Chris Down Mar 20 at 11:25

Whenever you see "option X is ignored" in --help output or a manpage, that means: the program accepts option X — you do not get a syntax error — but it doesn't have any effect. The program does the same thing it would have done in the absence of the option.

As the other answers demonstrate, this is done for backward compatibility. An option used to have some effect, whatever it did is no longer useful, and doing the same thing regardless of the option is the right compatibility behavior.

share|improve this answer

When looking at the comment in the historic source code, line 22:

  22   -f                     (ignored)\n\

the -f option was intended to be ignored since the initial release by Jim Meyering.

And the switch statement to handle options has an explicit case (lines 150/151) to do nothing:

 150         case 'f':
 151           break;

It is remarkable what motivated the following authors since 1992 to keep this option ignored. Maybe there's a usage scenario which requires the option -f and otherwise breaks?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.