name
=
instruction
. The string
name
can then be used in place of the instruction from the command line. If the
instruction contains spaces, you must enclose it in single quote marks. The alias
exists for the duration of the current Bash session so you might move the definition
into your .bashrc file.
• apropos—Find instructions whose descriptions match the given string.
• arch—Output the architecture (processor type) of the computer.
• bash—Start a new bash session. Once in this session, any definitions of your previous
bash session are “hidden” unless they were exported. To leave this bash session, use
exit.
• cat—Concatenate the file(s). By default, output is sent to the terminal window but this
is often used with redirection to create new files. Using
cat
<<
string
>
file-
name
allows you to input text from the keyboard and store the result in the new file
filename
.
• echo—Output instruction to output literal strings and the values of variables. Echo
will be of more use in scripts (see Chapter 7).
• exit—Used to exit a bash session. If there was no previous bash session, this will close
the terminal window.
The Bash Shell
◾
67
• export—Used to export a variable into the environment. This can be used from
within a script or so that a variable can be used in a new (or older) bash session.
• history—Output the last part of the history list.
• hostname—Output the computer’s host name.
• ls—Provide a listing of the contents of the specified directory, or if no directory is
specified, the current working directory.
• man—Display the given instruction’s man(ual) page.
• passwd—Allow the user to change passwords, or if specified with a username, allow
root to change the specified user’s password.
• pwd—Print the current working directory.
• source—Execute the given file by the current interpreter.
• unalias—Remove an alias from the environment.
• uname—Print the operating system name.
• wc—Perform a word count for the given textfile(s) which outputs the number of bytes
(characters), words and lines.
• who—List all logged in users and their login point (e.g., on console, remotely from
an IP address).
• whoami—Output the current user’s username.
REVIEW QUESTIONS
1. Why do we refer to the user’s environment as a shell?
2. What is the history of the Bash shell?
3. Given the following prompt, answer the questions below.
[zappaf@frenchie /etc]#
a. Who is logged in?
b. Is the user logged in as themself or root?
c. What is the current working directory?
d. What is the hostname?
4. What command would you use to determine your username?
5. What command would you use to find out your current working directory?
6. What command would you use to change your password?
7. What is the difference between the arch command and the uname command?
68
◾
Linux with Operating System Concepts
8. Assume that foxr is logged in to a Linux computer on console and user zappaf is
logged into the computer remotely from IP address 1.2.3.4. What would the com-
mand
who
show?
9. From your Bash shell, you type
bash
. After working for a while, you type
exit
.
What happens?
10. What is the difference between
ls -l
and
ls -L
?
11. What is the difference between
ls -a
and
ls -A
?
12. You want to perform a recursive listing using ls. What option(s) would you specify?
13. You type ls and you receive 3 columns worth of file names. You want to see the output
as a single column listing. What can you do?
14. What does the synopsis portion of a man page tell you? If you are not sure, try
man
ls
,
man mount,
and
man ip
as examples and see what you get.
15. You want to reexecute the last instruction you entered in your Bash session. Describe
three ways to do this.
16. Given the history list from Figure 2.3, what command is recalled with each of the
following?
a.
!!
b.
!5
c.
!ls
d.
!cd
e.
!c
17. What does
history -c
do?
18. Define a variable to store your first initial, your middle initial, and your last name.
Include proper spaces and punctuation.
19. Assume the variable AGE stores 21. What is the output for each of the following?
a.
echo AGE
b.
echo $AGE
c.
echo $age
d.
echo \$AGE
e.
echo $AGE\!
20. Provide an instruction to alter your prompt so that it displays the following
information:
The Bash Shell
◾
69
(time : instruction number) [username] prompt character as in
(10:04 am : 31) [foxr] $
21. Write the command to define as an alias … to move you up two directories.
22. Write the command to define as an alias
stuff
to perform a long listing of your
home directory.
23. Match the following command line editing function with the keystroke that provides it
a. Move the cursor to the end of the line
i. c
+
k
b. Move back one character
ii. c
+ _
c. Move forward one word
iii. c
+
e
d.
Delete
one
character
iv.
m
+
f
e. Retrieve the last instruction entered
v. c
+
b
f. Undo the last keystroke
vi. c
+
d
g. Delete all characters from here to the end of the line
vii. c
+
p
24. Provide an instruction to redirect the output of
ls -l
to the file
~/listing.txt
.
25. How does the operator
>>
differ from the operator
>
?
26. Explain why
wc
<
somefile
does not require the
<
operator.
27. What is the difference between
cat file1.txt file2.txt file3.txt
and
cat file1.txt file2.txt > file3.txt?
28. Provide an example of why you might use
<<
as a form of redirection.
29. The following instruction does not do what we expect in that we want to output the
word count for the items listed in the current directory. What does it do and how can
you fix it?
ls
>
wc
30. Name three compiled languages.
31. Name three interpreted languages.
32. Why is Bash an interpreted environment rather than a compiled one?
33. Explain the role of the following characters as used in Bash.
a. ~
b. !
c. –
d. *
71
C h a p t e r
3
Navigating the Linux
File System
T
his chapter’s learning objectives are
• To be able to utilize Linux file system commands cat, cd, cmp, comm, cp, diff, head,
join, less, ln, ls, more, mkdir, mv, paste, pwd, rm, rmdir, sort, tail, and wc
• To be able to navigate through the Linux file system using both absolute and relative
paths
• To understand the hierarchical layout of the Linux file system including the roles of
the top-level directories
• To be able to apply wildcards to simplify file commands
• To be able to use find to locate files
• To understand hard and soft links
• To understand the Linux permissions scheme, how to alter permissions using chmod
and how to convert permissions to their 3-digit value
• To understand the different types of storage devices and the advantages that the hard
disk has over the other forms
• To understand lossy versus lossless file compression
3.1 INTRODUCTION
The operating system is there to manage our computers for us. This leaves us free to run
applications without concern for how those applications are run. Aside from starting pro-
cesses and managing resources (e.g., connecting to a printer or network, adding hard disks,
etc.), the primary interaction that a user has with an operating system is in navigating
72
◾
Linux with Operating System Concepts
through the file system. It should be noted that the term file system has multiple meanings.
In this chapter, we generally mean the entire collection of storage devices that make up the
file space. In Chapter 10, we will see that the term file system also means the type of storage
used for a partition.
The file system is a logical way to describe the collection of storage devices available to
the computer. The primary storage device for any computer system is the internal hard
disk. There may be additional hard disks (internal or external) as well as mounted optical
disk, flash drive(s), networked drives (either optical or hard disk), and mounted magnetic
tape.
The word
logical
is used to denote the user’s view of the file system, which is a collection
of partitions, directories, and files. It is an abstraction or generalization over the physical
implementation of the file system, which consists of blocks, disk surfaces (tracks, sectors),
file pointers, and the mechanisms of a storage unit (read/write arm, spindle, etc.). It is far
easier for us to navigate a file system by using the abstract concepts of files, directories,
Do'stlaringiz bilan baham: |