Linux Commands and Architecture in Operating System
What is Linux?
- Linux is an open-source, Unix-like operating system kernel that serves as the core of various Linux distributions.
- It's known for its stability, security, and flexibility.
- Linux offers a command-line interface (CLI) for system administration and management, making it a popular choice for server environments and advanced users.
The Architecture of Linux OS
Linux is designed with a multi-layered architecture that consists of the following components:
1. Hardware Layer
The hardware layer includes the physical components of a computer, such as the CPU, RAM, storage devices, and peripherals.
2. Kernel
- The kernel is the core of the Linux operating system.
- It manages hardware resources, and system processes, and provides a bridge between software and hardware.
3. Shell
The shell is the user interface for interacting with the kernel. It interprets and executes commands entered by users.
4. User Applications
User applications are programs and software that run on top of the operating system, utilizing its resources and services.
Basic Directory Structure of Linux
Linux follows a hierarchical directory structure. Key directories include:
/ (Root)
- The root directory is the top-level directory in Linux. All other directories and files stem from it.
/bin
- Essential binary executable files are stored here, required for system booting and repair.
/etc
- Configuration files for system-wide settings are located in this directory.
/home
- User home directories are stored here, each with its user-specific files and settings.
/usr
- The secondary hierarchy for user and system files, including user binaries and libraries.
/var
- Variable data files, like log files, are stored in this directory.
Linux Basic Commands
Linux offers various commands to interact with the system. Let's explore a few basic commands:
man - Manual Pages
The man command is used to display the manual pages for other commands and programs. For example:
1man ls
info - Information Pages
The info command provides information pages for various commands and topics. For example:
1info ls
help - Built-in Command Help
Many commands have built-in help documentation that can be accessed by appending --help to the command. For example:
1ls –help
whatis - Short Description
The whatis command provides a brief description of a command. For example:
1whatis ls
apropos - Search Commands
The apropos command searches the manual pages for commands related to a given keyword. For example:
1apropos file
Linux Directory Navigation Commands
Cat
- cat is a command-line utility in Unix and Unix-like operating systems, including Linux.
- The term "cat" stands for "concatenate," but its primary purpose is to display the contents of files, concatenate files, or create new files.
- The basic syntax of the cat command is as follows:
1cat [options] [file(s)]
- Options: Additional settings or flags that modify the behavior of the cat command.
- File(s): The name(s) of the file(s) whose contents you want to display or concatenate.
Here are some common use cases of the cat command:
Displaying File Contents
To simply display the contents of a file:
1cat myfile.txt
Concatenating Files
You can use cat to concatenate multiple files and display the result:
1cat file1.txt file2.txt
This command outputs the combined content of file1.txt and file2.txt to the terminal.
Creating a New File
You can use cat to create a new file or overwrite the content of an existing file:
1cat > newfile.txt
After entering this command, anything you type will be written to newfile.txt. Press Ctrl + D to finish.
Redirecting Output to a File
You can also use cat to redirect the output of a command or multiple files into a new file:
1cat file1.txt file2.txt > combined.txt
This command concatenates file1.txt and file2.txt and writes the result to a new file named combined.txt.
cd - Change Directory
The cd command is used to change the current working directory. For example:
1cd /home/user
ls - List Files and Directories
The ls command lists the files and directories in the current directory. For example:
1ls –l
pwd - Print Working Directory
The pwd command displays the current working directory. For example:
1Pwd
mkdir - Create Directory
The mkdir command is used to create a new directory. For example:
1mkdir new_directory
rmdir - Remove Directory
The rmdir command deletes an empty directory. For example:
1rmdir empty_directory
mv - Move or Rename Files and Directories
The mv command can be used to move or rename files and directories. For example:
1mv file1.txt /path/to/new_location/
cp - Copy Files and Directories
The cp command duplicates files and directories. For example:
1cp file.txt /path/to/destination/
rm - Remove Files and Directories
The rm command deletes files and directories. For example:
1rm file.txt
file - Determine File Type
The file command is used to determine the type of a file. For example
1file document.pdf
date - Display Date and Time
The date command displays the current date and time. For example:
1Date
cal - Display Calendar
The cal command shows a calendar for a specified month and year. For example:
1Cal
echo - Print Text
The echo command is used to display text on the terminal. For example:
1echo "Hello, World!"
bc - Calculator
The bc command is a calculator for performing mathematical calculations. For example:
1
2echo "5 + 3" | bc
3
who - Display Users
The who command shows a list of users currently logged in. For example:
1Who
whoami - Current User
The whoami command displays the username of the current user. For example:
1whoami
hostname - Display Hostname
The hostname command shows the system's hostname. For example:
1Hostname
uname - System Information
The uname command displays system information. For example
1uname –a
tty - Display Terminal Name
The tty command shows the terminal device name. For example.
1Tty
alias - Create Command Aliases
The alias command is used to create aliases for longer or frequently used commands. For example:
1alias ll='ls -l'
- These are some of the fundamental aspects of Linux architecture, directory structure, and essential commands.
- Linux offers a vast array of commands and capabilities, making it a powerful and versatile operating system for various use cases.
How to Install Linux On Windows:
1. Using Windows Subsystem for Linux (WSL):
Windows 10 or later versions support WSL, which allows you to run a Linux distribution alongside your Windows installation.
Steps to set up WSL:
Enable WSL feature:
- Open PowerShell as an administrator and run:
1dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Install a Linux distribution:
- You can choose from various distributions available on the Microsoft Store, such as Ubuntu, Debian, or Fedora. Install your preferred one from the store.
Initialize and set up your Linux distribution:
- Launch your installed distribution, set up a username and password, and you're ready to use Linux.
2. Using Virtual Machines (VM):
You can also run Linux on a virtual machine using software like VirtualBox, VMware, or Hyper-V.
Steps to set up a Linux VM:
Install virtualization software:
- Download and install a virtualization tool like VirtualBox from the official website.
Download a Linux ISO:
- Download a Linux distribution ISO file from its official website. Common choices include Ubuntu, CentOS, and Fedora.
Create a new VM:
- Open your virtualization software, create a new virtual machine, and choose the Linux ISO as the installation source.
Follow the installation process:
- Go through the Linux installation process as you would on a physical machine.
Start your Linux VM:
- Once the installation is complete, you can run and manage your Linux VM alongside your Windows environment.
On macOS:
Using Virtualization Software:
macOS users can also run Linux on a virtual machine using software like VirtualBox or VMware Fusion.
Steps to set up a Linux VM on macOS:
Install virtualization software:
- Download and install a virtualization tool like VirtualBox or VMware Fusion on your Mac.
Download a Linux ISO:
- Download a Linux distribution ISO file from its official website. Common choices include Ubuntu, CentOS, and Fedora.
Create a new VM:
- Open your virtualization software, create a new virtual machine, and choose the Linux ISO as the installation source.
Follow the installation process:
- Go through the Linux installation process as you would on a physical machine.
Start your Linux VM:
- Once the installation is complete, you can run and manage your Linux VM alongside your macOS environment.
Both WSL and virtual machines provide a convenient way to get started with Linux on Windows and macOS.
Choose the method that best suits your needs and start exploring the Linux environment within your existing OS.