1.1 - examining and navigating directories
as previously discussed, the LFS is made
up of nested directories, like folders-within-folders. users navigate through the LFS by moving up, down, and
laterally through the levels of directories. to do so, the user executes the cd
command, which stands for "change directory". though most directories have text-based names, there are 3 shorthand
names that act as placeholders to aid in navigation.
the first is "~", which stands in for the "/home" directory. executing cd ~
will change the
current working directory to /home.
the second is ".", which means "the current working directory". executing cd .
will have no
effect, as the current working directory will not change.
the third is ".." which means "the parent directory of the current working directory". executing
cd ..
will change the working directory to the parent directory of the current directory,
effectively moving the user "up a level".
to move into a directory within the current working directory ("down a level"), the user executes
cd directoryname
.
to examine the contents of a directory, the ls
command is used, which is a shortening of the
word "list". on its own, the command will list the contents of the current working directory, with no information other
than the filenames. however, there are multiple modifications that can be made:
ls -l
: long format. displays file type, permissions, owner, group, number of hard links, size,
and date-time of last modification.ls -a
: show all files, including hidden files.ls directoryfullpath
: list contents of a directory without having to be in that directory.1.2 - accessing and reading files
there are multiple ways to display the contents of a file in the linux command line. the first, and likely easiest to use, is
cat
, which is short for "concatenate". there are a few ways to use it:
cat filename
: outputs the contents of filename to the terminal.cat file1 file2 file3 ...
: outputs the contents of each file to the terminal in the same order they were specified in the command.cat filename > outputfile
: writes the contents of filename to outputfile.cat filename >> outputfile
: appends the contents of filename to the end of outputfile.
another method of reading files is the more
command. this command will output the contents of a file one page at a
time. between pages, the command waits for the user to prompt it to continue. because the command waits for user input, the user can also execute
certain commands at these breaks.
a similar command is less
, which is very similar to more
. the difference is that
less
allows the user to scroll backwards through the text. it pages the same way, though.
the page size used by both more
and less
is determined by the number of lines available
in the terminal, which is just another way to say it depends how big the terminal window is.
1.3 - filenames
in the LFS, the format of a filename can change how it behaves, and what must be done to access it.
filename
: a normal filename, which will be displayed in a directory normally..filename
: a hidden file, which will normally not be displayed. it can be shown by adding the-a
option tols
.file name
: this file will be displayed normally, but the name must be put in quotes to reference it in a command.file-name
: this file will be dsiplayed like any normal filename.-filename
: the filename must be preceded by "./" to reference it in a command. it is not recommended to begin filenames with "-".
hidden files play a big role in linux systems. not for security reasons, as it is trivial to expose them. however, many config files are hidden so they don't get in the way.
1.4 - file information and readability
certain file types and data types are classified as "human readable" or "machine readable". for example, text in a .txt file is "human readable", while binary data in an executable file is "machine readable".
the file
command can be used to gather useful information about the files in a directory.
file filename
: returns the file/data type of filename.file *
: returns the file/data type of all files in the current working directory.
1.5 - searching for files
if certain attributes of a file are known, then the find
command can be used to locate any file matching those specifications. the
command will search a specified directory, which need not be the current working directory. if no directory is specified, the current directory will be searched.
bear in mind that the command will return a "permission denied" error for every match it finds for which the user doesn't have sufficient permissions.
attributes searchable with find
include, but are not limited to: owner, group, size, and type.