6

I am new to Ubuntu and I am trying hard to understand the command line.

When I want to see the contents of a tar file I use:

tar tf tarfile.tar

But when I want to see a listing of all file if I use:

ls a filename

It says:

ls: cannot access a: No such file or directory

Why is that?

Why is the minus sign "-" required for one command and not for the other?

Dianne
  • 236
  • 1
  • 4
  • 1
    The title and question body don't match. The title asks why it's wrong to use `-t` with `tar` (A: It isn't; modern versions of `tar` accept `-t`). The question body asks the opposite (why it's wrong to omit the `-` for options to other programs). – jamesdlin Nov 26 '14 at 03:00
  • 1
    [Obligatory xkcd](http://xkcd.com/1168/). – Martin Schröder Nov 28 '14 at 10:09

1 Answers1

10

The tar command is one of the oldest commands in *nix. It was created long long ago to do tape archives where data was stored on tape drives.

When the utility was written, the current standard of putting a dash to indicate a parameter was not yet invented.

It is optional for tar, but mandatory for almost every other command.

Marianna
  • 304
  • 2
  • 7
  • [Here is a similar answer, for the same question.](http://unix.stackexchange.com/questions/13573/why-use-superflous-dash-to-pass-option-flags-to-tar) – Adam Nov 25 '14 at 23:07