document (75)
document (75)
Linux Introduction
Linux Origins
Linux Principles
Why Linux?
• OpenSource.
• Community support.
• Heavily customizable.
• Most servers run on Linux.
• DevOps tools mostly implemented on Linux only.
• Automation.
• Secure.
Architecture of Linux
The diagram illustrates how users interact with the system, from applications to hardware, through the shell and kernel.
• Ubuntu Linux
• Linux Mint
• Arch Linux
• Fedora
• Debian
• OpenSuse
From the user's perspective, there is little functional difference in the tools. Both RPM and DEB formats are archive files with
metadata attached. They differ in subtle details such as installation paths and package management systems:
Note: Commands, packages, and service names can differ across RPM-based and Debian-based systems.
2. Basic Commands
Open Terminal
Command:
pwd
Output:
/home/imran
Command:
mkdir linux-practices
Command:
cd linux-practices/
Commands:
mkdir vpdir
mkdir testdir
mkdir devopsdir
ls
Output:
Create Some Empty Files with the touchCommand and List Them
Commands:
Output:
Commands:
pwd
ls
Output:
/home/imran/linux-practices
devopsdir file1 file2 file3 file4 testdir vpdir
What is a Path?
• A path is a unique location to a file or folder in the file system of an OS. It consists of / and alphanumeric characters.
• An absolute path specifies the location of a file or directory starting from the root directory (/).
• It provides the complete path from the root of the filesystem.
• /home/imran/linux-practices/
• /var/ftp/pub
• /etc/samba.smb.conf
• /boot/grub/grub.conf
• A relative path is defined as the path related to the present working directory (pwd).
• For example, if you're in /home/imranand want to change to /home/imran/linux-practices, you can use the
relative path concept.
Commands:
pwd
cd devopsdir/
Outputs:
Commands:
ls
mkdir devopsdir/ansible
mkdir /home/imran/linux-practices/devopsdir/aws
ls devopsdir/
Commands:
pwd
ls
cp file1 testdir/
ls testdir/
Outputs:
Commands:
cd
pwd
cp -rvp testdir/ vpdir/
ls vpdir/
Outputs:
Commands:
pwd
ls
mv file3 file4 vpdir/
ls
ls vpdir/
Outputs:
Commands:
rm file1
ls
rm -rf testdir/
ls
Outputs:
VIM Editor
Command:
Command:
vim firstfile.txt
VIM Editor
Overview of VIM
Command Function
gg Go to the beginning of the page.
G Go to the end of the page.
w Move the cursor forward, word by word.
b Move the cursor backward, word by word.
nw Move the cursor forward n words (e.g., 5w).
nb Move the cursor backward n words (e.g., 5b).
u Undo the last change.
U Undo all changes on the line.
Ctrl+R Redo the last undone change.
yy Copy a line.
nyy Copy n lines (e.g., 5yy).
p Paste the line below the cursor.
P Paste the line above the cursor.
dw Delete a word.
x Delete the character under the cursor.
dd Delete the current line.
ndd Delete n lines (e.g., 5dd).
/ Search for a word in the file.
These commands make it easy to navigate, edit, and manipulate text within the VIM editor efficiently.
Extended Mode is used for saving, quitting , or saving without quitting using the Esc key with :.
Command Function
:w Save the changes.
:q Quit (without saving).
:wq Save and quit.
:w! Save forcefully.
:wq! Save and quit forcefully.
:x Save and quit.
:X Set a password for the file and remove it.
:20 (or n) Go to line number 20 (or line n).
:set nu Set line numbers.
:set nonu Remove line numbers.
ls Command Options
Option Description
-l Long listing format of files and directories, one per line.
-a List all hidden files and directories (starting with .).
-F Add a / classification at the end of each directory.
-g List all files and directories with the group name.
-i Print the index number of each file and directory.
-m List all files and directories separated by commas.
-n List numeric UID and GID of owner and groups.
-R List all files and directories in reverse order.
-r Short list all directories.
-t Sort by modified time, starting with the newest file.
First Character in
File Type Description
Listing
Regular
- Normal files such as text, data, or executable files.
File
Directory d Files that are lists of other files.
Link l A shortcut pointing to the location of an actual file.
Special File c Mechanism used for input and output (e.g., character files in /dev).
A special file providing inter-process networking protected by the file system’s access
Socket s
control.
Pipe p A special file for processes to communicate using network socket semantics.
Symbolic Links
Commands:
ls -l /var/log
ln -s /var/log loglink
ls -l
Explanation:
Grep
The grep command is used to find specific text from any input.
Example: /etc/passwdFile
• The /etc/passwdfile stores information about all the users in the system.
• Sample content of /etc/passwd:
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
...
Command:
Output:
root:x:0:0:root:/root:/bin/bash
Case-Insensitive Search
Command:
Output:
root:x:0:0:root:/root:/bin/bash
Command:
Filter Commands