SM1:
Open-source Operating Systems |
ASIX/DAW/DAM-1
|
Task sm1act02: Basic command-line utilities.
The Linux directory tree |
26-09-2025 |
Task sm1act02: The Linux directory tree. Basic
command-line utilities.
GENERAL CONDITIONS
1- Deadline: 5-10-2025.
2- Upload your
videoclip to the
Moodle of your group and seminar with the following file name:
- ASIX1: asix1_surname1_name_sm1act02.mp4
- DAW1: daw1_surname1_name_sm1act02.mp4
where surname1 is your real first surname and name
is your real name.
3- Make
this report individually.
DOCUMENTATION
1- The Linux directory tree structure. Important files and
their paths
Read the following link:
https://www.howtogeek.com/117435/htg-explains-the-linux-directory-structure-explained/
At the moment, you should pay special attention to the following
directories (or folders):
a) /
|
d) /home
|
g) /usr/bin
|
b) /bin
|
e) /root
|
h) /usr/sbin
|
c) /etc
|
f) /sbin
|
|
But in the future we will pay special attention to /boot,
/dev, proc, mnt and /var directories as
well.
2- ls
a) The
ls command-line utility
lists directory (folder) contents.
b) Examples:
1) ls
--> Lists the contents of the present directory.
2) ls
-ls --> Lists the contents of the present directory
and extra information about each file or directory (owner,
size, permissions,.....)
3) If 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.
4) If you want to list information about an specific
folder but not about its contents you have to add the
option -d. For instance:
ls -ls -d
/home or also ls -lsd /home
5) If you want to show
hidden files or directories inside a directory, you have to
add the option -a. For instance:
ls -a /etc/skel --> Lists hidden
files inside /etc/skel
3-
cat
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.
4- cd
a) Description:
The cd command-line
utility changes the current working directory to a new working
directory.
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 and
special characters:
cd .
--> 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
directory".
cd ~ --> Changes to
the user's personal directory which is "/home/username". The "~" indicates the user's
personal directory.
cd -
--> Changes to the previous directory. The "-" indicates the previous
directory
5-
Special character * (asterisk)
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
prov*.
b) Examples:
dacomo@inf1-dacomo:~>ls
(with no *)
amemo mem memalx
memo memo.0612 memoa
memoalx.0620 memoalx.keep
memorandum
memosally sallymemo
typescript user.memo
It shows all files in the working directory
dacomo@inf1-dacomo:~>ls
memo*
memo memo.0612
memoa memoalx.0620
memoalx.keep memorandum
memosally
It shows all files in the working directory whose name
begin with the string memo
dacomo@inf1-dacomo:~>ls
*mo
amemo memo sallymemo
user.memo
It shows all files in the working directory whose name
end with the string mo
dacomo@inf1-dacomo:~>ls
*alx*
memalx memoalx.0620 memoalx.keep
It shows all files in the working directory whose name
contain the string alx
dacomo@inf1-dacomo:~>ls
*.*
memo.0612
memoalx.0620 memoalx.keep
user.memo
It shows all files in the working directory
whose name contains one or more extensions
dacomo@inf1-dacomo:~>ls
!(*.*)
amemo
mem memalx memo memoa memorandum
memosally sallymemo typescript
It shows all files in the working directory
whose name does not contain any extension. The special
character ! means: the opposite of, reverse,
negate, logical operator NOT.
6- Special character ~)
a) The ~ character means "personal folder". For instance,
if your user is called dacomo then ~ = /home/dacomo
b) You can combine ~ with a lot of commands on
Linux. For instance, if
your user is called dacomo then:
cd ~ => cd
/home/dacomo
ls ~ => ls
/home/dacomo
7- cp
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.
c) Examples:
cp /var/log/messages
/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.
cp
/var/log/messages /media/usb/messages.20131110 -->
/var/log/messages
will be copied in the directory /media/usb. The name of the new file will messages.20131110.
cp
/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 ~.
8- mv
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
old_name new_name
d) Note 3: You can
use mv to move a
directory --> mv
existing_directory new_directory
9- mkdir
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.
c) Examples:
mkdir
test00 -> Creates a new directory called test00 as a child of the
current working directory.
mkdir
/home/etpclot/test01 -> Creates a new directory
called test00 as a child
of the /home/etpclot
directory.
d) Note: you can use .,..,- and ~.
10- rm
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
/home/usuari/INDEX.gz.
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 . .. - ~
e) Note 2: rm !(filename) removes all
files with the only exception of filename. For instance, if
you run rm !(ex01.c), every file in the directory
is removed with the
only exception of ex01.c. The special character ! means: the
opposite of, reverse, negate, logical operator NOT.
11- gzip
a)Description: The gzip command-line utility compresses or expand
(uncompress) files. A file compressed with gzip is marked by a .gz filename extension.
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 running
the command, the original file will be replaced with a new
file called INDEX.gz.
c) Synopsis 2: gzip -d
file_name.gz where file_name is the name of the
file that will be expanded (uncompressed). Example: gzip -d
/home/etpclot/INDEX.gz.After
running 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. Option -l lists
the following fields: size of the
compressed file, size of the
uncompressed file, compress ratio and uncompressed
name.
12- tar
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) Examples:
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
TODO.txt
tar cf test_c.tar
test*.c --> Creating a new file test.tar that packs .c
files
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
13-
wget
a) Description: It
is a command-line utility for non-interactive download of
files from the Web.
b) Synopsis: wget URL where
URL is the web address of any resource on internet or
the LAN.
c) Example:
wget http://www.collados.org/asix1/sm1/sm1act00.pdf
--> Download sm1act00.pdf
14- which
a) Description: which shows where the
binary file (also called executable) of any command/program that
has been installed on your file system
b) Synopsis: which
command_name, where command_name
is the name of a program or command-line utility.
c) Example: which geany
15- find
a) Description: The
find command-line searches files (or directories)
in a directory tree.
b) Synopsis: find
<starting-point> -name <file
o directory name> 2> /dev/null where <starting-point> is a directory that is the search
starting point.
c)
Examples:
find /etc -name
sources.list 2> /dev/null
--> It finds where a
file called sources.list is stored in
/etc.
find
/boot/grub -name
*.conf 2> /dev/null ->
It finds where
files with extension .conf are stored
in /boot/grub.
find
/usr/lib/modules
-name
host
2>
/dev/null ->
It finds where files
with basename host
are stored in /usr/lib/modules.
BEFORE STARTING
1-
Enable Audio Input and
Output on your virtual
machine.
2- Boot
your virtual
machine
3-
Install Kazam
4- With
the help of Kazam
installed
on your Linux
machine,
make a video
clip with
audio, where
we can see and
hear (in
english, of
course) how
you solve the
questions in
the practical
part.
5- Video
clips made
with another
program and
installed on a
diferent
operating
system will
get a maximum
mark on 7.
PRACTICAL EXERCISE
VERY IMPORTANT - 1:
You can not answer any question as a root user. You can
only answer the questions of this exercise as a standard
user!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
VERY IMPORTANT - 2:
Video clips made with another program and
installed on a different operating system will get a
maximum mark of 7!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1- Create 3 new directories in your personal directory: task,
temp and help.
List the contents of your personal directory, showing additional relevant
information about them (owner, permissions, size, creation date,
etc...) and showing hidden an unhidden files.
2- Change to /usr/share/info directory. Copy gnupg.info.gz
and find.info.gz into the directory temp created
inside your personal folder in question 1. List the
contents of temp.
3- Move find.info.gz
inside temp to the directory task created
in question 1. Change
to task. Check the size of just
the find.info.gz
file. Uncompress find.info.gz.
Check the name and size of the new
file created after expanding find.info.gz.
Check
that find.info.gz
does not exist any
longer. Why?.
4- Change the name of the file gnupg.info.gz
inside the
directory temp to sm1act2q4.gz. List
only sm1act2q4.gz and additional information about it (owner,
permissions, size, creation date, etc...) .
5- Remove the directories temp and help
that you created in question 1. List the contents of your
personal directory.
6- Documents is a directory created during the
installation process inside your personal directory. Copy task
to Documents . List the contents of
Documents.
7- Remove find.info.gz
inside task. Afterwards, remove task.
List
the contents of
Documents.
8- Show a list (displaying
relevant information) of:
a) All files in /bin containingstarting
with ntfs.
b) All files
in /etc ending
with .conf.
c) A
list of files in the /etc/ssh directory
with no extension.
9- Change to /usr/share/info
directory. Move
a file called nano.info.gz inside your
personal directory. Can you move nano.info.gz
inside your personal
directory?.
Why?.
10-
Create a
new directory called tmp in your
personal directory. Copy all
files in the /usr/bin directory that begin with the
character "z" to tmp.
List the
contents of tmp.
11- Change to tmp.
Pack all files inside the tmp
directory in a new file called zpack.tar.
Afterwards, compress zpack.tar.
Finally, with the only exception of
zpak.tar, remove all files
in tmp.
12-
Create a
directory
called average
in
your personal
directory.
Change to average.
Download http://www.collados.org/asix1/sm1/downloads/average.tar.gz
with wget.
13-
Uncompress
average.tar.gz.
After
that,
unpack average.tar.
Afterwards,
list the
contents of
the average
directory.
Finally, show
the contents
of average.c
and README
using cat.
14-
Find:
a)
Directory
where the
binary file of
gzip
has been
stored.
b)
Directories
where
files with the
extension
.cnf are
stored
c)