Conceptts

           

Distro

diffrent kinds of linux branches with the same linux core,are called distros.like ubuntu,fedora,debian.

packages

softwares are packaged to easily be installed. debian based packages are in .deb format whereas redhat based are rpm packages.

Repositories

It is a software packages container. when search via software centre or tools lke apt-get or yum, you are shown a list of the packages within the repositories available to your system. A sofware repository can store its files on one server or across different servers known as mirrors. These are various Linux repo mirrors. They are unlisted, but public to anyone who needs them.

PPA

personal package archives -- PPAs provide access to third-party programs.
. These offer software not bundled in a default Linux operating system.

How to Add a PPA?

    sudo add-apt-repository [repository name]
    sudo apt-get update
    sudo apt-get install [software name]

File system

/              is called superuser home directory.It is the top of file system structure.All other directory are mounted under it.
/boot          contain the kernal image file.This also contain the files related to booting the system such as bootloader.
/etc           contain the whole system configuration file.
/home          This is the all users home directory.
/mnt           This is a generic mount point under which you mount your filesystems such as cdrom,floppy.
/proc          It is not a real file system, it is a virtual file system.This directory is empty until the proc  file system is mounted.
/sys           Modern Linux distributions include a /sys directory as a virtual filesystem (sysfs, comparable to /proc, which is a procfs), 
               which stores and allows modification of the devices connected to the system.
/dev           contain the devices nodes through which the operating system can access hardware and software devices on the system.
/bin           contain the command used by superuser and normal user.
/sbin          ontain the command used by superuser only
/var/www/html/ contain php files for local web host (lamp)

How tos

    

- Check os version in Linux:

$ hostnamectl

- Add toggle language feature to the keyboard:

$ setxkbmap -option grp:switch,grp:alt_shift_toggle,grp_led:scroll ir,us

- Check os version in Linux:

$ hostnamectl

- Backup MBR with dd command

Backing up partition is nothing but actually backing up MBR (master boot record). The command is as follows for backing up MBR stored on /dev/sdX or /dev/hdX :
# dd if=/dev/sdX of=/tmp/sda-mbr.bin bs=512 count=1
( Replace X with actual device name such as /dev/sda.)
To restore partition table to disk, all you need to do is use dd command:
# dd if= sda-mbr.bin of=/dev/sdX bs=1 count=64 skip=446 seek=446
How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 18.04

Shell commands

Shell commands are part of the shell program. 
There are several different shells 
(C shell, bash shell, bourne shell etc) to choose from,
and each will have a variation of the shell commands built in. 
The commands vary between shells, 
but each shell is the same across different linux distros.
                                            

Getting Help :

  'man' command     'apropos' command    whatis    info command    /usr/doc/* (or /usr/share/doc/*) - By typing the first few characters of a command, you can see posibilites by pressing 'tab' key 2 times Any operation can be found by 'apropos' command and learned by 'man' command described above. linux documentation project reference

Uninstall/installing packages:

  To remove package called mplayer, enter:   $ sudo apt-get remove mplayer

Uncompressing content of a file :

tar -xvzf Komodo

make a program from its source files:

sh ./configure

Directory operations ::

ls to list - the names of the directories and files in the current directory cp -r dir1 dir22 - to copy all contents of dir1 to dir2 recurcievly rm -f -r {file-name} - To remove a file or directory
Where, -f: Forcefully remove file and -r: Remove the contents of directories recursively linux permissions

SYSTEM INFORMATION

uname -a  Display Linux system information
uname -r Display kernel release information
cat /etc/redhat-release Show which version of redhat installed
uptime Show how long the system has been running + load
hostnameShow system host name
hostname -I Display the IP addresses of the host
last reboot Show system reboot history


Show the current date and time

date

Show this month's calendar

cal

Display who is online

w

Who you are logged in as

whoami

HARDWARE INFORMATION

Display messages in kernel ring buffer

dmesg

Display CPU information

cat /proc/cpuinfo

Display memory information

cat /proc/meminfo

Display free and used memory ( -h for human readable, -m for MB, -g for GB.)

free -h

Display PCI devices

lspci -tv

Display USB devices

lsusb -tv

Display DMI/SMBIOS (hardware info) from the BIOS

dmidecode

Show info about disk sda

hdparm -i /dev/sda

Perform a read speed test on disk sda

hdparm -tT /dev/sda

Test for unreadable blocks on disk sda

badblocks -s /dev/sda

PERFORMANCE MONITORING AND STATISTICS

Display and manage the top processes

top

Interactive process viewer (top alternative)

htop

Display processor related statistics

mpstat 1

Display virtual memory statistics

vmstat 1

Display I/O statistics

iostat 1

Display the last 100 syslog messages (Use /var/log/syslog for Debian based systems.)

tail 100 /var/log/messages

Capture and display all packets on interface eth0

tcpdump -i eth0

Monitor all traffic on port 80 ( HTTP )

tcpdump -i eth0 'port 80'

List all open files on the system

lsof

List files opened by user

lsof -u user

Display free and used memory ( -h for human readable, -m for MB, -g for GB.)

free -h

Execute "df -h", showing periodic updates

watch df -h

USER INFORMATION AND MANAGEMENT

Display the user and group ids of your current user.

id

Display the last users who have logged onto the system.

last

Show who is logged into the system.

who

Show who is logged in and what they are doing.

w

Create a group named "test".

groupadd test

Create an account named john, with a comment of "John Smith" and create the user's home directory.

useradd -c "John Smith" -m john

Delete the john account.

userdel john

Add the john account to the sales group

usermod -aG sales john

5 – FILE AND DIRECTORY COMMANDS

List all files in a long listing (detailed) format

ls -al

Display the present working directory

pwd

Create a directory

mkdir directory

Remove (delete) file

rm file

Remove the directory and its contents recursively

rm -r directory

Force removal of file without prompting for confirmation

rm -f file

Forcefully remove directory recursively

rm -rf directory

Copy file1 to file2

cp file1 file2

Copy source_directory recursively to destination. If destination exists, copy source_directory into destination, otherwise create destination with the contents of source_directory.

cp -r source_directory destination

Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2

mv file1 file2

Create symbolic link to linkname

ln -s /path/to/file linkname

Create an empty file or update the access and modification times of file.

touch file

View the contents of file

cat file

Browse through a text file

less file

Display the first 10 lines of file

head file

Display the last 10 lines of file

tail file

Display the last 10 lines of file and "follow" the file as it grows.

tail -f file

PROCESS MANAGEMENT

Display your currently running processes

ps

Display all the currently running processes on the system.

ps -ef

Display process information for processname

ps -ef | grep processname

Display and manage the top processes

top

Interactive process viewer (top alternative)

htop

Kill process with process ID of pid

kill pid

Kill all processes named processname

killall processname

Start program in the background

program &

Display stopped or background jobs

bg

Brings the most recent background job to foreground

fg

Brings job n to the foreground

fg n

FILE PERMISSIONS

Linux chmod example PERMISSION EXAMPLE U G W rwx rwx rwx chmod 777 filename rwx rwx r-x chmod 775 filename rwx r-x r-x chmod 755 filename rw- rw- r-- chmod 664 filename rw- r-- r-- chmod 644 filename

NOTE: Use 777 sparingly! LEGEND U = User G = Group W = World r = Read w = write x = execute - = no access

NETWORKING

Display all network interfaces and ip address

ifconfig -a

Display eth0 address and details

ifconfig eth0

Query or control network driver and hardware settings

ethtool eth0

Send ICMP echo request to host

ping host

Display whois information for domain

whois domain

Display DNS information for domain

dig domain

Reverse lookup of IP_ADDRESS

dig -x IP_ADDRESS

Display DNS ip address for domain

host domain

Display the network address of the host name.

hostname -i

Display all local ip addresses

hostname -I

Download http://domain.com/file

wget http://domain.com/file

Display listening tcp and udp ports and corresponding programs

netstat -nutlp

ARCHIVES (TAR FILES)

Create tar named archive.tar containing directory.

tar cf archive.tar directory

Extract the contents from archive.tar.

tar xf archive.tar

Create a gzip compressed tar file name archive.tar.gz.

tar czf archive.tar.gz directory

Extract a gzip compressed tar file.

tar xzf archive.tar.gz

Create a tar file with bzip2 compression

tar cjf archive.tar.bz2 directory

Extract a bzip2 compressed tar file.

tar xjf archive.tar.bz2

INSTALLING PACKAGES

Search for a package by keyword.

yum search keyword

Install package.

yum install package

Display description and summary information about package.

yum info package

Install package from local file named package.rpm

rpm -i package.rpm

Remove/uninstall package.

yum remove package

Install software from source code.

tar zxvf sourcecode.tar.gz cd sourcecode ./configure make make install

SEARCH

Search for pattern in file

grep pattern file

Search recursively for pattern in directory

grep -r pattern directory

Find files and directories by name

locate name

Find files in /home/john that start with "prefix".

find /home/john -name 'prefix*'

Find files larger than 100MB in /home

find /home -size +100M

SSH LOGINS

Connect to host as your local username.

ssh host

Connect to host as user

ssh user@host

Connect to host using port

ssh -p port user@host

FILE TRANSFERS

Secure copy file.txt to the /tmp folder on server

scp file.txt server:/tmp

Copy *.html files from server to the local /tmp folder.

scp server:/var/www/*.html /tmp

Copy all files and directories recursively from server to the current system's /tmp folder.

scp -r server:/var/www /tmp

Synchronize /home to /backups/home

rsync -a /home /backups/

Synchronize files/directories between the local and remote system with compression enabled

rsync -avz /home server:/backups/

DISK USAGE

Show free and used space on mounted filesystems

df -h

Show free and used inodes on mounted filesystems

df -i

Display disks partitions sizes and types

fdisk -l

Display disk usage for all files and directories in human readable format

du -ah

Display total disk usage off the current directory

du -sh

DIRECTORY NAVIGATION

To go up one level of the directory tree. (Change into the parent directory.)

cd ..

Go to the $HOME directory

cd

Change to the /etc directory

cd /etc

Linux Commands

Linux commands are not part of the shell. 
Each one is a seperate executable program, probably written in the C programming language. These executables are stored in various directories set up for binary files, such as /bin and /usr/bin. The location of these directories can be defined with the $PATH variable so the shells know where to find them. These commands vary between different linux distrubutions, and remain the same whichever shell you are using.

grep

grep prints the lines from a file or input stream that match an expression. For example, if you want to print the lines in the /etc/passwd file that contain the text root, use this command: grep root /etc/passwd The grep command is extraordinarily handy when operating on multiple files at once, because it prints the filename in addition to the matching line when in this multiple-file mode. For example, if you want to check on every file in /etc that contains root, you could use this command: grep root /etc/*

more and less

When a command's output is long, it can scroll off the top of the screen, and it's annoying to use a scrollbar to view such output because you have to move your hands around. You sometimes may also want to look at a large text file without starting a text editor. Two standard commands for text navigation are more and less. To page through a big file like /usr/dict/words, use a command such as more /usr/dict/words. When running more, you will see the contents of the file, one screenful at a time. You can press the space bar to go forward in the file and the b key to skip back one screenful. To quit more, type q. The less command performs the same function as more, but it is far more powerful and widely used. Use less --help to get a good summary of its operations. As you will learn in Section 1.14, you can send the output of nearly any program directly to another program's input, enabling operations such as this (try it to see what it does): grep ie /usr/dict/words | less

pwd

This program's name stands for "print working directory," and the command outputs the current working directory. That's all that pwd does, but it's useful. Some Linux distributions set up accounts with the current working directory in the prompt, but you may wish to change that because the current working directory takes up a lot of space on a line.

diff

To see the differences between two text files, use diff:

diff file1 file2

There are several options that can control the format of the output, such as -c, but the default output format is often the most comprehensible (for human beings, that is).

file

If you see a file and are unsure of its format, try using file to see if the system can guess, based on a large set of rules: file file You may be surprised to see how much this innocent-looking command can do.

find

It's frustrating when you know that a certain file is in a directory tree somewhere, and you just don't know where. Run find to find file in dir:

find dir -name file -print

Like most programs in this section, find is capable of some fancy stuff. However, don't try options such as -exec before you know the form shown here by heart, and you know why you need the -name and -print options. The find command accepts wildcard characters, such as *, but you must enclose them in single quotes ('*') to protect the wildcard characters from the shell's own wildcard features

head and tail

To quickly view a portion of a file or stream, use the head and tail commands. For example, head /etc/inittab shows the first ten lines of this system configuration file, and tail /etc/inittab shows the last ten lines. You can change the number of lines to print by using the -n option, where n is the number of lines you want to see. If you want to print lines starting at line n, use tail +n.

sort

The sort command quickly puts the lines of a text file in alphanumeric order. If the file's lines start with numbers, and you want to sort in numeric order, use the -n option. The -r option reverses the order of the sort.