Introduction to Operating Systems
|TU1: Installing, configuring and exploting a
|Practical Exercise 3: Running basic
command-line utilities. The linux directory tree
Exercise 3: Running basic command-line utilities. The
linux directory tree
interface to the on-line reference manuals. If you want to know
how a command works, you have to run the command: man command_name. For instance, if you
want to know how the tar command
works you have to run: man
tar, or if you want to know how the uname command works you have
to run: man uname.
1- Deadline: 28-10-2018.
2- Send your report as a PDF file attached to an e-mail with
the following specifications:
address: cf(at)collados.org or jordi.binefa(at)fje.edu
depending who is your teacher
b.1) ASIX1 (Catalan): asix1_surname_name_m01tu01pr3.pdf
b.2) DAW1 (English): daw1_surname_name_m01tu01pr3.pdf
c.1) ASIX1 (Catalan):
3- Make this report individually.
4- Left, right, top and bottom margins: 2cm.
5- Character format: a) Font: Arial, b) Size:
10, c) Questions typeface: Bold, d) Answers typeface: Regular
COMMAND-LINE UTILITIES AND THE LINUX
DIRECTORY TREE: DOCUMENTATION
1- The Linux directory structure. Important files and
their paths. Command tree
What is a directory?
is a directory tree?
c) Information about The
Linux directory structure and important files paths.
d) The command-line tree is a recursive directory listing that shows the
contents of a directory (including files and subdirectories) in
a tree-like format.
b) Some manuals have two
or more sections. If you are asked about what section you want to
read, like for instance after running man uname:
Man: find all matching manual pages (set
MAN_POSIXLY_CORRECT to avoid this)
* uname (1)
Man: Quina pągina de manual voleu?
You have to choose the number between brackets and press
enter. If you do not select any option, the default option
(option after * symbol) will be chosen.
c) Once your finished viewing a manual, you can
exit or close the manual by pressing
the q key
a) The ls command-line utility lists
directory (folder) contents.
--> Lists the contents of the present directory.
-ls --> Lists the contents of the present directory
and extra information about each file (owner, size,
you want to list the contents of any folder, you have to write its
path. For instance:
ls -ls / --> Lists the contents (and extra
informatiosn) of the / directory.
ls -ls /home --> Lists the
contents (and extra information) of the /home directory.
ls -ls /var/lib --> Lists the contents
(and extra informatiosn) of the /var/lib directory.
ls -a --> Lists hidden files
a) The cat command-line
displays the contents of a text file. For instance: cat /etc/resolv.conf
displays the contents of resolv.conf.
b) If a text is
longer than one screen, you can use the special character |
and the command more
that displays as much as can fit on the current screen and waits
for user input (enter for a new line or space bar for a new
screen) to advance. For instance: cat
/var/log/messages | more.
character * (asterisk)
The cd command-line
utility changes the current working directory to a new working
b) Synopsis: cd directory_name
where directory_name is the name of the new working directory.
c) Examples: cd /home, cd /var/log, .......
d) Special cases:
--> Changes to the
current working directory. The "."
character means "the current working directory".
cd .. --> Changes to the parent directory of the current
working directory. The ".."
character means "the parent directory of the current working
cd ~ --> Changes to
the user's personal directory which is "/home/username". The "~" indicates the user's
--> Changes to the previous directory. The "-" indicates the previous
a) The asterisk * character is a special
character that causes the shell to generate filenames. It matches
any number of characters in a filename. For instance, if you want
a list of files in a folder that begin with the string "prov" then you can run the
command: ls -ls
(it shows all files in the working directory that begin with the
etpclot@etpclot:~>ls -ls *mo
(it shows all files in the
working directory that end with the string mo)
etpclot@etpclot:~>ls -ls *alx*
(it shows all files in the
working directory that contain the string alx)
a) Description: The cp command-line utility copies
one or more files and directories to a destination directory.
b) Synopsis: cp source_file destination_file
where source_file is the
name of the file that cp will copy, and destination_file is the name
that cp assigns to the new copy of the file. By
default, the destination_file
will be equal to the source_file.
/media/usb/ --> A
file called messages in
the directory /var/log will
be copied in the directory /media/usb.
The name of the new file will be messages.
/var/log/messages /media/usb/messages.20131110 -->
will be copied in the directory /media/usb. The name of the new file will messages.20131110.
/var/log/* /media/usb --> All the files in
the directory /var/log
will be copied in the folder /media/usb.
d) Note: you can use .,..,- and ~.
a) Description: The mv command-line utility moves
one o more source files and directories to a destination
directory. The original files will be removed. Refers to cp for Synopsis and examples.
b) Note 1 : you can use
the following special characters: . .. - ~
c) Note 2: You can
use mv to rename a
file --> mv
d) Note 3: You can
use mv to move a
directory --> mv
a) Description: The
mkdir command-line utility
creates a new directory..
b) Synopsis: mkdir directory_name
where directory_name is the name of the new created directory.
test00 -> Creates a new directory called test00 as a child of the
current working directory.
/home/etpclot/test01 -> Creates a new directory
called test00 as a child
of the /home/etpclot
d) Note: you can use .,..,- and ~.
a) Description: The rm command-line utility remove
files or directories. By default it does not remove directories.
b) Synopsis 1: rm file_name where
file_name is the name of the file that will be removed. Example: rm
c) Synopsis 2: rm -r directory_name
where directory_name is the name of the directory that will be
removed. Example: rm -r /home/etpclot/test00.
d) Note 1 : you can use .,..,- and ~.
e) Note 2: rm !(filename) removes every
file but filename. For instance si you run rm !(ex01.c),
every file in the directory is removed but ex01.c.
a) Description: The whereis command-line utility
shows where the binary, source and manual page
files are for a command.
b) Synopis: whereis
command_name, where command_name
is the name of a command-line utiliy (for instance mkdir)
c) Example: whereis mkdir
d) Some useful options are:
-b: Searchs only for binaries.
Searchs only for manual sections.
only for sources.
a) Description: The
locate command-line utility finds (or locates) files by
b) Synopis: locate file_name, where file_name is
the name of a file to localte. Shows directories where
the file is stored.
c) Example 1: locate resolv.conf
--> Shows directories where any file with the string
"resolv.conf" in its name is stored
d) Example 2: locate
-b '\resolv.conf' -->
Shows directories where a file called "resolv.conf" is
a)Description: The gzip command-line utility compresses or expand
files. A file compressed with gzip
is marked by a .gz
b) Synopsis 1: gzip
file_name where file_name is the name of the file that
will be compressed. Example: gzip /home/etpclot/INDEX. After runing the
command, the original file will be replaced with a new file
c) Synopsis 2: gzip -d
file_name.gz where file_name is the name of the file
that will be expanded. Example: gzip -d /home/etpclot/INDEX.gz.After runing the command, the original file will be
replaced with a new file called INDEX.
d) Synopsis 3: gzip
-l file_name.gz where file_name is the
name of a compressed file. -l lists the following
fields: size of the
compressed file, size of the
uncompressed file and uncompressed name.
a) Description: The tar command-line
utility packs and
creates a new single file, which will be marked by a .tar filename extension,
from multiple files or directories hierarchies. The tar
comand-line utility can extract (unpack) files from a .tar file as well..
b) Synopsis 1: tar
cf filename.tar list_of_files
where filename.tar is the name of the .tar file that will be
created and list_of_files is a list of files (* can be used).
c) Synopsis 2: tar
xf filename.tar where filename.tar is the
name of the packed file that will be unpacked.
d) Synopsis 3: tar
cf filename.tar directory_name where filename.tar is the name of the .tar
file that will be created and
where directory_name is a directory that will be packed.
e) Synopsis 4: tar tf filename.tar shows the
contents of filename.tar.
f) Synopsis 5: tar rf filename.tar
new_file where new_file is the name of a file to be added
to an exisiting .tar file.
g) Synopsis 6: tar df
filename.tar old_file where old_file is the name of a file
to be removed from an exisiting .tar file.
tar cf test.tar
test00.c test01.c test02.c asm.hex
TODO.txt --> Creating a a new file test.tar
that packs test00.c
test01.c test02.c asm.hex and
tar cf test_c.tar
test*.c --> Creating a new file test.tar that packs .c
tar xf test.tar
--> Unpacking test.tar
tar cf home.tar /home
--> Creating a new file home.tar that packs the
content of /home
tar tf test.tar
Showing the contents of test.tar
tar rf test.tar test07.c
--> Adding test07.c to test.tar
--delete --file=test.tar test00.c -->
Removing test00.c from test.tar
15-nano: a text editor
a) Description: The nano
command_line utility is a small, free and friendly
plain text editor.
b) ctrl-o: Saving the current file
c) ctrl-x: Saving the
current file and exiting to the bash command-line interficie.
The passwd command-line
utility changes passwords for users and groups accounts.
a) While an administrator may change the password for any
account or group, a normal user is only allowed to change
the password for their own account.
b) If the password is accepted, passwd
will prompt again and compare the second entry against the
first. Both entries are require to match
in order for the password to be changed.
c) If an old password is present, the user is first
promted for it and the password is compared agaisnt the stored
one. After the user is authenticated, the user
is then prompted for a replacement password.
d) Care must be taken to not include special control
characters or characters, which are not available on all
Install tree on your system with the help of Synaptic.
Show a list of your personal directory in a tree-like format.
2- Change to the /usr/share/info directory
step by step going through the tree of files and directories.
3- Go back to your personal directory using a single
4- Change to the /usr/share/info
directory using a single command.
5- Go back to your
personal directory. List your hidden files,
showing extra information (owner, permissions, etc...).
6- Show to
the on-line reference manual for the command mkdir.
What is the porpouse of the -v argument?
6- Create a new
directory called job in
your personal folder. Create another directory in your
personal folder called tmp.
7- Change to /usr/share/info
directory. Copy grep.info.gz
and find.info.gz to
8- Could you copy grep.info.gz to /etc. What is
9- Move find.info.gz to ~/job. Check
the allocated size of this file. Expand the file. Check the
new allocated size of this file.
10- Copy grep.info.gz in ~/tmp to your folder and change
its name to test-HOWTO.gz.
11- Remove grep.info.gz from ~/tmp.
12- Remove the directories
~/tmp and ~/job.
13- Show all files in the /dev directory that contain
the string "sd" and "tty".
/usr/share/info/grep.info.gz to ~, changing
the name to INDEX.gz.Extract INDEx.gz. Display the
contents of the file INDEX.Where is INDEX.gz?
15- Create a new
directory called ~/temporal.
Copy all files in the /bin directory that begin with
the character "g" to ~/temporal.
Pack all files in the ~/temporal
directory in a new file called g_pack.tar.
16- With the
exception of g_pack.tar,
remove all files in
17- Compress g_pack.tar.
18- Create a new directory
called ~/temporalv1. Move ~/temporal/g_pack.tar.gz to ~/temporalv1.
19- Extract ~/temporalv1/g_pack.tar.gz. Unpack ~/temporalv1/g_pack.tar. Remove ~/temporalv1/g_pack.tar. List
all files in ~/temporalv1.
20- Change to your
directory. Pack ~/temporalv1
in a new file called
dir_temporalv1.tar. Compress dir_temporalv1.tar. Remove ~/temporalv1.
21- List all files
in your folder. Extract and unpack dir_temporalv1.tar.gz. Check if ~/temporalv1 exists
another time. Check all files in the
restored ~/temporalv1 directory.
22- Create a new directory
called ~/bin. Move ~/temporal to ~/bin changing its name to tmpv1.
are the binary code of gzip
and tar commands?.
24-Create a text
file in your personal folder using nano and write:
# Script scr01.sh
echo "Hello $USER"
ls -ls ~
Save the newly created text
file with the following specifications: a) File Name: script01.sh.
25- Show contents of script01.sh using cat.
26- Create a new directory
called ~/test. Change to the newly
created folder. Copy all files in /etc with the .conf
extension. Pack hdparm.conf, host.conf
and pam.conf in a new file called conf.tar.
Show the contents of conf.tar.
27- Add apg.conf to conf.tar. Show
the contents of conf.tar.
28- Remove host.conf from conf.tar.
Show the contents of conf.tar.
29- Compress conf.tar. List the size of the
compressed file, size of
the uncompressed file and
30- Locate the following files: fstab,
grub.cfg and stdin.
Change your password to fjeclot01. Logo out and check that
your new password works. (NOTE:
If your new and old passwords do not work then, follow these
steps: a) Select your virtual machine, b) Press
Ctrl (Right) + F1, c) Gain access to the system as a root
user, d) Change the user's password, e) Log out as
a root user, f) Press Ctrl(Right) + F7 or F8, g)
Gain access again as a normal user)