0% found this document useful (0 votes)
3 views

6 - Slides - Linux - Introduction to the command line

This document serves as an introduction to the command line interface (CLI) in Linux, detailing essential commands and their usage. It covers topics such as file handling, process management, and package installation, emphasizing the importance of practice and familiarity with command syntax. Additionally, it highlights the differences between normal and privileged commands, as well as the hierarchical structure of the UNIX file system.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

6 - Slides - Linux - Introduction to the command line

This document serves as an introduction to the command line interface (CLI) in Linux, detailing essential commands and their usage. It covers topics such as file handling, process management, and package installation, emphasizing the importance of practice and familiarity with command syntax. Additionally, it highlights the differences between normal and privileged commands, as well as the hierarchical structure of the UNIX file system.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

Introduction to the command line in Linux

Fulvio Risso
Politecnico di Torino
http://fulvio.frisso.net

1
Part I
Most significant LINUX commands

3
Introduction
◼ Why do we need to learn Linux CLI commands?
◼ #1: often we do not have access to a GUI (e.g., remote servers, embedded devices)
◼ #2: “scripting” allows automation (e.g., re-running the script multiple times), hence
allowing you to work faster
◼ Remember that Linux commands:
◼ Have been developed over a huge number of years, so they may not be so
“homogeneous” such as the GUI
◼ Are case-sensitive
◼ Example: “ls” is not equal to “LS”
◼ Warning #1: This set of slides is very limited (more pointers at the end of the
slides)
◼ Warning #2: studying is not enough, without a significant amount of practice!
◼ (Particularly because the CLI is not always so intuitive)

4
General format of UNIX commands
◼ A UNIX command line consists of the name of a UNIX command (actually the
”command” is the name of a built-in shell command, a system utility or an
application program) followed by its ”arguments” (options and the target filenames
and/or expressions). The general syntax for a UNIX command is:
command –options targets
E.g., “ls -la”, “cp –r source_folder destination_folder”, “rm –rf dest_folder”

◼ A command can be though of as a verb, options as an adverb and targets as the


direct objects of the verb. In the case that the user wishes to specify several
options, these need not always be listed separately (the options can sometimes be
listed altogether after a single dash)
◼ Usually, options are “order-independent” can be “compacted”
◼ Example: “ls –l –a” is equal to “ls –la” and “ls –al”

5
Normal vs. privileged commands (1)
◼ Some commands are available only if launched in privileged mode
◼ Also known as “root” or “privileged” commands
◼ To run a command in privileged mode, simply add “sudo” (i.e., “superuser do”)
before your command
◼ The system will ask you for the password (type the password of the current user), then it
will execute the desired command

In normal mode:

user@linux:~$ tcpdump
tcpdump: enp0s3: You don't have permission to capture on that device
(socket: Operation not permitted)

In privileged mode:

user@linux:~$ sudo tcpdump


[sudo] password for user:
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes

6
Normal vs. privileged commands (2)
◼ Hint #1: the current user can be determined by typing “whoami”
◼ Hint #2: the system stores the ‘root’ password for some time, so the next
commands with “sudo” are likely not to ask for the password anymore
◼ Hint #3: unfortunately, there is no clear error that says that the command needs
to be executed in privileged mode; different messaged are returned by different
applications in case you do not have the right set of privileges
◼ Hence, you need to read carefully the error message and, in case you feel is a permission
problem, try repeating the same command with “sudo” before

7
Getting help
◼ man (format and display the on-line manual pages)
◼ man ls
◼ man is the online UNIX user manual, and you can use it to get help with commands and
find out about what options are supported
◼ Alternative solution: Ask Google!
◼ A lot of people has troubles with Linux and ask for help on the Internet. If you have
patience, likely you can get your answer from Google.

8
Handling files and folders (a.k.a. directories) (1)
◼ Linux file system follows a “tree-based” approach
◼ pwd (print [current] working directory)
◼ pwd
◼ Displays the full absolute path to your current location in the file system
◼ ls (list directory)
◼ Lists the contents of a directory. If no target directory is given, then the contents of the
current working directory are displayed. Often is used in form “ls -la”, which shows all the
files with details (size, date, etc)

9
Handling files and folders (a.k.a. directories) (2)
◼ cd (change [current working] directory)
◼ cd path
◼ Changes your current working directory to path (which can be an absolute or a relative
path)
◼ Used without any target directory (i.e., just ‘cd’), it resets your current working directory
to your home directory (useful if you get lost).
◼ Special paths:
◼ “..” → the parent directory of the current directory
◼ “/” → the “root” directory (the beginning of the tree)
◼ The path can be the concatenation of different paths:

cd ..
cd myfolder ➔ cd ../myfolder

10
Creating/removing folders
◼ mkdir (make directory)
◼ mkdir directory
◼ Creates a subdirectory called directory in the current working directory
◼ You can only create subdirectories in a directory if you have “write” permission on that
directory
◼ rmdir (remove directory)
◼ rmdir directory
◼ Removes the subdirectory directory from the current working directory
◼ You can only remove subdirectories if they are completely empty

11
Copying, moving, removing files
◼ cp (copy) is used to make copies of files or entire directories
◼ To copy files, use: cp source-file(s) destination
◼ where source-file(s) and destination specify the source and destination of the copy respectively. To
copy entire directories (including their contents), use a recursive copy:
◼ cp -rd source-directory destination-directory
◼ mv (move)
◼ mv is used to rename files/directories and/or move them from one directory into another. Exactly one
source and one destination must be specified:
◼ mv source destination
◼ Can also be used to “rename” a file
◼ rm (remove/delete)
◼ rm myfile removes the specified files. Unlike other operating systems, it is almost impossible to
recover a deleted file unless you have a backup (no recycle bin!), so use this command with care
◼ rm can also be used to delete directories (along with all their contents, including any subdirectories
they contain). To do this, use the -r option.

12
Controlling the terminal (1)
◼ clear
◼ Cancels all the output present on the terminal and returns an empty terminal
◼ history
◼ Prints all the commands that you typed previously
◼ [ARROW UP] [ARROW DOWN]
◼ Recalls the commands that we typed previously
◼ Very useful if we need to type a command very similar to another one that we typed
recently, so that we can simply modify the previous command instead of typing again
everything from scratch
◼ CTRL+R
◼ It allows to search for a previous command, by matching what you are typing with
previous commands
◼ E.g., if you type “mo”, it may recall the command “mousepad” that you typed previously

13
Controlling the terminal (2)
◼ [TAB]
◼ The [TAB] keyboard key auto-completes the command in case you are going to type a
file/directory name
◼ You can start typing the command and the name of the folder ( e.g., “cd Doc”) and, as
soon as the command is no longer ambiguous, you can press [TAB]
◼ The shell will immediately expand your command (e.g., “cd Doc” + [TAB] → “cd
Documents”), so you do not have to type it in its entire form

14
Looking for a keyword in a file
◼ grep (globally search a regular expression and print)
◼ Searches a string in a set of files:
◼ grep [-options] pattern files
◼ E.g., “grep myword *” (search for all occurrences of “myword” in all the files present the
current directory)
◼ Options:
◼ -c counts lines which contain the pattern
◼ -i case insensitive
◼ -l shows only names of the files containing the pattern (usually also the line is shown)
◼ -n shows the line number
◼ -v shows only the lines not containing the pattern

15
Showing the content of a file
◼ cat
◼ Shows the content of a file
◼ E.g., “cat /etc/passwd”

◼ head
◼ Shows the first part (i.e., 10 lines) of the file, e.g., “head /etc/passwd”
◼ tail
◼ Shows the last part of the file (i.e., 10 lines) , e.g., “tail /etc/passwd”
◼ Suggestion: try to show the content of the “/var/log/syslog” file, which contains all
the important notifications coming from Linux (e.g., errors, etc)

16
Editing files
◼ There are several text-based file editors that can be used
◼ Linux nerds suggest “vi”, but it looks very primitive and difficult to use for unexperienced
users
◼ We suggest “nano”
◼ CTRL + O: save current file
◼ CTRL + X: save and exit
◼ ...

◼ GUI alternative: several programs may be available, depending on the desktop


version you have (e.g., kedit in KDE, gedit in GNOME, mousepad in XFCE, etc)

17
Starting processes on Linux
◼ Starting a process:
◼ Start with the name, e.g., “mousepad”
◼ It may require the full path in case the process is not in the PATH variable:
“/usr/bin/mousepad” (or…)
◼ What’s my PATH? Type “env”!
◼ (or…) the “./” before the executable name, which means “start from the current directory”
◼ Starting a process in “detached” way: previous command with “ &” at the end
◼ Stopping a process that is taking control of your terminal: type “CTRL+C” (using
the proper keys, not “C-T-R-L-+-C”!)

18
Controlling processes on Linux
◼ ps
◼ Provides a snapshot in time of the current set of processes active on a given system. The
ps command takes a large variety of options (man ps). By default, ps will only show
processes owned by the current user.
user@linux:~$ ps
PID TTY TIME CMD
3081 pts/0 00:00:00 bash
3552 pts/0 00:00:00 ps

◼ We see our bash session (our own process) and our “ps” command process
◼ kill
◼ Like the kill API function, allows us to send a signal to a process. We can also use it to list
the signals that are relevant for the given processor architecture with the “-l” option
◼ kill –s SIGKILL PID or kill -9 PID
◼ To send sigkill to the process PID.

19
Cascading commands
◼ Most commands can be cascaded, in a way that the output of the former becomes
the input of the latter
◼ This enables to create very small commands and connect them arbitrarily to create much
more complex commands
◼ Often, commands are connected thought the character “|” (“pipe”)
◼ Some very used examples
◼ “ps –ax” (may have a long output) → “ps -ax |more” (prints the output page after page)
◼ “ps –ax” → “ps -ax | grep gnome” (prints only the lines that contains “gnome”)
◼ Not very intuitive at the beginning, but very used (hence, very important)
in Linux!

20
Watch command
◼ Very useful to keep the system under control
◼ E.g., show something on screen periodically, e.g., to see if the content of a file changes
◼ Example: “watch command”
◼ Some very useful examples
◼ Show the first 15 lines of a file, every 2 second
◼ E.g., “watch head -n 15 file.txt”
◼ Show the last 15 lines of a file, every 2 second (very used to show if the content of a log
file changes)
◼ E.g., “sudo watch tail –n 15 /var/log/syslog”

21
Shell
◼ It provides a text-based interface (“Command Line Interface”, a.k.a. CLI)
◼ It allows communicating with the O.S.
◼ interactively
◼ by means of a script
◼ In Unix, the shell application is a normal user-level application, and it is not
integrated in the kernel
◼ Hence, you can have different shells, up to your choice
◼ E.g., “sh”, “bsh”, “bash”, etc
◼ Most common is “bash”
◼ Functions are not all the same: for example, “sh” does not support the autocompletion
through “[TAB]”

22
Executing shell
◼ Shell can be executed
◼ Automatically at login (as specified in /etc/passwd)
◼ From another shell (when the new shell exits the previous shell is operating again)
◼ To end a shell:
◼ exit
◼ EOF character (usually ^d)

23
Installing / upgrading packages in Ubuntu (2)
◼ Each Linux distribution has its own package manager, i.e., a tool that allows to
install/remove programs
◼ It often includes also a GUI component to simplify operations
◼ “apt” in Ubuntu
◼ E.g., “sudo apt install htop” installs the “htop” package
◼ E.g., “sudo apt install aisleriot” installs the “solitaire” game
◼ This is a nice feature of Linux, as many additional packages are available through
the package manager, which downloads them from a centralizer (and somehow
controlled) repository

24
Installing / upgrading packages in Ubuntu (2)
◼ To get the list of the most updated packages: “sudo apt update”
◼ To upgrade the currently installed packages with the most recent versions: “sudo
apt upgrade”
◼ Remember: having your system up-to-date (hence, running frequent software updates) is
one of the key ingredients to protect your system from security bugs
◼ In recent years, we have seen some distributions (e.g., Ubuntu) suggesting the use
of “snap” as package manager
◼ Functions and commands of snap are almost equal to apt
◼ Snap is based on containers, hence (1) apps require more disk, (2) it simplifies the
management of dependencies (libraries, etc), as everything is packed in the same snap

25
Part II
UNIX File System

26
UNIX file system
◼ Characteristics:
◼ hierarchical (father-son relationship)
◼ directory organization
◼ notation uniformity (disks, directories, files)
◼ no extensions and no versions
◼ hard link (same file with different names)
◼ soft link (a file pointing to another)
◼ protection

27
File system hierarchy
◼ Rather complex organization; details at:
◼ https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard

28
Linux Directory Structure (1)
◼ / – Root
◼ Every single file and directory starts from the root directory
◼ Only root user has write privilege under this directory
◼ Please note that ‘/root’ is the home directory of ‘root’ user, which is not same as ‘/’
◼ /bin – User Binaries
◼ Contains binary executables, such as most common Linux commands you need to use in
single-user mode [*]
◼ Commands used by all the users of the system are located here
◼ E.g., ‘ps’, ‘ls’, ‘ping’, ‘grep’, ‘cp’

[*] Single user mode is a mode in which a multiuser computer operating system boots into a single superuser. It is mainly used for
maintenance of multi-user environments such as network servers. Some tasks may require exclusive access to shared resources, for
example running fsck on a network share. This mode can also be used for security purposes - network services are not run,
eliminating the possibility of outside interference. On some systems a lost superuser password can be changed by switching to
single user mode, but not asking for the password in such circumstances is viewed as a security vulnerability.
https://en.wikipedia.org/wiki/Single_user_mode

29
Linux Directory Structure (2)
◼ /sbin – System Binaries
◼ Just like ‘/bin’, also ‘/sbin’ contains binary executables
◼ However, the Linux commands located under this directory are used typically by system
administrator, for system maintenance purposes
◼ For example: ‘ip’, ‘iptables’, ‘reboot’, ‘fdisk’, ‘ifconfig’
◼ /etc – Configuration Files
◼ Contains configuration files required by all programs
◼ This also contains startup and shutdown shell scripts used to start/stop individual
programs
◼ Examples:
◼ ‘/etc/resolv.conf’: address of the DNS server
◼ ‘/etc/hostname’: name of the current host
◼ If changed, your terminal will start showing the new name, such as ‘username@my-new-name:/$’

30
Linux Directory Structure (3)
◼ /dev – Device Files
◼ Contains device files, such as terminal devices, USB, or any device attached to the system
◼ For example: ‘/dev/tty1’, ‘/dev/usbmon0’
◼ Remember that programs perform I/O on physical devices in the same way as
reading/writing on a file
◼ /proc – Process Information
◼ This is a virtual filesystem that contains information (in text forma) about running
processes and system resources
◼ Examples:
◼ ‘/proc/{pid}’ directory contains information about the process with that particular PID
◼ ‘/proc/cpuinfo’ contains information about the CPU of the machine
◼ E.g., ‘cat /proc/cpuinfo’

31
Linux Directory Structure (4)
◼ /var – Variable Files
◼ Variable files, i.e., files whose content is expected to continually change during normal
operation of the system—such as logs, spool files, and temporary e-mail files
◼ Examples
◼ ‘/var/log’: System log files
◼ ‘/var/lib’: State information; persistent data modified by programs as they run, e.g.,
databases, packaging system metadata, etc.
◼ ‘/var/mail’: Emails
◼ ‘/var/spool’: Print queues
◼ ‘/var/lock’: Lock files
◼ ‘/var/tmp’: Temporary files to be preserved across reboot

32
Linux Directory Structure (5)
◼ /usr – User Programs
◼ Secondary hierarchy for read-only user data; contains binaries, libraries, documentation
for non-system programs (either installed by default by Linux, or installed at a later time
by each single user)
◼ Examples:
◼ ‘/usr/bin’: binary files for user programs, e.g., ‘gcc’, ‘time’, ‘clear’, ‘less’, ‘ssh’, ‘whereis’
◼ If you cannot find a user binary under ‘/bin’, look under ‘/usr/bin’

◼ ‘/usr/sbin’: binary files for system administrators, e.g., ‘cron’, ‘sshd’, ‘tcpdump’, ‘useradd’,
‘userdel’
◼ Usually require ‘sudo’ to be executed
◼ If you cannot find a system binary under /sbin, look under /usr/sbin

◼ ‘/usr/local’: user-installed programs. For example, when you install the Apache web server,
it goes under ‘/usr/local/apache2’

33
Linux Directory Structure (6)
◼ /tmp – Temporary Files
◼ Directory that contains temporary files created by system and users
◼ Files under this directory are deleted when system is rebooted
◼ /home – Home Directories
◼ Home directories for all users to store their personal files
◼ Examples
◼ ‘/home/john’
◼ ‘/home/student’

34
Linux Directory Structure (7)
◼ /boot – Boot Loader Files
◼ Contains boot loader related files
◼ Kernel ‘initrd’, ‘vmlinux’, ‘grub’ files are located under ‘/boot’
◼ For example: ‘initrd.img-2.6.32-24-generic’, ‘vmlinuz-2.6.32-24-generic’
◼ /lib – System Libraries
◼ Contains library files that support the binaries located under /bin and /sbin
◼ Libraries can be shared across multiple applications (such as “DLL” – “Dynamic Link
Libraries” in Windows); these have usually extension ‘.so’ (“shared object”), e.g.,
‘libncurses.so.5.7’
◼ /opt – Optional add-on applications
◼ Contains add-on applications (“opt” stands for optional) from individual vendors

35
Linux Directory Structure (8)
◼ /mnt – Mount Directory
◼ Temporary mount directory where system administrator can mount additional filesystems
(e.g., a shared directory available on another computer)
◼ /media – Removable Media Devices
◼ Temporary mount directory for removable devices, such as:
◼ ‘/media/cdrom’: CD-ROM
◼ ‘/media/cdrecorder’: for CD writer

◼ /srv – Service Data


◼ Contains site-specific data served by this system, such as data and scripts for web
servers, data offered by FTP servers; ‘srv’ stands for service

36
Linux Directory Structure: final comment
◼ Rather complex, due to the many changes that have been made over the year
◼ Not always obvious the differences between folders that look similar
◼ Some common question:
◼ Where is my executable?
◼ ‘/bin’, ‘/usr/bin’, ‘/usr/sbin’, ‘/usr/local/bin’, ‘/opt’, …
◼ What is the difference between ‘/media’ and ‘/mnt’?
◼ In the end, no clear answer; hence some parts of the Linux file system may be
quite confusing, and each application can make its own choices where to install its
components (binaries, libraries, config files, run-time data, etc)

37
Devices and files
◼ Physical devices (e.g., network card, keyboard, mouse, etc) are visible as files in
the /dev folder
◼ Users can use the above “files” to send/receive data on it
◼ Example
◼ cat /etc/passwd > /dev/null ➔ instead of showing the content of “/etc/passwd” file on
screen, it sends it on the /dev/null device, which “eats” all the data that comes to it (and
it does not show anything on screen)

38
File system hierarchy
◼ The list of files of a directory and of the subdirectories is called “.” (dot)
◼ The father of a directory is linked from “..” (dot dot)

39
Part III
Users, groups, permissions

40
Users and groups (1)
◼ Each user has its own identity
◼ Each process is associated to a given user
◼ Example: “ps –axu” ➔ “u” forces to print also the owner of each user
◼ Each user belongs to one or more groups
◼ E.g., group “students” that include many user accounts
◼ adduser
◼ Creates a new user: e.g., “adduser myname”
◼ By default, each user is created with a group that is equal to its user name
◼ deluser
◼ Removes an existing user: e.g. “deluser myname”

41
Users and groups (2)
◼ A group is useful to associate a given set of permissions to multiple users at once,
not just one each time (e.g., associate permissions to all members of the “student”
group, instead of giving permissions to “student1”, “student2”, …)
◼ Creating /deleting a group:
◼ addgroup: creates a new group
◼ delgroup: removes a group
◼ Associating a user to a secondary group:
◼ “sudo usermod -a -G groupname username”
◼ In Ubuntu, it may be very important to associate a user to the “sudoers” group
◼ This is mandatory if you want that the new user will have the permission to run
“privileged” commands, i.e., starting with “sudo”
◼ “sudo usermod -aG sudo username”

42
Users and groups (3)
◼ Showing users and groups
◼ Users: “cat /etc/passwd”
◼ Groups: “cat /etc/group”
◼ Impersonating a new user
◼ Two options:
◼ 1) use the “su” command: “su user” ➔ you become the new user
◼ 2) log-in as a new user: “login” ➔ then type the credentials of the new user

43
Additional considerations about users and groups
◼ Currently, groups in Linux are not very used
◼ Most of the time, when a user is created, a new group with the same name is created as
well
◼ So, it looks like each user belongs to a group, which has only that single user as member
◼ This does not prevent to make a more extensive usage of groups if needed (e.g., create a
group “students” and another group “professors” to avoid setting permissions individually
for each user)
◼ Why there are so many users in a fresh Linux install?
◼ Because the user/group model is how Linux handles permissions. So, users are used to
limit the permissions of specific applications (particularly, system applications such as the
desktop environment), in order to limit the possible damages created by that application
in case of bugs, misbehaviors, or security leaks (e.g., a security exploit taking the control
of a selected application from remote).

44
Permissions (on the file system)
◼ Each object (e.g., file) belongs to an owner (in the form userid:group)
◼ Visible as “bits” associated to files: e.g., “ls –la”

ttpu@ttpu-os-2020:~$ ls -l
total 28
drwxr-xr-x 2 ttpu ttpu 4096 Sep 7 08:28 Desktop
drwxr-xr-x 2 ttpu ttpu 4096 Aug 28 20:45 Documents
drwxr-xr-x 2 ttpu ttpu 4096 Aug 28 20:45 Downloads
drwxrwxr-x 4 ttpu ttpu 4096 Sep 7 08:30 projects
-rw-rw-r-- 1 ttpu ttpu 61 Aug 28 21:02 textfile.txt
“Directory” bit: if set,
the object is a folder
Group that owns the file

Three bits for the permissions User that owns the file
of the owner (user)

Three bits for the permissions of Three bits for the permissions of anybody else (neither
who belongs to the owner group owner user, nor it does belong to the owner group)

45
Permissions (on the file system)
◼ Three basic permissions:
◼ read (r): read
◼ write (w): write
◼ execute (x): execution or step into (for directories)
◼ Three user groups:
◼ user (u): owner
◼ group (g): group
◼ others (o): all the others
◼ ➔ total of 9 permissions per each object

46
Setting permissions
◼ Change owner: chown
◼ E.g., “sudo chown user2:group2 myfile.txt”

◼ Change permissions: chmod


◼ Setting all bits at once
◼ Each bit is in octal notation, without the first flag (the “d”)
◼ Example: “chmod 777 myfile.txt”: 777 ➔ 111 – 111 – 111 ➔ rwx , rwx, rwx
◼ Setting a selected bit
◼ Syntax: [u|g|o|a] [+|-] [r|w|x] → e.g., u+w, g-r, o+x, a+w, …
◼ “a” means “set for all (user, group, other)” ➔ “chmod a+w myfile.txt” set “writing”
permissions for the owner, the group owner, and others
◼ Example: “chmod g+w myfile.txt” (meaning: “+” add “w”rite permissions to “g”roup
members)

47
Part IV
Variables, scripting

48
Variables
◼ Linux allow to define arbitrary variables that can be used by executables
◼ Very much used in cloud computing, where an application needs to know some
parameters that depend on where it is currently running
◼ Environment variables: variables that are available system-wide and are
inherited by all spawned child processes and shells
◼ Shell variables: variables that apply only to the current shell instance. Each shell
such as zsh and bash, has its own set of internal shell variables

49
Variables: basic commands
◼ List of environment variables:
◼ printenv
Nice video tutorial for Linux variables:
◼ Set a new variable: “Linux for Programmers #8 - Environment
◼ MYFIRSTVAR="My first variable" Variables On Linux,”
https://youtu.be/paQQ5HCpaRc
◼ Print the above variable:
◼ echo $MYFIRSTVAR
◼ Transform this variable into an environment variable:
◼ export MYFIRSTVAR
◼ And now it can be shown with printenv
◼ Nice page if you want to know more: https://linuxize.com/post/how-to-set-and-
list-environment-variables-in-linux/

50
Introduction to Scripting
Nice video tutorial for Linux scripting:
◼ Capability to create a text file that (1) contains a list
“Linux For Programmers #11 - Shell
of bash commands and (2) it can be executed Scripts,”
https://youtu.be/EKAx918CP5g
File my_first_script.sh (e.g., create with “nano”)
#!/bin/bash First line, compulsory, which specifies which interpreter
# has to be used (e.g., bash, but also Python, etc)
echo "Showing the content of current folder"
ls –la
#
read -p "Press [Enter] key to continue..."
Commands we want to execute
#
echo "Showing current processes"
ps -ax

chmod +x my_first_script.sh Turn this file into an executable

Run the file (remember to start with "./“ because the


./my_first_script.sh current folder is not in the list of folders that contain
executable files (the list can be seen with “echo $PATH”)
51
Part V
Conclusions

52
Conclusions
◼ Linux is is a very complex, but very powerful system, thanks to its many
commands and the “concatenation” options
◼ Commands are often “elementary”, but the concatenation of many of them brings a lot of
power in your hands
◼ However, the Linux CLI is not really intuitive, hence it requires a lot of practice
◼ Next step is bash programming, which adds even more power in your hands

53
Additional pointers: books
◼ A very good suggested lecture is this (currently still in draft) book:
◼ “Linux command line for you and me” is a book for newcomers to command line
environment
◼ Online version: https://lym.readthedocs.io/en/latest/
◼ PDF version: https://buildmedia.readthedocs.org/media/pdf/lym/latest/lym.pdf

54
Additional pointers: videos
◼ Joseph Delgadillo, “The Complete Linux Course: Beginner to Power User!,” available
at https://youtu.be/wBp0Rb-ZJak (suggested till the section “Services”, time
2:59:20)
◼ Geek's Lesson, “Linux Command Line Full course: Beginners to Advance. Bash
Command Line Tutorials,” available at https://youtu.be/2PGnYjbYuUo
◼ Apparently more “boring”, but basic Linux commands are very well explained
◼ Tech with Jim, “Linux for programmers,” available at
https://youtube.com/playlist?list=PLzMcBGfZo4-nUIIMsz040W_X-03QH5c5h
◼ A list of small lectures (15-20 mins each) dedicated to the most important topics about
Linux concepts and commands.

55

You might also like