METACHARACTERS 101
A metacharacter is a character that has a special meaning, such as a
carat (^), dollar sign ($) or an asterisk (*) has special meaning to a
computer program, a shell interpreter, a regular expression engine,
etc.
Metacharacters Functions
$ Shell variable
~ Special home directory variable
& Background command execution
; Command termination
< << > >> Input/Output redirection
| Command piping
*?[] Shell wildcards
AUTO COMPLETION IN SHELL COMMANDS 102
Tab completion is a helpful feature in any command-line
environment.
This feature speeds up typing commands. Just hit Tab while typing a
command, and the shell environment will automatically complete or
suggest options.
Example: Let’s say you want to run the Apt package manager’s
commands. You can type apt- and press Tab twice to see a list of
commands beginning with apt-. To run one of the commands,
continue typing it and press Tab again - for example, you could type
apt-g, press Tab, and apt-get would appear.
ALIAS 103
Alias
shortcuts to commands stored in special variables that can be created and
viewed
User can give their own name to a command or sequence of commands
using the alias command
To create an alias to the command mkdir mydir1 mydir2 called makemyfolder:
alias makemyfolder="mkdir mydir1 mydir2“
Command to display BASH shell aliases:
alias
ALIAS (CONT.) 104
Example : To create an alias called cls: It will also named for clear. Therefore when
user type cls, it will clear the screen (same function as user use function clear).
alias cls=clear
MANUAL PAGES 105
Commonly referred to as man Code Functions
pages 1 Executable programs or shell commands
2
man pages are a System calls
user manual that is built by
default into 3 Library calls
most Linux distributions and other
Unix-like operating systems 4 Special files (usually devices, those found in
during installation /dev) and drivers
Simply type the man command 5 File formats and conventions
followed by a command name:
6 Games
$ man <command> man
7 Miscellaneous
Information about that Linux
command is displayed page-by- 8 System administrator commands
page on the terminal screen
All manual pages contain certain 9 Kernel routines
section numbers that describe the
category of the command in the Details can be find in :
manual page database https://man7.org/linux/man-pages/man7/man-pages.7.html
INFO PAGES & HELP FUNCTION 106
You can access GNU info pages by typing the info command
followed by the name of the command in question
$ info <command>
Example : $info mkdir
The info command returns an easy-to-read description of each
command and also contains links to other information pages
(called hyperlinks)
Functions that are built into the BASH shell itself:
$ <command> --help
Example : $mkdir --help
107
TOPIC 3:
LINUX FILESYSTEM
MANAGEMENT
This Photo by Unknown Author is licensed under
CC BY-NC
LEARNING OUTCOME 108
Identify Filesystem Hierarchy Standards (FHS) in Linux directory
structure
Define the Filesystem Hierarchy Standard (FHS)
State the Linux directories defined by the FHS
Show the relative and absolute pathnames
Show the Linux directory structure to view in Linux system
Identify the directory structure using file manager
View filenames and file types using file manager
Apply command cd and pwd
Apply command ls and file to view filename and file types
LEARNING OUTCOME 109
Use the wildcards to specify multiple filenames
Use cat, more, less, head and tail to display the
contents of the text files
Use command grep search for regular expressions in
file
Manipulate files and directories management in
Linux system
Explain the process to manage files and directory
using file manager
Create and delete file
Copy, rename and move files
Search file
LEARNING OUTCOME 110
Show command touch, cat and mkdir to create a
new files and directories
Show command rm, rmdir and rm –rf to remove
files and directories
Show command cp and mv to copy, rename and
move files and directories
Demonstrate command find and locate to search
files and directories.
LEARNING OUTCOME 111
Identify various type of graphical and text editors
Carry out graphical editor to create and modified file
Carry out text editor to create and modified file
Requirements
Computer (or VM) installed with Ubuntu Desktop
112
This Photo by Unknown Author is licensed under CC BY-SA-NC
FILESYSTEM HIERARCHY
STANDARD (FSH)
FILESYSTEM Filesystem generally is a layer which is under the 113
operating system that handles the positioning of your
data on the storage, without it; the system cannot
know which file starts from where and ends where.
The term filesystem has two meanings:
• The entire hierarchy of directories (also referred
to as the directory tree structure) that is used to
organize files on a computer system.
• The type of filesystem, that is, how the storage of
data (i.e., files, folders, etc.) is organized on a
computer disk or on a partition on a hard disk.
FILE HIERARCHY STANDARD (FHS) It is based on the older 114
standard FSSTND (Filesystem
Standard).
Filesystem Hierarchy Standard (FHS) defines a
standard set of directories for use by all Linux
systems, as well as the file and sub-directory
contents of each directory.
FHS gives Linux software developers the ability to
locate files on a Linux system regardless of the
distribution.
The FHS is maintained by the Linux Foundation
and available online at
https://refspecs.linuxfoundation.org/fhs.shtml
The tree of the Linux file system starts at the trunk or slash,
LINUX FILESYSTEM STRUCTURE indicated by a forward slash (/). 115
The "/" directory is also called the root directory or "the root" of the
file system.
Directories that are only one level below the root directory are
often preceded by a slash, e.g. /boot, /etc, /home.
- /directory in Windows similar with C:\
(windows OS being installed)
- Other partition D:\ for example will be
represented as another folder / on
Linux
COMMON LINUX DIRECTORIES
116
Linux Directories
COMMON LINUX DIRECTORIES
117
CONT...
/bin – Essential
User Binaries
COMMON LINUX DIRECTORIES 118
Directories Descriptions
/bin Essential User Binaries
/boot Static Boot Files
/dev Device Files
/etc Configuration files
/home Home Folders
/lib Essential Shared Libraries
/cdroom Historical Mount Point for CD-ROMs
LINUX DIRECTORIES 119
Directories Descriptions
/snap Snap Files
/media Removable Media
/mnt Temporary Mount Points
/opt Optional Packages
/proc Kernel & Process Files
/root Root Home Directory
/run Application State Files
/sbin System Administration Binaries
/srv Service Data
/tmp Temporary Files
/usr User Binaries & Read-Only Data
/var Variable Data Files
ABSOLUTE & RELATIVE PATHNAME Absolute pathname – refers to a specific file in ce1r2ta0in
location on a computer.
The path starts with a single slash (/), then the root of
the file tree is assumed as starting point.
/home/miasara/Pictures/images/lemon.png
Relative pathname – relative to the location of the file
that contains them.
The path without a slash at the beginning means that
the current directory is the assumed starting point.
images/lemon.png (where the current directory is
/home/miasara/Pictures/)
PATH COMPLETION 121
The TAB key can help you in typing a path without
errors.
For example:
a) typing cd /et
b) followed by the tab key
c) will expand the command line to cd /etc/
For example:
a) typing cd /Et
b) followed by the tab key
c) nothing will happen because you typed the wrong
path
122
This Photo by Unknown Author is licensed under CC BY-SA-NC
LINUX DIRECTORY
STRUCTURE
COMMON LINUX DIRECTORIES 123
Directories Functions
/bin Common programs, shared by the system, the system administrator and the
users
/boot
The startup files and the kernel, vmlinuz. In some recent distributions also
/dev grub data
Contains references to all the CPU peripheral hardware, which are
represented as files with special properties
/etc Contains most important system configuration files
/home
/lib Home directories of the common users
/cdrom Library files, includes files for all kinds of programs needed by the system
and the users
A temporary location for CD-ROMs inserted in the system. However, the
standard location for temporary media is inside the /media directory.
NAVIGATE THE DIRECTORY STRUCTURE 124
USING FILE MANAGER
VIEW FILENAMES AND FILE TYPES USING
FILE MANAGER 125
NAVIGATE THE DIRECTORY STRUCTURE 126
USING CD AND PWD
Command Description
pwd Print name of current/working directory
cd [directory] Change directory
cd or cd ~ Return back to your home directory
cd .. To go to the parent directory
cd - To go to the previous directory
ls List the current directory contents
ls -a [directory] With option -a; to show all files including the
hidden files
ls -l [directory]
With option -l; to list directory contents, use a
long listing format
VIEW FILENAMES AND FILE TYPES USING LS
AND FILE 127
Command Description
ls List the current directory contents
ls -a [directory] With option -a; to show all files including the
hidden files
ls -l [directory]
With option -l; to list directory contents, use a
ls -lh [directory] long listing format
ls –F [directory] To list directory contents with file sizes in a more
human readable format
ls –S [directory]
file [filename] To list directory contents, add one character of
*/=>@| to enteries
To list directory contents, short by file size
Determines the file type
FILE TYPES 128
The ls –F command appends a special character at the end of
each filename displayed to indicate the type of file.
Symbol Description
@
* A linked file
/ An executable file
= A subdirectory
| A socket
A named pipe
[none] No special character appended to them and could be
text files, binary data files, or special device files.
USING WILDCARDS TO SPECIFY 129
MULTIPLE FILENAMES
Wildcard Description
* Matches 0 or more characters in a filename
? Matches 1 character in a filename
[aegh] Matches 1 character in a filename – provided this character is
either an a, e, g, or h
[a-e] Matches 1 character in a filename – provided this character is
either an a, b, c, d, or e
[!a-e] Matches 1 character in a filename – provided this character is
NOT an a, b, c, d, or e
DISPLAY THE CONTENTS OF THE TEXT
FILES USING cat, more, less, head & tail 130
Command Description
Display the first ten lines of a file
head [filename] Display the first n lines of a file
head -n [filename] Display the last ten lines of a file
tail [filename] Allow to see the contents of the file page by page.
more [filename] Useful for displaying files that take up more than one
screen. Allows forward movement only. Use the
less [filename] spacebar to see the next page, or q to quit
cat [filename]
Similar to more. Allows backward movement in the
file as well as forward movement
To view a file's content. Not suitable for displaying
files that take up more than one screen
COMMON REGULAR EXPRESSIONS 131
Expression Description
* Matches 0 or more occurrences of the previous
character
.
[128] Matches 1 character of any type
Matches one character from the range specified
[^128] within the braces
^ Matches one character not from the range specified
within the braces
$
Matches the following characters if they are the first
characters on the line
Matches the previous characters if they are the last
characters on the line
EXTENDED REGULAR EXPRESSIONS USING 132
grep
Expression Description
? Matches 0 or 1 character
+ Matches 1 or more character
{3} Matches a specific number or range of the previous
(sun|moon) character
Matches either of two sets of characters
133
This Photo by Unknown Author is licensed under CC BY-SA-NC
FILES AND DIRECTORY
WORK WITH FILES AND DIRECTORIES
134
Command Description
mkdir [directory] Make directories. You have to give at least one
parameter to mkdir
mkdir -p Create parent directories as needed. Similar to mkdir
[parent_dir/child_dir] a a/b a/b/c
rmdir [directory] Remove an empty directories
rmdir -p Remove directory and its ancestors. Similar to rmdir
[parent_dir/child_dir] a/b/c a/b a
touch [file] Change file timestamps. Can be used to create an
empty file
cat > [filename] Create a new file with content
cat [filename]
Concatenate. View single content of given filename
cat file1 file2
View multiple files
Cat –n filename
View contents of a file preceding with line numbers
rm [file]
To remove a file
WORK WITH FILES AND DIRECTORIES (cont.) 135
Command Description
rm -i [file] Prompt before every removal
rm -rf [directory] Remove directories and their contents recursively
cp [source] [target] without prompt
cp -r To copy a file. The last argument (the target) must be
a directory
cp -p To copy complete directories. Forces recursive
mv [source] [target] copying of all files in all sub-directories
To preserve permissions and time stamps from source
files
To move (or rename) a file. The target can be a new
name of the file or the destination/directory
SEARCH FILES AND DIRECTORIES 136
find searches the directory structure recursively, starting
from a certain directory for files that meet a certain
criterion
slower but more versatile method for locating files on the
filesystem
locate looks in a built-in database, rather than the entire
filesystem
the database is indexed for fast searching, and it is updated
automatically
can update the database manually by running the updatedb
command
SEARCH FILES AND DIRECTORIES (CONT.) 137
Command Description
find [directory] -name [file] Find files in the directory
find [directory] -type Find files of the mentioned type file in
[file_format] -name [file] the directory. At the file format
parameter, f means file type, d means
locate [directory] [file] directory
Uses an index to locate files. Create
the index with the updated command
138
This Photo by Unknown Author is licensed under CC BY-SA
TEXT EDITORS
TEXT EDITOR 139
What is a Text Editor in Linux?
Text Editor also known as code editor.
Is an application designed for create and modify text
and coding (editing in HTML, CSS, JavaScript, PHP and
many other programming languages).
Editors features:
Syntax highlighting
Easy navigation
Customizable interfaces
Search and replace options
140
TEXT EDITORS
TYPES OF TEXT EDITOR
This Photo by Unknown Author is
licensed under CC BY
TEXT EDITOR 141
Two types of text editors :
Command-line text editors.
A good example is Vim, which gives you the option of jumping into
the editor from the command line. System admins will find this very
useful when editing configuration files.
Graphical user interface (GUI) text editors.
This type of text editor features a GUI but cannot be used from the
command line
142
EXAMPLE OF POPULAR TEXT EDITORS
https://phoenixnap.com/kb/best-linux-text-editors-for-coding
Text editor Description
vi The oldest and most popular visual text editors available for Linux
(known as vim or "vi improved")
nano It is used with many bootable Linux systems and other limited-
space Linux environments
emacs One of the most popular and powerful text editors used on Linux
Gedit
jed The GNOME text editor runs on the desktop
joe It is designed for use by programmers
Joe's Own Editor is a command-line text editor for Unix systems,
kate available under the GPL
KWrite KDE Advanced Text Editor is a programmer's text editor
mcedit
Nedit The default graphical text editor in the KDE desktop
Internal file editor of GNU Midnight Commander.
Nirvana editor, is a text editor and source code editor for the X
Window System
https://www.linuxtechi.com/top-10-text-editors-for-linux-desktop/
143
GRAPHICAL TEXT
EDITORS
144
GRAPHICAL TEXT
EDITUOBRUINNTSUTA2L0L.0E4D IN
145
GUI TEXT EDITOR GOT INTERFACE
TEXT EDITOR
LIBREOFFICE 146
LibreOffice includes several applications that make it the
most versatile Free and Open Source office suite on the
market: Writer (word processing), Calc (spreadsheets),
Impress (presentations), Draw (vector graphics and
flowcharts), Base (databases), and Math (formula
editing).
Installer :
https://www.libreoffice.org/download/download/
147
LIBREOFFICE
WRITER
This Photo by Unknown Author is licensed under CC BY-SA
LIBREOFFICE WRITER
148
INTERFACE
149
SUBLIME TEXT
Sublime Text stand out than other text editor in 150
Linux because its ability to make use of each
OS’ native functionalities. Sublime Text one of
the more resource-efficient options.
SUBLIME TEXT Pros: Sublime Text is highly customizable, both in appearance and in
functionality (using plugins). In addition to having many of the basic editor
features (like colored syntax and searchability), Sublime adds a Goto Anything
feature. You can search inside or outside the application or open and manipulate
files with a quick keystroke. It also allows multiple selections, so you can
highlight multiple lines and edit them all at once.
Cons: Sublime Text has a steep learning curve even though it’s designed to
simplify workflows. You can use it free of charge, but it has a very intrusive
popup system asking users to buy a license.