6

Why does tar cvpfz /tmp/backup.tgz . backup hidden files?

(Note ls . does not see the hidden files. Trivia: there are ways to see hidden files such as with ls -a but this is just trivia. The question pertains to a difference in the behaviour when similar behaviour might be expected.)

H2ONaCl
  • 9,693

2 Answers2

11

Quick answer: use ls -a to see the "hidden" files.

Long story: there's no such thing as a "hidden" file in UNIX/Linux, in the sense that the Linux kernel does not mark "hidden" files in any special way (as opposed, e.g., to what Windows does).

There is however a convention that file names starting with a dot character . are not displayed by ls unless the user explicitly asks for it (hence, the -a option). Since this was the convention adopted by the ls program (one of the first commands that existed in UNIX), it was followed by other file-display utilities, like Nautilus and the graphical file selection dialog.

On the other hand, since it's only a convention on displaying files, it does not affect other file-manipulating commands like tar.

1

ls (Short list) doesn't show hidden files.
ll (Long list, typically a shell alias to ls -alF) does.

Eliah Kagan
  • 117,780
RobinJ
  • 8,910
  • Please read the question. ll does not see hidden files. Try it. – H2ONaCl Oct 15 '11 at 11:06
  • Yeah it does. Anyway, it does backup hidden files simply because you order it to... man tar or tar --help. – RobinJ Oct 15 '11 at 11:13
  • @broiyan. ll isn't actually a program: it's a shell alias. Exactly what it's an alias too may differ. Try type ll to see what it's aliased to on your system. – TRiG Nov 09 '13 at 00:41