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 contentsowner, 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 > file2But it doesn't work.  file2 is truncated to nothing and not written to.  However,cat < file1 > file2does 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.
Is it a UUOC (useless use of cat) to redirect one file to another?
files;io redirection;file copy;cat
cat < file1 > file2 is not a UUOC. Classically, < and > do redirections which correspond to file descriptor duplications at the system level.File descriptor duplications by themselves dont do a thing (well, > redirections open with O_TRUNC, so to be accurate, output redirections do truncate the output file). Dont let the < > symbols confuse you. Redirections dont move datathey assign file descriptors to other file descriptors.In this case you open file1 and assign that file descriptor to file descriptor 0 (<file1 == 0<file1) and file2 and assign that file descriptor to file descriptor 1 (>file2 == 1>file2).Now that youve got two file descriptors, you need a process to shovel data between the twoand thats what cat is for.