Beginner's Guide to Basic Linux Commands: Day 2
Introduction
Welcome to Day 2 of our 90-day DevOps journey! In today's blog, we will learn about basics of Linux operating system. we'll dive deeper into Linux, exploring its core components, architecture, essential commands, and more basic concepts crucial for DevOps daily-to-daily tasks.
What is Linux?
Linux is an open-source operating system kernel originally developed by Linus Torvalds in 1991. It is the core of many Linux distributions (distros) like Ubuntu, Debian, CentOS, and Fedora. Known for its stability, security, and flexibility, Linux powers everything from servers and supercomputers to embedded devices and smartphones (Android is based on the Linux kernel).
Why Linux?
Linux is a powerhouse in the world of operating systems, and its widespread adoption in various domains—from personal computers to enterprise servers—raises the question: Why Linux? Below, we explore the key reasons why Linux is a preferred choice for many users and organizations.
Open Source and Free
Example: Ubuntu, a popular Linux distribution, is free to download and use. Users can also access and modify its source code to fit their needs.
Stability and Reliability
Example: Many web servers, including those for major companies like Google and Facebook, run on Linux due to its ability to handle high loads and maintain stability over long periods.
Security
Example: The Apache web server on Linux benefits from regular updates and community-driven security patches, making it a secure choice for hosting websites.
Flexibility and Customization
Example: Distributions like Arch Linux allow users to build their system from the ground up, installing only the software they need and customizing it to their exact specifications.
Performance
Example: Embedded systems, like those in routers and IoT devices, often run on Linux due to its minimal resource requirements and high efficiency.
Architecture of Linux
Linux follows a monolithic kernel architecture where the kernel provides core functionality directly to applications and drivers. Key components include:
Kernel: Core of the operating system managing hardware, memory, and processes.
Shell: Interface for users to interact with the kernel via command-line interpreters like Bash.
Filesystem: Organizes data into files and directories, supporting various filesystem types (e.g., ext4, etx2).
Processes: Running instances of programs managed by the kernel.
Components of the Linux File System
The Linux File System is structured hierarchically, starting from the root directory (/
). Key directories include:
/bin: Essential user binaries (commands) like
ls
,cp
,mv
./etc: Configuration files for system-wide settings.
/home: Home directories for users.
/var: Variable files like logs and databases.
/proc: Virtual file system providing kernel and process information.
Basic Linux Commands
ls
- Lists files and directories in the current directory.ls # Example: Listing contents of the current directory
cd
- Changes the current directory.cd /path/to/directory # Example: Changing to the /var/log directory cd /var/log
pwd
- Prints the current working directory.pwd # Example: Showing the current directory path
mkdir
- Creates a new directory.mkdir new_directory # Example: Creating a directory named "projects" mkdir projects
rmdir
- Removes an empty directory.rmdir empty_directory # Example: Removing an empty directory named "old_folder" rmdir old_folder
rm
- Removes files or directories.rm file_or_directory # Example: Removing a file named "old_file.txt" rm old_file.txt # Example: Removing a directory and its contents rm -r old_directory
cp
- Copies files or directories.cp source destination # Example: Copying a file "file.txt" to the "backup" directory cp file.txt backup/ # Example: Copying a directory and its contents cp -r source_directory backup/
mv
- Moves or renames files or directories.mv old_name new_name # Example: Renaming a file from "oldname.txt" to "newname.txt" mv oldname.txt newname.txt # Example: Moving a file to another directory mv file.txt /path/to/destination/
touch
- Creates an empty file or updates the timestamp of an existing file.touch filename # Example: Creating an empty file named "newfile.txt" touch newfile.txt
cat
- Concatenates and displays the content of files.cat file # Example: Displaying the content of "file.txt" cat file.txt
more
- Views file content one screen at a time.more file # Example: Viewing the content of "file.txt" one screen at a time more file.txt
less
- Views file content with backward and forward navigation.less file # Example: Viewing the content of "file.txt" with navigation less file.txt
head
- Displays the first few lines of a file.head file # Example: Displaying the first 10 lines of "file.txt" head file.txt
tail
- Displays the last few lines of a file.tail file # Example: Displaying the last 10 lines of "file.txt" tail file.txt
These are some basic commands you will use in Linux daily. If you have any issues with any Linux command, use the man
command to get complete information about it.
Syntax
man [command]
Examples
View the manual page for the
ls
command:man ls
This will display the manual for the
ls
command, which lists the files and directories in the current directory.
Well, congratulations! We are making great progress in the DevOps challenge and have unlocked the realm of Linux. These basic commands are the main way to interact with Linux. Get yourself familiar with them, and I'll see you in the next blog as we continue this exciting journey.