Linux Simple Notes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

https://www.linkedin.

com/in/vijaykumar-biradar-29b710161/

Linux Simple Notes


Check below Linux Fundamentals for beginners post for more information
https://www.linkedin.com/posts/vijaykumar-biradar-29b710161_linux-fundamentals-ugcPost-68
34000725429903360-dE4t
Why Use Linux

Unix Vs Linux
Today Linux is in great demand. You can see the use of Linux everywhere. It's dominating on
our servers, desktop, smartphones and even used in some electrical devices like refrigerators.

Some people think Unix and Linux as synonyms, but that's not true. Many operating systems
were developed to be like Unix but none of them got the popularity as Linux. Linux is the clone
of Unix. It has several features similar to Unix, still have some key differences. Before Linux
and Windows, computer world was dominated by Unix. Unix is a copyrighted name and IBM
AIX, HP-UX and Sun Solaris are only Unix operating system remained till date.

Difference between Linux and Unix

Comparison Linux Unix

Definition It is an open-source operating system It is an operating system which can be


which is freely available to everyone. only used by its copyrighters.

Examples It has different distros like Ubuntu, IBM AIX, HP-UX and Sun Solaris.
Redhat, Fedora, etc

Users Nowadays, Linux is in great demand. It was developed mainly for servers,
Anyone can use Linux whether a home workstations and mainframes.
user, developer or a student.

Usage Linux is used everywhere from servers, It is used in servers, workstations and
PC, smartphones, tablets to mainframes PCs.
and supercomputers.

Cost Linux is freely distributed, downloaded, Unix copyright vendors decide


and distributed through magazines also. different costs for their respective
And priced distros of Linux are also Unix Operating systems.
cheaper than Windows.

Development As it is open source, it is developed by Unix was developed by AT&T Labs,


sharing and collaboration of codes by various commercial vendors and non-
world-wide developers. profit organizations.
Manufacturer Linux kernel is developed by the Unix has three distributions IBM AIX,
community of developers from HP-UX and Sun Solaris. Apple also
different parts of the world. Although uses Unix to make OSX operating
the father of Linux, Linus Torvalds system.
oversees things.

GUI Linux is command based but some Initially it was command based OS,
distros provide GUI based Linux. Gnome but later Common Desktop
and KDE are mostly used GUI. Environment was created. Most Unix
distributions use Gnome.

Interface The default interface is BASH (Bourne It originally used Bourne shell. But is
Again SHell). But some distros have also compatible with other GUIs.
developed their own interfaces.

File system Linux supports more file system than It also supports file system but lesser
support Unix. than Linux.

Coding Linux is a Unix clone,behaves like Unix Unix contain a completely different
but doesn't contain its code. coding developed by AT&T Labs.

Operating Linux is just the kernel. Unix is a complete package of


system Operating system.

Security It provides higher security. Linux has Unix is also highly secured. It has
about 60-100 viruses listed till date. about 85-120 viruses listed till date

Error As Linux is open-source,whenever a In Unix, users have to wait for some


detection user post any kind of threat, developers time for the problem to be resolved.
and solution from all over the world start working on
it. And hence, it provides faster
solution.
Linux Distributions (Distros)

Choosing a Linux Distro

Distribution Why To Use

UBuntu It works like Mac OS and easy to use.

Linux mint It works like windows and should be use by new comers.

Debian It provides stability but not recommended to a new user.

Fedora If you want to use red hat and latest software.

Red hat To be used commercially.


enterprise
CentOS If you want to use red hat but without its trademark.

OpenSUSE It works same as Fedora but slightly older and more stable.

Arch Linux It is not for the beginners because every package has to be installed by
yourself.

Top Linux Distribution


Linux Commands List
Hardware Information
Show bootup messages:

dmesg

See CPU information:

cat /proc/cpuinfo

Display free and used memory with:

free -h

List hardware configuration information:

lshw
See information about block devices:

lsblk

Show PCI devices in a tree-like diagram:

lspci -tv

Display USB devices in a tree-like diagram:

lsusb -tv

Show hardware information from the BIOS:

dmidecode

Display disk data information:

hdparm -i /dev/disk

Conduct a read-speed test on device/disk:

hdparm -tT /dev/[device]

Test for unreadable blocks on device/disk:

badblocks -s /dev/[device]

Searching
Search for a specific pattern in a file with grep:
grep [pattern] [file_name]

Recursively search for a pattern in a directory:

grep -r [pattern] [directory_name]

Find all files and directories related to a particular name:

locate [name]

List names that begin with a specified character [a] in a specified


location [/folder/location] by using the find command:

find [/folder/location] -name [a]

See files larger than a specified size [+100M] in a folder:

find [/folder/location] -size [+100M]

File Commands
List files in the directory:

ls

List all files (shows hidden files):

ls -a

Show directory you are currently working in:


pwd

Create a new directory:

mkdir [directory]

Remove a file:

rm [file_name]

Remove a directory recursively:

rm -r [directory_name]

Recursively remove a directory without requiring confirmation:

rm -rf [directory_name]

Copy the contents of one file to another file:

cp [file_name1] [file_name2]

Recursively copy the contents of one file to a second file:

cp -r [directory_name1] [directory_name2]

Rename [file_name1] to [file_name2] with the command:

mv [file_name1] [file_name2]
Create a symbolic link to a file:

ln -s /path/to/[file_name] [link_name]

Create a new file:

touch [file_name]

Show the contents of a file:

more [file_name]

or use the cat command:

cat [file_name]

Append file contents to another file:

cat [file_name1] >> [file_name2]

Display the first 10 lines of a file with:

head [file_name]

Show the last 10 lines of a file:

tail [file_name]

Encrypt a file:
gpg -c [file_name]

Decrypt a file:

gpg [file_name.gpg]

Show the number of words, lines, and bytes in a file:

wc

Directory Navigation
Move up one level in the directory tree structure:

cd ..

Change directory to $HOME:

cd

Change location to a specified directory:

cd /chosen/directory

File Compression
Archive an existing file:

tar cf [compressed_file.tar] [file_name]

Extract an archived file:


tar xf [compressed_file.tar]

Create a gzip compressed tar file by running:

tar czf [compressed_file.tar.gz]

Compress a file with the .gz extension:

gzip [file_name]

File Transfer
Copy a file to a server directory securely:

scp [file_name.txt] [server/tmp]

Synchronize the contents of a directory with a backup directory using the rsync
command:

rsync -a [/your/directory] [/backup/]

Users
See details about the active users:

id

Show last system logins:

last

Display who is currently logged into the system with the who command:
who

Show which users are logged in and their activity:

Add a new group by typing:

groupadd [group_name]

Add a new user:

adduser [user_name]

Add a user to a group:

usermod -aG [group_name] [user_name]

Temporarily elevate user privileges to superuser or root using the sudo command:

sudo [command_to_be_executed_as_superuser]

Delete a user:

userdel [user_name]

Modify user information with:

usermod
Package Installation
List all installed packages with yum:

yum list installed

Find a package by a related keyword:

yum search [keyword]

Show package information and summary:

yum info [package_name]

Install a package using the YUM package manager:

yum install [package_name.rpm]

Install a package using the DNF package manager:

dnf install [package_name.rpm]

Install a package using the APT package manager:

apt-get install [package_name]

Install an .rpm package from a local file:

rpm -i [package_name.rpm]

Remove an .rpm package:


rpm -e [package_name.rpm]

Install software from source code:

tar zxvf [source_code.tar.gz]


cd [source_code]
./configure
make
make install

Process Related
See a snapshot of active processes:

ps

Show processes in a tree-like diagram:

pstree

Display a memory usage map of processes:

pmap

See all running processes:

top

Terminate a Linux process under a given ID:

kill [process_id]
Terminate a process under a specific name:

pkill [proc_name]

Terminate all processes labelled “proc”:

killall [proc_name]

List and resume stopped jobs in the background:

bg

Bring the most recently suspended job to the foreground:

fg

Bring a particular job to the foreground:

fg [job]

List files opened by running processes:

lsof

System Information
Show system information:

uname -r

See kernel release information:


uname -a

Display how long the system has been running, including load average:

uptime

See system hostname:

hostname

Show the IP address of the system:

hostname -i

List system reboot history:

last reboot

See current time and date:

date

Query and change the system clock with:

timedatectl

Show current calendar (month and day):

cal
List logged in users:

See which user you are using:

whoami

Show information about a particular user:

finger [username]

Disk Usage
See free and used space on mounted systems:

df -h

Show free inodes on mounted filesystems:

df -i

Display disk partitions, sizes, and types with the command:

fdisk -l

See disk usage for all files and directory:

du -ah

Show disk usage of the directory you are currently in:


du -sh

Display target mount point for all filesystem:

findmnt

Mount a device:

mount [device_path] [mount_point]

SSH Login
Connect to host as user:

ssh user@host

Securely connect to host via SSH default port 22:

ssh host

Connect to host using a particular port:

ssh -p [port] user@host

Connect to host via telnet default port 23:

telnet host

File Permission
Chown command in Linux changes file and directory ownership.
Assign read, write, and execute permission to everyone:

chmod 777 [file_name]

Give read, write, and execute permission to owner, and read and execute permission to
group and others:

chmod 755 [file_name]

Assign full permission to owner, and read and write permission to group and others:

chmod 766 [file_name]

Change the ownership of a file:

chown [user] [file_name]

Change the owner and group ownership of a file:

chown [user]:[group] [file_name]

Network
List IP addresses and network interfaces:

ip addr show

Assign an IP address to interface eth0:

ip address add [IP_address]

Display IP addresses of all network interfaces with:


ifconfig

See active (listening) ports with the netstat command:

netstat -pnltu

Show tcp and udp ports and their programs:

netstat -nutlp

Display more information about a domain:

whois [domain]

Show DNS information about a domain using the dig command:

dig [domain]

Do a reverse lookup on domain:

dig -x host

Do reverse lookup of an IP address:

dig -x [ip_address]

Perform an IP lookup for a domain:

host [domain]
Show the local IP address:

hostname -I

Download a file from a domain using the wget command:

wget [file_name]

Linux Keyboard Shortcuts


Kill process running in the terminal:

Ctrl + C

Stop current process:

Ctrl + Z

The process can be resumed in the foreground with fg or in the background with bg.

Cut one word before the cursor and add it to clipboard:

Ctrl + W

Cut part of the line before the cursor and add it to clipboard:

Ctrl + U

Cut part of the line after the cursor and add it to clipboard:

Ctrl + K
Paste from clipboard:

Ctrl + Y

Recall last command that matches the provided characters:

Ctrl + R

Run the previously recalled command:

Ctrl + O

Exit command history without running a command:

Ctrl + G

Run the last command again:

!!

Log out of current session:

exit

You might also like