Table of contents
- What is Kernel
- What is Shell
- What is Linux Shell Scripting?
- Explain in your own words and examples, what is Shell Scripting for DevOps.
- What is #!/bin/bash? can we write #!/bin/sh as well?😒
- Write a Shell Script which prints I will complete #90DaysOofDevOps challenge
- Write a Shell Script to take user input, input from arguments and print the variables.
- Write an Example of If else in Shell Scripting by comparing 2 numbers
- Top 100 Linux Commands Cheat Sheet:
What is Kernel
The kernel is a computer program that is the core of a computer’s operating system, with complete control over everything in the system.
What is Shell
A shell is a special user program which provides an interface for the user to use operating system services. Shell accepts human-readable commands from a user and converts them into something which the kernel can understand. It is a command language interpreter that executes commands read from input devices such as keyboards or from files. The shell gets started when the user logs in or start the terminal.
What is Linux Shell Scripting?
A shell script is a computer program designed to be run by a Linux shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manipulation, program execution, and printing text.
Tasks
Explain in your own words and examples, what is Shell Scripting for DevOps.
Shell scripting for DevOps is all about 🤖 automating and orchestrating tasks and processes in a DevOps environment using 📜 shell scripts. It involves writing scripts in shell programming languages (such as Bash, PowerShell, or Python) to streamline repetitive tasks, enable process automation, and facilitate the integration and deployment of software. 🚀
What is #!/bin/bash?
can we write #!/bin/sh
as well?😒
The line "#!/bin/bash" is known as a shebang or hashbang. It is commonly placed at the beginning of a shell script file and specifies the interpreter to be used to execute the script. In this case, "/bin/bash" indicates that the script should be interpreted and executed by the Bash shell.
Bash (Bourne Again Shell) is a popular and feature-rich shell that is commonly used as the default shell on many Linux distributions. It is backwards-compatible with the original Bourne shell (/bin/sh) and provides additional functionality and improvements.
Now, regarding the use of "#!/bin/sh," it specifies the Bourne shell as the interpreter for the script. The Bourne shell is an older shell that lacks some of the advanced features and capabilities found in Bash. However, it is more lightweight and is still available on most Unix-like systems.
Write a Shell Script which prints
I will complete #90DaysOofDevOps challenge
#!/bin/sh
echo "I will Complete #90DaysOfDevOps Challenge"
First, create a file using touch Challenge.sh
Then vi Challenge.sh
Press I
on the keyboard to insert
Write you content
Press the esc Key on the keyboard
Write :wq
press enter to save and quit Vim
Give permission to file the execute using chmod -x Challenge.sh
At last type ./Challenge.sh
Write a Shell Script to take user input, input from arguments and print the variables.
Write an Example of If else in Shell Scripting by comparing 2 numbers
#!/bin/bash
# Compare two numbers
num1=10
num2=20
if [ $num1 -eq $num2 ]; then
echo "The numbers are equal."
elif [ $num1 -gt $num2 ]; then
echo "Number 1 is greater than Number 2."
else
echo "Number 2 is greater than Number 1."
fi
Top 100 Linux Commands Cheat Sheet:
cd — Change directory
ls — List directory contents
pwd — Print working directory
cat — Concatenate and display files
touch — Create an empty file
cp — Copy files and directories
mv — Move or rename files and directories
rm — Remove files and directories
mkdir — Create a new directory
rmdir — Remove an empty directory
cut — Cut out sections of a file
gzip — Compress or decompress files using gzip
gunzip — Decompress files compressed with gzip
find — Find files and directories matching a pattern
grep — Search for a pattern in a file
awk — Pattern scanning and processing language
sed — Stream editor for filtering and transforming text
head — Display the first few lines of a file
tail — Display the last few lines of a file
sort — Sort lines of a file
uniq — Remove duplicate lines from a file
wc — Count lines, words, and characters in a file
diff — Compare two files line by line
patch — Apply a patch to a file
chmod — Change permissions of files and directories
chown — Change the owner of a file or directory
chgrp — Change the group ownership of a file or directory
ps — List running processes
top — Display system resource usage and process information
kill — Send a signal to a process to terminate it
du — Display disk usage of files and directories
df — Display free disk space on the file system
mount — Mount a file system
umount — Unmount a file system
ping — Test connectivity to a network host
ssh — Secure shell remote login and command execution
scp — Secure copy files between hosts
rsync — Remote file and directory synchronization
curl — Transfer data from or to a server using various protocols
wget — Retrieve files from the web using various protocols
ftp — File Transfer Protocol client
sftp — Secure File Transfer Protocol client
telnet — Telnet client
nslookup — DNS lookup utility
dig — DNS lookup utility
netstat — Display network connections and statistics
ifconfig — Configure network interfaces
route — Display or modify the routing table
iptables — Firewall and packet filtering utility
hostname — Display or set the hostname of the system
date — Display or set the system date and time
timedatectl — Control the system date and time
uname — Display system information
whoami — Display the current user ID
id — Display user and group information
su — Switch user to become another user
sudo — Execute a command with superuser privileges
passwd — Change the password of a user account
useradd — Create a new user account
userdel — Delete a user account
usermod — Modify a user account
groupadd — Create a new group
groupdel — Delete a group
groupmod — Modify a group
finger — Display information about users on the system
last — Display information about recent logins
history — Display command history
echo — Print a message to the terminal
printf — Format and print data
lshw — Displays hardware information
lspci — Displays information about PCI buses and devices.
lsusb — Displays information about USB buses and devices.
hwinfo — Displays detailed hardware information.
free — Displays memory usage.
vmstat — Displays system memory, processor, and I/O statistics.
iostat — Displays CPU and disk I/O statistics.
uptime — Displays system uptime and load averages.
journalctl — Displays the system journal.
dmesg — Displays the kernel ring buffer.
crontab — Schedules recurring tasks.
at — Schedules a one-time task.
service — Manages system services.
systemctl — Controls system services in systemd-based distributions.
traceroute — Traces the network path to a remote host.
bzip2 — Compresses files using the bzip2 algorithm.
unzip — Extracts files from a ZIP archive.
tee — Redirect output to multiple files
chroot — Change the root directory for a process
ps aux — Display information about all running processes
less — Display file contents in a paginated format
more — Display file contents one page at a time
ln — Create links between files
realpath — Print the resolved absolute path of a file
watch — Execute a command periodically and display the output
cal — Display a calendar
tar -xzvf — Extract files from a compressed archive
tar -czvf — Create a compressed archive
whereis — Locate the binary, source, and manual page files for a command
locate — Find files by name
which — Display the full path to an executable