Deep Dive Into Linux
As a DevOps engineer, you are responsible for preparing and maintaining the infrastructure (servers) on which the application is deployed. So you need to know how to administer a server and install different tools on it.
Linux is an operating system based on UNIX, and was first introduced by Linus Torvalds commonly used in servers It is free and open source.
We can download Linux for free and customize it as per our needs.
• It is very adaptable
• Immense amount of libraries and utilities
This operating system comes in various forms, known as distributions, each possessing its unique attributes and strengths.
Ubuntu: This one is good for people who are new to Linux, user friendly with a range of features
Fedora: This version is all about using the newest software. People who like to be on the cutting edge of technology usually prefer Fedora.
Debian: If you want an operating system that doesn't crash and is all about being open and free, Debian is a good choice. Many other Linux versions are based on Debian.
CentOS: This version is made for big servers and businesses. It's stable and gets long-term support, meaning it'll be taken care of for a long time.
Kali Linux: This one is made specifically for cybersecurity and testing security. It has a lot of tools built in for finding vulnerabilities and checking how secure things are.
Linux Architecture
Hardware: Linux boasts extensive compatibility with various hardware architectures, including x86, ARM, PowerPC, and more. It effectively interfaces with critical hardware elements like CPUs, memory, disks, network interfaces, and peripherals. Device drivers play a crucial role in enabling Linux to communicate with and govern diverse hardware devices.
Kernel: At the core of the Linux operating system lies the kernel, serving as its central nucleus. The kernel directly engages with the hardware, adeptly managing system resources and providing an interface for applications. It assumes vital responsibilities such as process scheduling, memory management, integration of device drivers, and ensuring system security.
Some pivotal Linux kernel-related commands include:
uname -r
: Presents the current version of the Linux kernel.lsmod
: Provides a list of the kernel modules currently loaded into memory.dmesg
: Offers insights into kernel messages and system logs.
Shell: Acting as a mediator between users and the operating system, the shell facilitates interaction through command-line interpretation. Linux provides various shell options, with Bash (Bourne Again SHell) being the most prevalent. The shell adeptly interprets user commands, empowering users to manage the system and execute programs.
Some frequently used shell commands include:
ls
: Displays files and directories.cd
: Switches the current directory.mkdir
: Creates a new directory.cp
: Copies files or directories.rm
: Deletes files or directories.
Applications: Linux boasts an extensive array of applications and software tailored for diverse purposes. Open-source software plays a significant role in the Linux ecosystem, fostering collaboration and innovation. Users can effortlessly install and utilize applications that cater to their specific requirements, including web browsers, office suites, media players, and development tools. Package managers like apt, yum, or dnf streamline the installation and administration of software packages.
Commands related to package management include:
apt-get install <package>
: Installs a package using the Advanced Package Tool (APT).
In summary, Linux's modular architecture encompasses the hardware layer, a kernel serving as the core orchestrator of system operations, a shell offering a command-line interface, and a diverse assortment of applications managed through package managers. This architectural framework delivers unparalleled flexibility, customization, and efficient management capabilities for Linux-based systems.
File Commands
ls | To view the contents of the directory (list) |
ls -al | Formatted listing with hidden files |
ls -lt | Sorting the Formatted listing by time modification |
cd dir | Change directory |
cd | Change to the home directory |
mv | move files / rename files |
rm | remove files |
cp | copy files |
clear | clear terminal window |
echo | move data into a file |
less | Shows file’s contents one screen at a time |
pwd | Show current working directory |
sudo | enables you to perform tasks that require administrative or root permissions |
top | task manager in the terminal |
apt | command line tool for interaction with the packaging system |
alias | custom shortcuts used to represent a command |
ping | to check the connectivity status to a server |
tar | used to archive multiple files into a tarball |
zip | to compress your files into a zip archive |
unzip | to extract the zipped files from a zip archive |
ssh | a secure encrypted connection between two hosts over and insecure network |
mkdir | make new directory |
cat | list the content of the file to the terminal |
rm file name | remove the files |
rm -r dir | Deleting the directory |
rm -f file | Force to remove the file |
rm -rf dir | Force to remove the directory dir |
cp file1 file2 | Copy the contents of file1 to file2 |
cp -r dir1 dir2 | Copy dir1 to dir2; create dir2 if not present |
touch filename | create a blank new file |
more filename | Output the contents of the file |
head file name | Output the first 10 lines of the file |
tail file name | Output the last 10 lines of the file |
tail -f | Output the contents of the file as it grows, starting with the last 10 lines |
Process management
ps | To display the currently working processes |
top | Display all running process |
kill pid | Kill the process with the given pid |
killall proc | Kill all the processes named proc |
pkill pattern | Will kill all processes matching the pattern |
bg | List stopped or background jobs, resume a stopped job in the background |
fg | Brings the most recent job to the foreground |
fg n | Brings the job n to the foreground |
ifconfig | Print IP address stuff |
ip a | similar to ifconfig but shortest print |
System Info
date | Show the current date and time |
cal | Show this month's calendar |
uptime | Show current uptime |
w | gives us important information about who is currently using the computer |
whoami | Who you are logged in as |
finger user | Display information about the user |
uname -a | Show kernel information |
cat /proc/cpuinfo | Cpu information |
cat proc/meminfo | Memory information |
man command | Show the manual for command |
df | Show the disk usage |
df -H | to check the storage space in harddisk |
free -h | to check the memory space in harddisk |
du | Show directory space usage |
whereis app | Show possible locations of the app |
which app | Show which applications will be run by default |
Searching
grep | used to search words in specific files |
grep pattern file | Search for a pattern in the file |
grep -r pattern dir | Search recursively for patterns in dir |
locate file | Find all instances of file |
find . -name filename | Searches in the current directory (represented by a period) and below it, for files and directories with names starting with the filename |
pgrep pattern | Searches for all the named processes, that match with the pattern and, by default, return their ID |
File permission
chmod — to change permissions of files and directories
chown — to change ownership of files and directories
chmod | to change permissions of files and directories |
chown | to change ownership of files and directories |
chmod octal file | Change the permission of the file to octal, which can be found separately for user, group, and world by adding, • 4-read(r) • 2-write(w) • 1-execute(x) |
Some Important Questions!
✨What are two types of Linux User Mode?
Command Line
GUI
✨ What is the difference between hard links and soft links?
Hard links point directly to the inode of a file, while soft links (or symbolic links) are separate files that contain the path to the target file.
✨ Explain the significance of the 'root' user in Linux.
The 'root' user is the superuser with administrative privileges. It has the highest level of access and can perform any operation on the system.
✨ How do you find all files modified in the last 10 minutes in a directory and its subdirectories?
Use the find command: find /path/to/directory -mmin -10.
✨ What is a kernel in Linux?
The kernel is the core of the operating system that manages hardware resources and provides essential services for other parts of the system.
✨ Explain the purpose of the 'chmod' command.
'chmod' changes the permissions of a file or directory. It can add or remove read, write, and execute permissions for the owner, group, and others.
✨ How can you find out the current runlevel of a Linux system?
Use the runlevel command: runlevel.
✨ Explain the role of the 'grep' command in Linux.
'grep' is used for searching text patterns in files. It can search for patterns using regular expressions and display matching lines.
✨ What is the purpose of the 'df' command?
'df' displays information about disk space usage on the filesystem.
✨ Explain the 'ps' command and how it is used to view processes.
'ps' shows information about currently running processes. Common options include ps aux to display detailed information about all processes.
✨ How do you change the priority of a process in Linux?
Use the nice command to run a process with a specified priority. For example, nice -n 10 command sets a lower priority.
✨ What is the purpose of the 'awk' command?
'awk' is a versatile text processing tool that performs pattern scanning and text extraction. It is often used for data manipulation and reporting.
✨ Explain the role of the 'tar' command in Linux.
'tar' is used for creating and extracting archive files. It bundles multiple files into a single archive file and can compress the archive using various algorithms.
✨ How can you check the connectivity between two hosts using the 'ping' command?
Use the ping command followed by the target IP or hostname: ping <target>.
✨ What is a cron job, and how do you create one?
A cron job is a scheduled task in Linux. To create one, use the crontab -e command and add an entry specifying the schedule and the command to be executed.
✨ Explain the purpose of the 'iptables' command.
'iptables' is used for configuring the Linux kernel's netfilter firewall. It can filter, modify, or redirect network packets.
Subscribe to my newsletter
Read articles from Ashwin directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Ashwin
Ashwin
I'm a DevOps magician, conjuring automation spells and banishing manual headaches. With Jenkins, Docker, and Kubernetes in my toolkit, I turn deployment chaos into a comedy show. Let's sprinkle some DevOps magic and watch the sparks fly!