The program
touch
can be used to update the modified
date and time to the moment
that touch is run. If the file doesn’t exist, touch will create an empty file that has the
modified and created timestamp set to the moment touch was executed.
Other file- and directory-related commands that will be really useful are ones related
to setting permissions and owners. Every file and directory gets a set of permissions,
as indicated previously, as well as having an owner and a group. To set permissions on
a file or directory, you use the
chmod
command, which can
take a numerical value for
each of the possible permissions. Three bits are used, each either on or off for
whether the permission is set or not. Since they are bits, we are talking about powers
of 2. It’s easiest to remember the powers of 2 as well as the order read, write, and exe‐
cute. If you read left to right as the people of most Western cultures do, you will think
about the most significant value being to the left. Since
we are talking about bits, we
have the powers of 2 with exponents 0–2. Read has the value of 2
2
, or 4. Write has the
value of 2
1
, or 2. Finally, execute has the value of 2
0
, or 1. As an example, if you want
to set both read and write permissions on a file, you would use 4 + 2, or 6. The bit
pattern would be 110, if it’s easier to see it that way.
There are three sets of permissions: owner, group, and world (everyone). When you
are
setting permissions, you specify a numeric value for each, meaning you have a
three-digit value. As an example, in order to set read, write, and execute for the
owner but just read for the group and everyone, you use
chmod 744 filename
, where
filename
is the name of the file you are setting permissions for. You could also just
specify the bit
you want either set or unset, if that’s easier. For example, you could use
chmod u+x filename
to add the executable bit for the owner.
The Linux filesystem is generally well-structured, so you can be sure of where to look
for files. However, in some cases, you may need to search for files. On Windows or
macOS, you may understand
how to look for files, as the necessary tools are embed‐
ded in the file managers. If you are working from the command line, you need to
know the means you can use to locate files. The first is
locate
, which relies on a system
database. The program
updatedb
will update that database, and when you use
locate
,
the system will query the database to find the location of the file.
If you
are looking for a program, you can use another utility. The program
which
will
tell you where the program is located. This may be useful if you have various loca‐
tions where executables are kept. The thing to note here is that
which
uses the PATH
variable in the user’s environment to search for the program. If the executable is
found in the PATH, the full path to the executable is displayed.
A more multipurpose program for location is
find
. While
find
has
a lot of capabilities,
a simple approach is to use something like
find / -name foo -print
. You don’t have to
provide the
-print
parameter, since printing the results is the default behavior; it’s just
how I learned how to run the command and it’s stayed with me. Using
find
, you spec‐
ify the path to search in.
find
performs a recursive search,
meaning it starts at the