Deep Dive Into Linux

AshwinAshwin
9 min read

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.

  1. Ubuntu: This one is good for people who are new to Linux, user friendly with a range of features

  2. Fedora: This version is all about using the newest software. People who like to be on the cutting edge of technology usually prefer Fedora.

  3. 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.

  4. 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.

  5. 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

  1. 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.

  2. 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.

  3. 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.

  4. 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

lsTo view the contents of the directory (list)
ls -alFormatted listing with hidden files
ls -ltSorting the Formatted listing by time modification
cd dirChange directory
cdChange to the home directory
mvmove files / rename files
rmremove files
cpcopy files
clearclear terminal window
echomove data into a file
lessShows file’s contents one screen at a time
pwdShow current working directory
sudoenables you to perform tasks that require administrative or root permissions
toptask manager in the terminal
aptcommand line tool for interaction with the packaging system
aliascustom shortcuts used to represent a command
pingto check the connectivity status to a server
tarused to archive multiple files into a tarball
zipto compress your files into a zip archive
unzipto extract the zipped files from a zip archive
ssha secure encrypted connection between two hosts over and insecure network
mkdirmake new directory
catlist the content of the file to the terminal
rm file nameremove the files
rm -r dirDeleting the directory
rm -f fileForce to remove the file
rm -rf dirForce to remove the directory dir
cp file1 file2Copy the contents of file1 to file2
cp -r dir1 dir2Copy dir1 to dir2; create dir2 if not present
touch filenamecreate a blank new file
more filenameOutput the contents of the file
head file nameOutput the first 10 lines of the file
tail file nameOutput the last 10 lines of the file
tail -fOutput the contents of the file as it grows, starting with the last 10 lines

Process management

psTo display the currently working processes
topDisplay all running process
kill pidKill the process with the given pid
killall procKill all the processes named proc
pkill patternWill kill all processes matching the pattern
bgList stopped or background jobs, resume a stopped job in the background
fgBrings the most recent job to the foreground
fg nBrings the job n to the foreground
ifconfigPrint IP address stuff
ip asimilar to ifconfig but shortest print

System Info

dateShow the current date and time
calShow this month's calendar
uptimeShow current uptime
wgives us important information about who is currently using the computer
whoamiWho you are logged in as
finger userDisplay information about the user
uname -aShow kernel information
cat /proc/cpuinfoCpu information
cat proc/meminfoMemory information
man commandShow the manual for command
dfShow the disk usage
df -Hto check the storage space in harddisk
free -hto check the memory space in harddisk
duShow directory space usage
whereis appShow possible locations of the app
which appShow which applications will be run by default

Searching

grepused to search words in specific files
grep pattern fileSearch for a pattern in the file
grep -r pattern dirSearch recursively for patterns in dir
locate fileFind all instances of file
find . -name filenameSearches in the current directory (represented by a period) and below it, for files and directories with names starting with the filename
pgrep patternSearches 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

chmodto change permissions of files and directories
chownto change ownership of files and directories
chmod octal fileChange 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

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.

0
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!