If I want to make the contents of file2
match the contents of file1
, I could obviously just run cp file1 file2
.
However, if I want to preserve everything about file2
except the contents—owner, permissions, extended attributes, ACLs, hard links, etc., etc., then I wouldn't want to run cp
.* In that case I just want to plop the contents of file1
into file2
.
It seems like the following would do it:
< file1 > file2
But it doesn't work. file2
is truncated to nothing and not written to. However,
cat < file1 > file2
does work.
It surprised me that the first version doesn't work.
Is the second version a UUOC? Is there a way to do this without invoking a command, merely by using redirections?
Note: I'm aware that UUOC is more of a pedantic point than a true anti-pattern.
*As tniles09 discovered, cp
will in fact work in this case.