If you’ve ever used the command line in Linux, you’re probably familiar with the tar command. tar is a command-line utility that is used to create, manipulate, and extract files from archives. One thing you may have noticed about tar and other command line tools in Linux is that they often allow you to specify parameters without the – syntax commonly used in other systems. For example, in Linux, you can create a tar archive using the following command:
tar cf archive.tar file1.txt file2.txt
tar -cf archive.tar file1.txt file2.txt
In this example, tar
is used to create a new archive called archive.tar
. The
c
option specifies that we want to create a new archive, and f
specifies the
filename of the archive. We then list the files we want to include in the
archive.
But why is it possible to use parameters without the --
syntax in Linux
command line tools? The answer lies in the history of Linux and its roots in
Unix and the BSD operating system.
Before the development of Linux, Unix was the dominant operating system in the
world of computing. Many of the command-line tools used in Linux today,
including tar
, were originally developed for Unix. In Unix, command line tools
often used single-letter options to specify parameters, and these options could
be combined together to form complex commands.
The BSD operating system, which was developed at the University of California, Berkeley in the 1970s, was based on Unix and included many of the same command line tools. Because of this, BSD also used the single-letter option syntax in its command line tools.
When Linux was developed in the 1990s, its creators wanted to create an open-source operating system that was compatible with Unix. To achieve this, they borrowed many ideas and tools from Unix and BSD, including the single-letter option syntax.
So, when you use the tar
command in Linux and specify options like -c
or
-f
, you’re actually using a syntax that has its roots in the early days of
Unix and BSD.
Here are some more examples of using the tar
command in Linux without the --
syntax:
- Extracting files from an archive:
tar xf archive.tar tar -xf archive.tar
This command extracts all the files from the archive.tar
archive. The x
option specifies that we want to extract files, and f
specifies the filename
of the archive.
- Adding files to an existing archive:
tar rf archive.tar file3.txt tar -rf archive.tar file3.txt
In this example, we add a new file called file3.txt
to an existing
archive.tar
. The r
option specifies that we want to append files to the
archive, and f
specifies the filename of the archive.
- Listing the contents of an archive:
tar tf archive.tar tar -tf archive.tar
This command lists the contents of the archive.tar
archive. The t
option
specifies that we want to see the contents of the archive, and f
specifies the
filename of the archive.
In conclusion, the ability to specify parameters without the --
syntax in
Linux command line tools like tar
is a legacy of the early days of Unix and
the BSD operating system. Despite being over 40 years old, this syntax remains a
useful and efficient way to interact with the command line in Linux today.