2023S2 - Ors216d Task V3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

PRACTICAL SETUP ASSUMPTIONS

A. You can perform the following tasks on Debian-based Linux running on:
a. Bare metal PC or
b. Virtualized environment (VirtualBox) or
B. On Cloud platform such as Google Shell terminal
A. Connect via your Gmail account:
https://shell.cloud.google.com/?show=ide%2Cterminal

LEARNING OUTCOME 2 THE COMMAND LINE


1.1. An Introduction to BASH

Explain prompt WORD1@WORD2:~$ -- discuss what


WORD1 mean, what WORD2 mean, what ~ mean and what $ mean!
How will you change each of the above?
Example:
You can change ~ to be a different value by moving to a different file system path –
e.g cd / OR cd .. or cd /etc or cd /mnt/ or cd ~/Downloads
NB: cd ~/Downloads will not run on Google Shell or emalabserv… Why?
Revise: Linux command format : command -option argument
Know that Linux commands can be executed in any of the options below…

command -option(s) argument(s)


Command without options/switches nor ls
arguments
Command with switches, without arguments ls -l
Command with both switches and argument ls -la /var
Command with argument, without switches mkdir ~/folder1
Command with both switches and argument mkdir -p ~/folder2/subfolder2
Command with switches and two arguments cp -rfv /etc/fstab ~/folder1
But…each command will tell you how it must be ran!
1.2. Getting help on Linux commands: man, info and –help
Without searching the Internet – you can get what each Linux command does, how
and which switches can be used for what and how should arguments be structured.

If the OPTION or ARGUMENTS are in [] it means they are MONDATORY…

e.g. its not mandatory to use switch for mkdir BUT mandatory to put argument

e.g. its not mandatory to use switch for cp BUT mandatory to name TWO arguments

Page 2 of 5 By Mafoko A’ Kanegelo Ruri TUT© 2023


now, enter man ls (it is lower case L not I or 1) and explain as I did above
From now on – use man OR info OR help (please- resist temptation to search the
Internet or books- get help about each of the following commands by using use man,
info or help from command line!)

1.3. Using history, auto-completion and bang feature


Get a history of all commands you have entered so far!
NB: To know other commands starting with ANY number of letters…type those letters and
press tab key!
we will later use the bang feature later!
1.4. Show System Name: uname
Use uname to get the following details about the Linux machine you are using:
✓ Get the Machine hostname,
✓ The kernel version, the Operating system name
✓ And all info at once!
✓ Now- check the information you can get by using hostnamectl command…
which other commands starts with hostnamectl ?
1.5. Who Is Logged In: who and w, finger
Find who else is connected to the same computer you are using!
1.6. Switch User: su vs sudo
Find out what this command does – but…. we may not be able to use it now!

File/Folder Management
1.7. Listing contents of a directory: ls
✓ Enter ls THEN ls –l ;THEN ls –la THEN ls –l /etc THEN ls –ld /etc
NB: Enter each command and press enter …see outputs…and only THEN…anter
the next command!
✓ Now – from the results- explain what the commands achieved!

1.8. Create a Directory: mkdir


✓ Create a folder named folder101, then use another command to create the
subfolder of folder101 named subdir101 (do not use cd command )
✓ Use one command (with some switches) to create a folder named folder201
and its subfolder named subdir201
1.9. Open or change directories: cd also use shortcuts (.), (..), (~)
1.10. Show Present Working Directory: pwd
✓ Show the full path you are working in now…
✓ Then enter cd /etc/apt … then show the full path you are working in now
✓ Then enter cd ~… then show the full path you are working in now
✓ Then enter cd /var/tmp/ … then show the full path you are working in now

Page 3 of 5 By Mafoko A’ Kanegelo Ruri TUT© 2023


✓ Then enter cd /home/username … then show the full path you are working in
now (NB: username is the username corresponding to WORD1 above!)
✓ Now enter cd /etc ; then pwd ; then cd $HOME
✓ Have you seen what cd, pwd do?
✓ Have you seen how ~ and /home/username and $HOME are related?

1.11. Listing contents of a file: cat


1.12. Listing contents of a file One Screen at a Time: more and less
1.13. Listing only those contents of a file you want: tail and head
1.14. Create a Files: touch (empty file) or redirection (having content)
✓ Create an empty file inside folder101 named file101.mp4
✓ Create a file having the history of all commands you entered so far
✓ Create a file whose contents is the contents of /etc folder
✓ Enter the command hostnamectl then re-enter it but now sent the output to a
file named pcinfo.txt
✓ Show the contents of pcinfo.txt on the screen.
✓ Enter the command id then, re-enter that command but now append the
output of id to pcinfo.txt file
✓ Via command, show the contents of /etc/passwd then re-show those contents
but now append then to the bottom of pcinfo.txt
✓ Show the contents of pcinfo.txt , one screen at a time
✓ Show only the first 5 lines within pcinfo.txt
✓ Show only the last 3 lines within pcinfo.txt file
1.15. Editing/modifying contents of a file with text editors: nano, vi/vim
✓ Use any command line text editor to put your surname, initials and student
number at the top of pcinfo.txt
✓ Use echo command to append any holly sentence in your mother tongue to the
file pcinfo.txt
✓ Use any command line text editor put the word ORS216D-TUT under the last
line of pcinfo.txt
1.16. Search contents of a file: grep
✓ Search the word nobody within the file pcinfo.txt
1.17. Copy Files and directories: cp
✓ Copy the file of /etc/fstab to subdir201
✓ Copy the file of /etc/fstab to subdir201 but now safe it as exfstab
✓ Copy the folder of subdir101 to subdir201
✓ Copy the contents of /etc/network to subdir201
Have for noticed that you had to use –r switch in the last copy, why?

Page 4 of 5 By Mafoko A’ Kanegelo Ruri TUT© 2023


1.18. Move Files and directories: mv
✓ Cut and paste (move) the folder subdir101 to folder201
✓ Cut and paste (move) the folder folder101 to folder201 but now safe it as
exfolder101
✓ Rename the folder subdir201 to subzonke201

1.19. Remove a Directory and files: rmdir or rm


✓ Delete folder exfolder101
✓ Delete the file exfstab
✓ Delete folder sunzonke201
Discuss how deleting the three resources differed!
Doing more with found files and storage
1.20. Multiple Commands: pipes(|) and ;
1.21. Create shortcuts to files/directories: ln
1.22. Find a File and directory: find & do something with found results –exec
✓ Find all files ending with .cfg that are within /etc folder, then copy them to
your home folder
1.23. Find a File and directory using metacharacters/wildcards: *, ?
✓ Use one command to create 200 folders whose name starts with dirfolderX
where X is a number
✓ Use one command to create 200 files whose name starts with dirfolderX.mp3
where X is a number
✓ Now remove only those files and folders whose name is has a number between
100 and 199
1.24. File Compression: zip/gzip & tar
1.25. Disk Free: df
1.26. Disk Utilization: du
1.27. Check RAM usage: free

Page 5 of 5 By Mafoko A’ Kanegelo Ruri TUT© 2023

You might also like