SM1: Open-source Operating Systems ASIX/DAW/DAM-1
Task sm1act02: Basic command-line utilities. The Linux directory tree 23-09-2024


Task sm1act02: The Linux directory tree. Basic command-line utilities.


GENERAL CONDITIONS

1-
Deadline: 6-10-2024.

2-
Send your report attached to an e-mail with the following specifications:
     a) E-mail address:
cf(at)collados.org or jordi.binefa(at)fje.edu depending on who is your teacher
     b) File Name:
        b.1)
ASIX1: asix1_surname_name_sm1act02.pdf and asix1_surname_name_sm1act02.odt
        b.2) DAW1: daw1_surname_name_sm1act02.pdf
and daw1_surname_name_sm1act02.odt
    
c) Subject:
       c.1)
ASIX1: asix1_surname_name_sm1act02
       c.2) DAW1: daw1_surname_name_sm1act02

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




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 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. 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.

PRACTICAL EXERCISE


VERY IMPORTANT: You can not answer any question as a root user. You can only answer the questions of this exercise as a standard user!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

1- Answer the following questions:
a) Where is the personal folder of your standard user in the linux directory tree?:
b)
Where is the personal folder of root user in the linux directory tree?:
c) How is called the main directory of the linux directory tree?:
d
) Which are the folders where you can find the system administrator (or root) binaries (applications, command,...)?:
e) Which are the folders where you can find binaries used by standard users?:

2- Change to the  /usr/share/grub directory using a single command. List the directory contents showing additional relevant information about the them (owner, permissions, size, creation date, etc...).

3-
Go back to your personal directory using a single command. List your hidden and unhidden files and folders, showing additional relevant information about the them (owner, permissions, size, creation date, etc...).

4-
Create 3 new directories in your personal folder: tasktemp and help. Show the contents of your personal folder.

5-
Change to /usr/share/info directory. Copy gnupg.info.gz and find.info.gz to ~/temp.
List the ~/temp directory contents. 

6-
Move
~/temp/find.info.gz  to ~/task. Change to ~/task. Check
~/task/find.info.gz file size. Expand the file. Check  the new file size.

7-
Copy ~/temp/gnupg.info.gz to ~/help. Change the name of
~/help/gnupg.info.gz to ~/help/gnupginf.gzList the ~/help directory contents.

8-
Remove gnupg.info.gz from ~/temp. Copy ~/help to ~/temp.
List the ~/temp directory contents.

9-
Remove the directories ~/temp and ~/task.

10-
S
how a list (displaying relevant information) of:
    a) All files in /bin containing "dt".   
    b)
All files in /etc ending with ".conf".
    c)
All files in /usr/lib/NetworkManager starting with "nm-".
    d) A list of files in the /etc/ssh directory with no extension.
    e)
A list of files in the /boot/grub directory
whose name contains one or more extensions.
 

11- Copy /usr/share/info/nano.info.gz in your personal folder with the help of the special character ~. Change to your personal folder
with the help of the special character ~. Show the contents of your personal folder (hidden and not hidden) with the help of ~.

12- Run a command to check only  the size of
nano.info.gz. Extract the contents of nano.info.gz. Check the size of the extracted file nano.info. Check that nano.info.gz does not exist any longer.
 
13- Create a new directory called  ~/tmp. Copy all files in the /usr/bin directory that begin with the character "z" to ~/tmp. List the contents of ~/tmp.

14- 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 with the help of !.

15- Create a new directory called  ~/tmpl. Copy all files in the /usr/bin directory that begin with the characters "xd" to ~/tmpl.  Pack and compress the directory ~/tmpl  in a file called tmpl.tar.gz. Afterwards, remove ~/tmpl. Run a command to check the size only of the directory ~/tmpl.tar.gz.

16- Create a folder called ~/average. Change to ~/average. Download http://www.collados.org/asix1/sm1/downloads/average.tar.gz with wget.

17-
Extract and unpack 
average.tar.gz. Remove average.tar. List the contents of ~/average. Show the contents of average.c and README using cat.

18- Find:
    a) Directories where the binary file of gzip, gcc and geany have been stored. Please note that
gzip, gcc and geany are commands/programs.
    b) Directories where a file called  fstab (with no extension) is stored.
    c) Directories where  files with the extension .cnf are stored
    d)
Directories where  files with the basename hosts are stored