100% found this document useful (9 votes)
2K views

Linux QuickStart

This document provides an introduction to Linux, including common Linux distributions, package management systems like RPM and DEB, basic Linux commands, file permissions, users and groups, software installation, searching files, remote login, and file transfers. It covers topics such as navigating the file system, editing files with VIM, creating users and groups, managing software packages, searching for files, remote access via SSH/Telnet, and transferring files using SCP and Rsync.

Uploaded by

anu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (9 votes)
2K views

Linux QuickStart

This document provides an introduction to Linux, including common Linux distributions, package management systems like RPM and DEB, basic Linux commands, file permissions, users and groups, software installation, searching files, remote login, and file transfers. It covers topics such as navigating the file system, editing files with VIM, creating users and groups, managing software packages, searching for files, remote access via SSH/Telnet, and transferring files using SCP and Rsync.

Uploaded by

anu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

1.

Linux Introduction
Why Linux?
• OpenSource.
• Community support.
• Heavily customizable.
• Most Servers runs on Linux.
• DevOps most of the tools implements on Linux only.
• Automation
• Secure.

Architecture of Linux
Diffrent Linux distros
➔ Popular Desktop Linux OS
• Ubuntu Linux

• Linux Mint

• Arch Linux

• Fedora

• Debian

• OpenSuse

➔ Popular Server Linux OS


• Red Hat Enterprise Linux

• Ubuntu Server

• Centos

• SUSE Enterprise Linux


Most used Linux distros currently in IT industry.
RPM based:- RHEL & Centos
Debian based :- Ubuntu Server

Diffrence between RPM based and Debian based.


From user’s point of view, there isn’t much difference in these tools. The RPM and DEB formats
are both just archive files, with some metadata attached to them. They are both equally arcane, have
hardcoded install paths and only differ in subtle details. DEB files are installation files for Debian
based distributions. RPM files are installation files for Red Hat based distributions. Ubuntu is based
on Debian’s package manage based on APT and DPKG. Red Hat, CentOS and Fedora are based on
the old Red Hat Linux package management system, RPM.

DEB or .deb (Debian based softwares)


DEB is the extension of the Debian software package format and the most often used name for such
binary packages. DEB was developed by Bedian.
Example: Google chrome software
Package name: google-chrome-stable_current_amd64.deb
Installation: dpkg -i google-chrome-stable_current_amd64.deb
RPM or .rpm (Red Hat based softwares.)
It is a package management system. The name RPM variously refers to the .rpm file format, files in
this format, software packaged in such files, and the package manager itself. RPM was intended
primarily for Linux distributions; the file format is the baseline package format of the Linux
Standard Base. RPM was developed by Community & Red Hat.
Example: Google chrome software
Package Name: google-chrome-stable-57.0.2987.133-1.x86_64.rpm
Installation: rpm -ivh google-chrome-stable-57.0.2987.133-1.x86_64.rpm

NOTE: You will also encounter diffrent commands, packages and service names while using
both kinds of distros.
2. Basic Commands
➔ Open Terminal

➔ Know where you are? Present Working Directory

➔ Create a directory/folder in your home directory.

➔ Change your current working directory to linux-practices(Go to linux-practices


folder).

➔ Create some more directories and list them with “ls” command.

➔ Create some empty files with “touch” command and list them.
➔ Reconfirm your location in your system.

Absolute path and Relative path

What is a path?
A path is a unique location to a file or a folder in a file system of an OS. A path to a file is a

combination of / and alpha-numeric characters.

What is an absolute path?


An absolute path is defined as the specifying the location of a file or directory from the root

directory(/). In other words we can say absolute path is a complete path from start of actual

filesystem from / directory.

Some examples of absolute path:

/home/imran/linux-practices/
/var/ftp/pub
/etc/samba.smb.conf
/boot/grub/grub.conf
If you see all these paths started from / directory which is a root directory for
every Linux/Unix machines.

What is the relative path?


Relative path is defined as path related to the present working directory(pwd). Suppose I am located

in /home/imran and I want to change directory to /home/imran/linux-practices. I can use relative

path concept to change directory to linux-practices and also devopsdir directory.


If you see all these paths did not start with / directory.
➔ Creating directories in devopsdir directory with absolute and relative path.

➔ Copying files into directory.

➔ Copying directories from one location to another.


➔ Moving files from one location to another.

➔ Removing files and directories.


3. VIM EDITOR
➔ Install vim editor.

➔ Open up a file in vim editor

➔ Hit i to enter into insert mode

=> type few lines => hit Esc

=> type :wq

=> Enter.
➔ Read file with cat command.
Types of files in linux.

Symbolic links
Symbolic links are like desktop shortcuts we use in windows.
Create a soft link for /var/log directory in our current working directory.
4. Filter & IO redirection command.
Grep
grep command is used to find texts from any text input.
Passwd file: stores information about all the users in the system

➔ Finding line which contains word as “root” from /etc/passwd file.

➔ Linux is case sensetive, Root is diffrent that root. Ignoring case in grep with -i option.

➔ To display things except the given word use -v option

Filter Commands
• less: Displays file content page wise or line wise.
Ex: less /etc/passwd
• more

• head

• tail
• cut

• sed
I/O redirection

➔ Create a file named devopstools with below content.

➔ Search for text “tech” replace it with “tools” and redirect output to a new file.

➔ Appending another output in same file with “>>” .


Piping
So far we've dealt with sending data to and from files. Now we'll take a look at a
mechanism for sending data from one program to another. It's called piping and the
operator we use is ( | ). What this operator does is feed the output from the program on
the left as input to the program on the right.

Find
5. Users & Groups.
USERS
Passwd file

$ id => Show the active user id


with login and group

$ last => Show last logins on the


system (few more examples)

$ who => Show who is logged on the


system(real user who logged in)

$ sudo groupadd admin => Add group "admin"


(force add existing group)
$ sudo adduser sam => Create user "sam" and add to group
"admin"(here read all parameter)

$ sudo usermod => Modify user


information(mostly useful for linux system admins)

$ sudo passwd sam => Changing password for other user

$ passwd => Changing your own password.

$ sudo userdel -r sam => Delete user sam


(force,file removal)

$ sudo groupdel deck => Deletes a group


6.File permissions
7. Sudo
sudo gives power to a normal user to execute commands which is owned by root user.
Example shown below:
If a user has already full sudoers privilege, it can become a root user anytime.
➔ sudo -i changes from normal user to root user

Note: User imran was already a sudo user with full privilege.
➔ Adding user sam in sudoers list.

➔ Like a user a group can also be added into sudoers list.


➔ Every time you enter sudo command it asks your own password. To turn that off use
NOPASSWD in sudoers file.

➔ Changing to any other user with “su -” command.

➔ Become a root user from sam user login.


8. Software Management.

➔ Download package from internet.

# wget http://archive.ubuntu.com/ubuntu/pool/universe/t/tree/tree_1.7.0-3_amd64.deb

REDHAT family(single package)

$ sudo rpm -i pkgname.rpm # Install rpm


based package (Installing, Uninstalling, Updating, Querying
,Verifying)

$ sudo rpm -e pkgname # Remove package

REDHAT family(Package with dependency from internet)

$ sudo yum install package-name #Install with dep

$ sudo yum remove package-name # Remove package

UBUNTU/DEBIAN

$ sudo dpkg -i package-name #Install deb pack

$ sudo dpkg -e package-name #Remove deb pack

UBUNTU/Debian(Package with dependency from internet)

$ sudo apt-get install package-name #Install with dep

$ sudo apt-get remove package-name #Remove deb pack

Install from source

./configure

make

make install (what it is)


9. SEARCH
$ grep pattern files # Search for pattern in files
(you will this command often)

$ grep -r pattern dir # Search recursively for


pattern in dir

$ locate file # Find all instances of file

$ find /home/tom -name 'index*' # Find files names that start


with "index"(10 find examples)

$ find /home -size +10000k # Find files larger than


10000k in /home

10. LOGIN (SSH AND TELNET)


$ ssh user@host # Connect to host as user
(secure data communication command)

$ ssh -p port user@host # Connect to host using


specific port

$ telnet host # Connect to the system


using telnet port

11. FILE TRANSFER


scp

$ scp file.txt server2:/tmp # Secure copy


file.txt to remote host /tmp folder

$ scp nixsavy@server2:/www/*.html /www/tmp # Copy *.html files


from remote host to current system /www/tmp folder

$ scp -r nixsavy@server2:/www /www/tmp # Copy all files


and folders recursively from remote server to the current system
/www/tmp folder

rsync

$ rsync -a /home/apps /backup/ # Synchronize


source to destination

$ rsync -avz /home/apps [email protected]:/backup #


Synchronize files/directories between the local and remote system
with compression enabled
12. DISK USAGE
$ df -h # Show free space on mounted
filesystems(commonly used command)

$ df -i # Show free inodes on mounted


filesystems

$ fdisk -l # Show disks partitions sizes and


types(fdisk command output)

$ du -ah # Display disk usage in human


readable form (command variations)

$ du -sh # Display total disk usage on the


current directory

$ findmnt # Displays target mount point for


all filesystem (refer type,list,evaluate output)

$ mount device-path mount-point # Mount a device

13. DIRECTORY TRAVERSE


$ cd .. # To go up one level of the
directory tree(simple & most needed)

$ cd # Go to $HOME directory

$ cd /test # Change to /test directory

14. SERVICES
$ sudo service apache2 start # Starts apache2 on ubuntu

$ sudo service httpd start # Starts apache2 on Redhat

$ sudo service httpd stop

$ sudo service httpd restart # Restart services

$ sudo service httpd reload # Reload conf

$ chkconfig httpd on # starts httpd at boot time

$ chkconfig httpd off # stops httpd at boot time


15. COMPRESSION / ARCHIVES
$ tar cf home.tar home # Create tar named home.tar
containing home/ (11 tar examples)

$ tar xf file.tar # Extract the files from


file.tar

$ tar czf file.tar.gz files # Create a tar with gzip


compression

$ gzip file # Compress file and renames it


to file.gz (untar gzip file)

16. PROCESS RELATED


$ ps # Display your currently active
processes (many parameters to learn)

$ ps aux | grep 'telnet' # Find all process id related to


telnet process

$ pmap # Memory map of process


(kernel,user memory etc)

$ top # Display all running processes


(30 examples)

$ kill pid # Kill process with mentioned


pid id (types of signals)

$ killall proc # Kill all processes named proc

$ pkill processname # Send signal to a process with


its name

$ bg # Resumes suspended jobs without


bringing them to foreground (bg and fg command)

$ fg # Brings the most recent job to


foreground

$ fg n # Brings job n to the foreground


17. SYSTEM
$ uname -a => Display linux system
information

$ uname -r => Display kernel release


information (refer uname command in detail)

$ cat /etc/redhat_release => Show which version of redhat


installed

$ uptime => Show how long system running +


load (learn uptime command)

$ hostname => Show system host name

$ hostname -i => Display the IP address of the


host (all options hostname)

$ last reboot => Show system reboot history


(more examples last command)

$ date => Show the current date and time


(options of date command)

$ cal => Show this month calendar (what


more in cal)

$ w => Display who is online (learn


more about w command)

$ whoami => Who you are logged in as


(example + sreenshots)

$ finger user => Display information about user


(many options of finger command)

18. HARDWARE
$ dmesg => Detected hardware and boot
messages (dmesg many more options)

$ cat /proc/cpuinfo => CPU model

$ cat /proc/meminfo => Hardware memory

$ cat /proc/interrupts => Lists the number of interrupts


per CPU per I/O device

$ lshw => Displays information on


hardware configuration of the system

$ lsblk => Displays block device related


information in Linux (sudo yum install util-linux-ng)

$ free -m => Used and free memory (-m for


MB) (free command in detail)
$ lspci -tv => Show PCI devices (very useful
to find vendor ids)

$ lsusb -tv => Show USB devices (read more


lsusb options)

$ lshal => Show a list of all devices with


their properties

$ dmidecode => Show hardware info from the


BIOS (vendor details)

$ hdparm -i /dev/sda # Show info about disk sda

$ hdparm -tT /dev/sda # Do a read speed test on disk sda

$ badblocks -s /dev/sda # Test for unreadable blocks on

disk sda

19. STATISTICS
$ top => Display and update the top
cpu processes (30 example options)

$ mpstat 1 => Display processors related


statistics (learn mpstat command)

$ vmstat 2 => Display virtual memory


statistics (very useful performance tool)

$ iostat 2 => Display I/O statistics (2sec


Intervals) (more examples)

$ tail -n 500 /var/log/messages => Last 10 kernel/syslog


messages (everyday use tail options)

$ tcpdump -i eth1 => Capture all packets flows on


interface eth1 (useful to sort network issue)

$ tcpdump -i eth0 'port 80' => Monitor all traffic on port


80 ( HTTP )

$ lsof => List all open files belonging


to all active processes.(sysadmin favorite command)

$ lsof -u testuser => List files opened by specific


user

$ free -m => Show amount of RAM (daily


usage command)

$ watch df -h => Watch changeable data continuously(interesting


linux command)

You might also like