Linux
Linux
Introduction
Kernel: The core of the Linux operating system, managing hardware and system
processes.
Shell: The interface that allows users to interact with the kernel through a command-line
interface (CLI) or a graphical user interface (GUI).
System Libraries: Essential for running applications, providing standard functions for
programs.
Linux Distributions
The Linux file system hierarchy is organized as an inverted tree with the root
directory / at the top. All other directories and files stem from this root. Here are
some key directories:
Basic Commands
Commonly used commands for file manipulation (cp, mv, rm), directory navigation (cd,
ls), and system information (uname, top).
Boot Loader files
Kernel initrd, vmlinux, memtest, efi, grub files are located under /boot
Example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic
basic system programs like ls, cp, ps, ls, cat, ping, grep etc. It’s typically
located at /bin.
Devices files- usb, cpu,bus, char,block, mqueque, net, pts, disk, fd, dri, bsg,
input, lightnvm, snd,shm, v4l, core, console.
/etc :
Host-specific system-wide configuration files.
Contains configuration files required by all programs.
This also contains startup and shutdown shell scripts used to start/stop
individual programs.
Example: /etc/resolv.conf, /etc/logrotate.conf.
The /etc directory in Linux is where system-wide configuration files are stored.
Here are some common files and subdirectories you might find there:
Within a Linux home directory, you’ll typically find several standard subdirectories
and files:
Software Management
Package managers and how they simplify software installation and updates.
Comparison of apt, yum, dnf, and pacman.
Networking
Shell Scripting
#!/bin/bash
# This is a comment
The most common wildcards are * for matching any number of characters, ? for
matching a single character, and [ ] for matching any one of the enclosed characters.
Logging in Linux involves two main types: kernel logging and user logging. Kernel
logging captures system-related messages, while user logging pertains to applications
and services running on the system. Logs are typically stored in the /var/log directory.
cd - Change directory.
touch - Create a new file.
mkdir - Create a new directory.
rm - Remove files or directories.
`cat` : In this we will print the context inside a text file on terminal.
3. Process Management:
4. Networking Commands:
Create a script that checks for system updates and applies them automatically.
Commands Description
Used to check whether the calling program has access to a specified file. It
access can be used to check whether a file exists or not
Used to turn on or turn off the process for accounting or change info
accton process accounting file
aclocal Used to automatically generate aclocal.m4 files from configure.in file
acpi Used to display the battery status and other ACPI information
Tests whether ACPI (Advanced Configuration and Power Interface)
acpi_available subsystem is available or not
It provides intelligent power management on a system and is used to notify
acpid the user-space programs about the ACPI events
addr2line Used to convert addresses into file names and line numbers
It is a Linux version of getty, which is a Unix program running on a host
computer that manages physical or virtual terminals to allow multi-user
agetty access
Instructs the shell to replace one string with another string while executing
alias the commands
It is a command-line mixer for ALSA(Advanced Linux Sound
amixer Architecture) sound-card driver
It is a command-line audio player for ALSA(Advanced Linux Sound
aplay Architecture) sound card drivers.
Used to play standard MIDI(Musical Instrument Digital Interface) files, by
sending the content of a MIDI file to an ALSA(Advanced Linux Sound
aplaymidi Architecture) MIDI port
It helps the user when they don’t remember the exact command but knows
apropos a few keywords related to the command that define its uses or functionality
Provides a high-level CLI (Command Line Interface) for the package
management system and is intended as an interface for the end user which
enables some options better suited for interactive usage by default
apt compared to more specialized APT tools like apt-cache and apt-get
apt-get It is a command-line tool which helps in handling packages in Linux
Opens up a highly built-in interface to interact with the package manager
aptitude of the machine
ar Used to create, modify and extract the files from the archives
arch Used to print the computer architecture
It manipulates the System’s ARP cache. It also allows a complete dump of
arp the ARP cache
aspell Used as a spell checker in Linux
atd It is a job scheduler daemon that runs jobs scheduled for later execution
atrm Used to remove the specified jobs. To remove a job, its job number is
passed in the command
atq It displays the list of pending jobs which are scheduled by the user
autoconf Used in Linux to generate configuration scripts
Used to create a template file of C “#define” or any other template header
autoheader for configure to use
Used for automatically generating Makefile.in files compliant with the set
automake GNU Coding Standards
autoreconf Used to create automatically buildable source code for Unix-like systems
autoupdate Used to update configure.in file in our Linux system to a newer Autoconf.
It is a scripting language used for manipulating data and generating
awk reports
banner Used to print the ASCII character string in large letter to standard output
It strips directory information and suffixes from file names i.e. it prints the file
basename
name NAME with any leading directory components removed
Used to read commands from standard input or a specified file and execute
batch them when system load levels permit i.e. when the load average drops below
1.5
A mail notification system for unix that notifies the user at the command line
biff
when new mail arrives and tells from whom it is
break Used to terminate the execution of for loop, while loop and until loop
Used to run a shell builtin, passing it arguments(args), and also to get the exit
builtin
status
bzgrep Used to search for a pattern or an expression but inside a bzip2-compressed file
bzless It does not have to read the entire input file before starting, so with a large file,
it starts up faster
Used as a filter for CRT viewing of bzip2 compressed files, which are saved
bzmore
with .bz2 suffix
case It is the best alternative when we had to use multiple if/elif on a single variable
Reads data from file and gives their content as output. It helps us to create,
cat
view, concatenate files
chage Used to view and change the user password expiry information
It is a file system command which is used for changing the attributes of a file in
chattr
a directory
It allows you to change a user‟s name and other details easily. chfn stands for
chfn
Change finger
chkconfig Used to list all available services and view or update their run level settings
cksum Used to display a CRC(Cyclic Redundancy Check) value, the byte size of the
file and the name of the file to standard output
Used to compare the two files byte by byte and helps you to find out whether
cmp
the two files are identical or not
It is used to filter out reverse line feeds. The col utility simply reads from the
col
standard input and writes to standard output
Used to format the text processor output so that it can be viewed on Cathode
colcrt
Ray Tube displays
Compares two sorted files line by line and write to standard output; the lines
comm
that are common and the lines that are unique
Used to reduce the file size. After compression, the file will be available with
compress
an added .Z extension
continue Used to skip the current iteration in for, while and until loop
cpio stands for “copy in, copy out“. It is used for processing the archive files
cpio
like *.cpio or *.tar. This command can copy files to and from archives
A list of commands that you want to run on a regular schedule, and also the
crontab
name of the command used to manage that list
csplit Used to split any file into many parts as required by the user
It allows quick access across the files (For example quickly seeing definition of
ctags
a function)
curl A tool to transfer data to or from a server, using any of the supported protocols
For cutting out the sections from each line of files and writing the result to
cut
standard output
Used to store the history of a file. Whenever a file gets corrupted or anything
cvs
goes wrong “cvs” help us to go back to the previous version and restore our file
Used to display the system date and time. It is also used to set date and time
date
of the system
Used to declare shell variables and functions, set their attributes and display
declare
their values
Used to display information related to file systems about total space and
df
available space
diff Used to display the differences in the files by comparing the files line by line
Used to remove the trailing forward slahes “/” from the NAME and prints the
dirname
remaining portion
dmesg Used to examine the kernel ring buffer and print the message buffer of kernel
Used when the user wants to retrieve system‟s hardware related information
dmidecode such as Processor, RAM(DIMMs), BIOS detail, etc. of Linux system in a
readable format
Used to return the Network Information System (NIS) domain name of the
domainname
host
dosfsck Diagnoses MS-DOS file system for problems and attempts to repair them
du Used to track the files and directories which are consuming excessive amount
of space on hard disk drive
Used to print the super block and blocks group information for the filesystem
dumpe2fs
present on device
Used for launching the ed text editor which is a line-based text editor with a
ed minimal interface which makes it less complex for working on text files i.e
creating, editing, displaying and manipulating files
It treats the pattern as an extended regular expression and prints out the lines that
egrep
match the pattern
It is a editor having simple user interface. Also, there is no insert mode in this
emacs
editor. It only have editing mode.
It is a text editor in Linux which is also termed as the line editor mode of the vi
ex
editor
Allows you to convert tabs into spaces in a file and when no file is specified it
expand
reads from standard input
This command or scripting language works with scripts that expect user inputs. It
expect
automates the task by providing inputs
It is bash shell BUILTINS commands, which means it is part of the shell. It marks
export
an environment variables to be exported to child-processes
factor Used to print the prime factors of the given numbers, either given from command
line or read from standard input
It scans the font directories and build font cache for applications which use
fc-cache
fontconfig for their font handling
It is used to list the available fonts and font styles. Using the format option, the list
fc-list
of all fonts can be filtered and sorted out
find Used to find files and directories and perform subsequent operations on them
It is a user information lookup command which gives details of all the users
finger
logged in.
It wraps each line in an input file to fit a specified width and prints it to the
fold
standard output
for Used to repeatedly execute a set of command for every element present in the list
Displays the total amount of free space available along with the amount of
free memory used and swap memory in the system, and also the buffers used by the
kernel
GNU Debugger tool helps to debug the programs written in C, C++, Ada,
gdb
Fortran, etc.
getent Used to get the entries in a number of important text files called databases
Searches a file for a particular pattern of characters, and displays all lines that
grep
contain that pattern
Groups are the collection of users. Groups make it easy to manage users with
groups
the same security and access privileges
It verifies the integrity of the groups information. It checks that all entries in
grpck
/etc/group and /etc/gshadow have the proper format and contain valid data
This command compresses files. Each single file is compressed into a single
gzip
file.
Used to instruct the hardware to stop all the CPU functions. Basically, it
halt
reboots or stops the system.
Used to get statistics about the hard disk, alter writing intervals, acoustic
hdparm
management, and DMA settings
Used to filter and display the specified files, or standard input in a human
hexdump
readable specified format
Used to obtain the DNS(Domain Name System) name and set the system‟s
hostname
hostname or NIS(Network Information System) domain name.
Provides a proper API used to control Linux system hostname and change its
hostnamectl
related settings
It is a command line utility that allows the user to interactively monitor the
htop
system‟s vital resources or server‟s processes in real time
hwclock Utility for accessing the hardware clock, also called Real Time Clock (RTC)
iconv Used to convert some text in one encoding into another encoding
Used to find out user and group names and numeric ID‟s (UID or group ID) of
id
the current user or any other user in the server
It basically brings the network interface up, allowing it to transmit and receive
ifup
data
Used for capturing a screenshot for any of the active pages we have and it gives
import
the output as an image file
Reads documentation in the info format. It will give detailed information for a
info
command when compared with the main page
iostat Used for monitoring system input/output statistics for devices and partitions
Used to display and monitor the disk IO usage details and even gets a table of
iotop
existing IO utilization by the process
iptables- It will save the current iptables rules in a user specified file, that can be used
save later when the user wants
Used to display the parameters, and the wireless statistics which are extracted
iwconfig
from /proc/net/wireless
It is a command line utility for joining lines of two files based on a key field
join
present in both the files
Used to terminate processes manually. kill command sends a signal to a process which
kill
terminates the process
Used to display the list of all the users logged in and out since the file /var/log/wtmp
last
was created
less Used to read contents of text file one page(one screen) per time
Used to display details about block devices and these block devices(Except ram disk)
lsblk
are basically those files that represent devices connected to the pc.
Used to display the status of modules in the Linux kernel. It results in a list of loaded
lsmod
modules
lsusb Used to display the information about USB buses and the devices connected to them
This command in Linux prints the mail queue i.e the list of messages that are there
mailq
in the mail queue
man Used to display the user manual of any command that we can run on the terminal
mkdir Allows the user to create directories. This command can create multiple
directories at once
Used to view the text files in the command prompt, displaying one screen at a
more
time in case the file is large (For example log files)
Used to move one or more files or directories from one place to another in file
mv
system like UNIX
Used to convert the content of input in different formats with octal format as the default
od
format
pidof Used to find out the process IDs of a specific running program
ping Used to check the network connectivity between host and server/host
It is a user information lookup command which gives details of all the users
pinky logged in. Unlike finger, in the pinky, you may trim the information of your
interest.
Used to display the memory map of a process. A memory map indicates how
pmap
memory is spread out
poweroff Sends an ACPI signal which instructs the system to power down
Used to display the given string, number or any other format specifier on the
printf
terminal window
Used to list the currently running processes and their PIDs along with some other
ps
information depends on different options
pwd It prints the path of the working directory, starting from the root
Reads up the total number of bytes from the specified file descriptor into the
read
buffer
rename Used to rename the named files according to the regular expression perlexpr
Used to initialize the terminal. This is useful once a program dies leaving a
reset
terminal in an abnormal state
restore Used for restoring files from a backup created using dump
Used to remove objects such as files, directories, symbolic links and so on from
rm
the file system like UNIX
route Used when you want to work with the IP/kernel routing table
It is a software utility for Unix-Like systems that efficiently sync files and
rsync
directories between two hosts or machines
Provides the ability to launch and use multiple shell sessions from a single ssh
screen
session
script Used to make typescript or record all the terminal activities
Used to compare two files and then writes the results to standard output in a
sdiff
side-by-side format
select Used to create a numbered menu from which a user can select an option
prints to standard output either the scan codes or the key code or the `ascii‟
showkey
code of each key pressed
sleep Used to create a dummy job. A dummy job helps in delaying the execution
sudo Used as a prefix of some command that only superuser are allowed to run
Used to examine and control the state of “systemd” system and service
systemctl
manager
tac Used to concatenate and print files in reverse
Reads the standard input and writes it to both the standard output and one or
tee
more files
Used to execute a command and prints a summary of real-time, user CPU time
time
and system CPU time spent by executing a command when it terminates
tracepath Used to traces path to destination discovering MTU along this path
traceroute Prints the route that a packet takes to reach the host
It displays the information related to terminal. It basically prints the file name of
tty
the terminal connected to standard input
type Used to describe how its argument would be translated if used as commands
Converts each spaces into tabs writing the produced output to the standard
unexpand
output
uniq It is a command line utility that reports or filters out the repeated lines in a file
Used to execute a set of commands as long as the final command in the „until‟
until
Commands has an exit status which is not zero
Uptime Used to find out how long the system is active (running)
usermod Used to change the properties of a user in Linux through the command line
It provides a set of commands to fetch username and its configurations from the
username
Linux host
users Used to show the user names of users currently logged in to the current host
It is the default editor that comes with the UNIX operating system is called visual
vi
editor.
Displays a message, or the contents of a file, or otherwise its standard input, on the
wall
terminals of all currently logged in users
Used to find out number of lines, word count, byte and characters count in the files
wc
specified in the file arguments
Used to download files from the server even when the user has not logged on to
Wget
the system and it can work in background without hindering the current process
Used to locate the executable file associated with the given command by searching
which
it in the path environment variable
whoami Displays the username of the current user when this command is invoked
Allows a user to communicate with other users, by copying lines from one user‟s
write
terminal to others
Commonly Used Options in `ls` command in Linux
Options Description
known as a long format that displays detailed information about files and
-l directories.
Options Description
-a Represent all files Include hidden files and directories in the listing.
Sort files and directories by their last modification time, displaying the most
-t recently modified ones first.
-r known as reverse order which is used to reverse the default order of listing.
-S Sort files and directories by their sizes, listing the largest ones first.
known as inode which displays the index number (inode) of each file and
-i directory.
known as group which displays the group ownership of files and directories
-g instead of the owner.
-rw-rw-r– 1 maverick maverick 1176 Feb 16 00:19 1.c 1st Character – File Type:
First character specifies the type of the file. In the example above the hyphen (-)
in the 1st character indicates that this is a normal file. Following are the possible
file type options in the 1st character of the ls -l output.
Field Explanation
– normal file
d : directory
s : socket file
l : link file
Field 1 – File Permissions: Next characters specifyes the files permission.
Every 3 characters specify read, write, execute permissions for user(root),
group and others respectively in order. Taking the above example, -rw-rw-r–
indicates read-write permission for user(root), read permission for group, and
no permission for others respectively. If all three permissions are given to
user(root), group and others, the format looks like -rwxrwxrwx
Field 2 – Number of links: Second field specifies the number of links for that
file. In this example, 1 indicates only one link to this file.
Field 3 – Owner: Third field specifies owner of the file. In this example, this file
is owned by username „maverick‟.
Field 4 – Group: Fourth field specifies the group of the file. In this example, this
file belongs to” maverick‟ group.
Field 5 – Size: Fifth field specifies the size of file in bytes. In this example,
„1176‟ indicates the file size in bytes.
Field 6 – Last modified date and time: Sixth field specifies the date and time of
the last modification of the file. In this example, „Feb 16 00:19‟ specifies the last
modification time of the file.
Field 7 – File name: The last field is the name of the file. In this example, the file
name is 1.c.
Linux comes in various distributions (distros), each with its own set of features and
target users. Here’s a list of some popular Linux distros: