A Linux shell provides a command line environment through which a user can interact with the kernel
The user provides the kernel with instructions using text-based commands
These commands are translated by the shell into something the kernel can comprehend, which are then executed by the kernel.
Built-in System Utilities
Linux built-in system utilities are programs that allow a user to perform tasks which involve complex actions
Utilities provide user interface functions that are basic to an operating system, but which are too complex to be built into the shell
Examples of utilities are programs that let us see the contents of a directory, create, edit, move, copy files and delete files and check the status of connected devices
Application Software and Utilities
These are not part of the operating system, but additional programs that are bundled with a Linux distribution, or available separately
These can range from additional or different versions of basic utilities, to full scale commercial applications
These include office productivity applications, web browsers, media players, text editors and third-party programming environments just to name a few
Linux CLI Shells
A shell is the interface between a Linux system and a user
It is used to invoke commands as required to perform specific tasks
It acts as an interpreter between the user and the protected Linux kernel
There are several shells available for Linux including bsh, ksh, tcsh, bash and others
In this unit, we will be using the bash shell
Command Line Interface
When accessing a Linux shell, you can either do this locally or remotely
Remote Terminal: Access the shell terminal of a Linux machine (server) across the internet.
Local Terminal: Access the shell terminal of the Linux machine (workstation) you are using.
The Terminal
Linux Command Basics
- To execute a command, enter its name, followed by required flag(s) and arguments into the command line
- Command flags allow you to change a command’s default operation
- Flag Conventions:
A single hyphen followed by one or more letters, e.g (“ls -l”), (“ls -la”)
Sometimes have double dashes followed by a keyword (“--help”)
All of a command’s flags can be found by consulting its man pages entry, i.e. man ls
The List (ls) Command
ls command example:
ls list all user files in the current working directory
ls -a list all files including hidden file beginning with a period “.”
ls -ld * List details about a directory and not its contents
ls -F Put an indicator character at the end of each name
ls –l Simple long listing
ls –lh Give human readable file sizes
ls –lS Sort files by file size
ls –lt Sort files by modification time
Linux File Systems
The Linux file system follows a hierarchical structure and is based on the Filesystem Hierarchy Standard (FHS), which defines the organisation and layout of directories in a Linux system
Data files are stored in directories (folders) that can be nested as deeply asrequired
There are many core directories that form an essential part of any Linux system, each of which Linux admins and developers need to be aware of
/bin (Binary):
The /bin directory contains essential executable files that are required for basic system functionality
These files are accessible to all users and are crucial for booting the system and performing essential system operations, including in single-user mode
/etc (Configuration):
The /etc directory stores system-wide configuration files for services, applications, and the overall system settings
Examples of files in /etc include passwd (user account information), hosts (network hostnames), and fstab (file system table)
/sbin (System Binary):
The /sbin directory holds system binaries that are essential for system administration and maintenance
These executables are typically used by the system administrator or root user for tasks like managing the network, configuring hardware, and performing system recovery operations
Regular users typically don't have direct access to these files
/var (Variable):
The /var directory stores variable data files that change during system operation and expected to grow over time, such as log files, spool files, temporary files, and databases
Examples of directories within /var include /var/log for system log files, /var/spool for print queues and mail spools, and /var/www for web server content.
/usr
The /usr directory contains various subdirectories that store user-related data and applications
It’s the largest directory in the Linux file system • The main subdirectories in /usr include:
/usr/bin contains non-essential command-line binaries for all users
/usr/sbin Similar to /sbin, it holds system administration binaries, but these are not crucial for the system's basic functionality
/usr/lib contains libraries that support the binaries in /usr/bin and /usr/sbin
/usr/local used for installing software manually by the system administrator, separate from the operating system's package manager
/usr/share contains architecture-independent data such as documentation, images, and common files shared across different applications
/dev (Devices):
The /dev directory contains device files that represent and provide access to physical and virtual devices connected to the system.
These device files allow user programs to interact with hardware devices and peripherals
For example, /dev/sda represents the first SCSI or SATA disk, and /dev/tty1 represents the first virtual console.
/proc:
/proc is a special directory in Linux providing a virtual file system interface to the kernel and its running processes
It does not represent physical files on disk, but rather, provides a dynamic view of the system's processes and kernel-related info
Each running process in Linux has a corresponding directory inside /proc, e.g. /proc/1234 represents the process with PID (Process Identifier) 1234.
Linux files are stored in a single rooted, hierarchical file system
Data files are stored in directories (folders)
Directories may be nested as deep as needed
Naming Files
Files are named by chaining directories from the root downwards to the containing directory and the file name itself
This is known as the pathname
Current Working Directory
One directory is designated the current working directory
If you omit the leading / then path name is relative to the current working directory
Use pwd to find out where you are
Special File Names
Some file names are special:
/ Represents the root directory
- this is not to be confused with the root user
. Represents the current directory
.. Represents the parent (previous) directory ~ represents the user’s home directory
Linux environment and path variables
Environment Variables:
Environment variables are global settings that control the function of the shell and other Linux programs. They are sometimes referred to global shell variables.
- Setting:
VAR=/home/fred/doc
export TERM=ansi
SYSTEMNAME=`uname -n`
Using Environment Variables:
echo $VAR
cd $VAR
cd $HOME
echo “You are running on $SYSTEMNAME”
Displaying - use the following commands:
set (displays local & env. Vars)
Export
Variables can be retrieved by a script or a program
PATH Environment Variable
Controls where commands are found
PATH is a list of directory pathnames separated by colons. For example: PATH=/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/home/scully/bin
If a command does not contain a slash, the shell tries finding the command in each directory in PATH. The first match is the command that will run
Linux File Permissions
- Linux provides three kinds of permissions:
Read (r) - users with read permission may read the file or list the directory
Write (w) - users with write permission may write to the file or new files to the directory
Execute (x) - users with execute permission may execute the file or lookup a specific file within a directory
- In Linux, file and directory permissions are managed through the concepts of owner, group, and others. These entities determine who can perform certain actions on a file or directory, such as reading, writing, or executing.
Comentarios