Optional Topics
File and Directory Compression
Compression in Linux typically involves packing collections of files into an archive
using the tar
command, which gets its name from tape archive. Files or directories
can be packed into a single tar file, as well as compressed further either the -z
option to tar or other programs. The -c
flag is used to create an archive and the -x
flag is for
extracting an archive. The -v
option enables verbose
output, and -f
specifies to store as an archive file. By
default, directories are added recursively, unless otherwise specified. Here
is an example of creating an archive or tar file:
$ tar -cvf my_archive.tar file1 file2 file3
file1
file2
file3
And to extract the same archive (not verbose):
$ tar -xf my_archive.tar
A program commonly used along with tar
is
gzip
, which creates
archives with the extension .gz
. A file can be compressed simply
by gzip file
(with an added -r
for a directory) or
a .tar.gz
file can be created (or extracted) by adding the -z
option to a tar
command. For example, the same command from above
to extract with gzip
:
$ tar -xzf my_archive.tar.gz
Another common extension for a gzipped tar file is .tgz.
For more on compression, see this detailed article.
Symbolic Links
Symbolic links are a special type of file which refer to another file in the filesystem. The symbolic link contains the location of the target file. Symbolic links are used to provide pointers to files in more than one place and can be used to facilitate program execution, make navigating on the system easier, and are frequently used to manage system library versions. To make a symbolic link:
$ ln -s data/file/thats/far/away righthere
See the man pages for ln
for more information on linking files.
Root and Sudo
The root user on any system is the administrative account with the highest level of permissions and access. This account is sometimes referred to as the superuser. By default, most Linux systems have a single root account when installed and user accounts have to be set up. The root account has a UID of 0, and the system will treat any user with a UID of 0 as root.
If you have access to a root account on any Linux system, best practice is to
only use this account when the privileges are needed to perform your
work (such as installing packages), and to use a user account for all of your
other work. Note that the root directory
is not the home directory
of the root user, but rather the root of the filesystem. The home directory
of the root user is actually located at /root
.
The program sudo allows users to run commands with the equivalent privileges
of another user. The default privileges selected are the root user's, but any
user can be selected. A user with sudo privileges can run commands with root
privileges without logging in as root (must enter user's password) by putting
sudo
in front the command. The first user account created on some
Linux distributions is given sudo privileges by default, but most distributions
require you to specifically give sudo privileges to a user. This is typically
done by editing the /etc/sudoers
file (requires either root or
sudo access), or running a command like usermod
.
Package Managers
The root user and any user with sudo privileges have full access to the features of a package manager. In short, packages are archives of software and associated data, and a package manager is used to install, uninstall, and manage packages on a system. They are used in the shell or through a GUI, and have varying features. Most Linux distributions have a default package manager installed with the system. Some common package managers available are:
-
APT, which includes:
- apt
- aptitude
- apt-get
apt
; see this article for a detailed explanation. - Synaptic - a GUI for APT
- dpkg
- yum
- pacman
Commands for these package managers can be found in their supporting documentation or via the man pages. Note that on a managed resource, the availability of user software is often managed through the Module Utility.
Mounting Storage Volumes or Devices
The mount
command can be used to attach the filesystem of another
device at a specified place in the directory tree for easy read/write access.
mount
with no arguments is useful for seeing what devices are mounted.
Typically, you must specify the
type
of the filesystem, name of the
device,
and the path to where you want to mount it:
mount -t [type] [device] [path]
Use the umount
command to unmount a device's filesystem. It has
similar options to mount
, and both commands have thorough man pages.
Another way to mount a device is to use
fstab
, which
automates the process. Network shares can be mounted as well, so long as
appropriate credentials are supplied to connect.