Linux came from a Unix family, Linux is a free and open-source software operating system, which Linus Torvalds developed in September 1991.
In 1991, Linus Torvalds was a student at the University of Helsinki, Finland, USA.
He developed the first code of Linux 0.01 and post it on the Minix newsgroup on 17 Sep 1991, his code become so popular people encouraged him to develop new code and he was led to develop new code and release the first "official" version of Linux, version 0.02 on October 5, 1991.
Today many year pass and Linux become one of the most popular operating systems. Today 90% fastest Supercomputers out of 500 run on Linux variants including the top 10.
In Linux everything is represented as a file including a hardware program, the files are stored in a directory, and every directory contains a file with a tree structure. That is called File System Hierarchy.
Linux uses single rooted, inverted tree-like structure.
Root Directory represents with / (forward slash) It is a top-level directory in Linux.
The base of the Linux directory is the root. This is the starting point of FSH. Every directory arises from the root directory. It is represented by a forward slash (/).
If someone says to look into the slash directory, they refer to the root directory.
It is the home directory for the root user (superuser).
- Contains binary executable.
- Common Linux commands you need to use in single-user modes are located under this directory.
- Commands used by all the users of the system are located here.
Just like /bin, /sbin also contains binary executables.
But, the linux commands located under this directory are used typically by system aministrator, for system maintenance purpose.
For example: iptables, reboot, fdisk, ifconfig, swapon
- it contains hardware device files,
- Contains device files.
- These include terminal devices, usb, or any device attached to the system.
For example: /dev/tty1, /dev/usbmon0
The variable data files such as log files are located in the /var directory.
File contents that tend to grow are located in this directory.
This includes
- /var/log: System log files generated by OS and other applications.
- /var/lib: Contains database and package files.
- /var/mail: Contains Emails.
- /var/tmp: Contains Temporary files needed for reboot.
This directory is used to mount a file system temporarily.
The /media directory contains subdirectories where removable media devices inserted into the computer are mounted.
The /usr directory contains applications and files used by users, as opposed to applications and files used by the system.
It contains all configuration files of server
The core configuration files are stored in the /etc directory. It controls the behavior of an operating system or application. This directory also contains startup and shutdown program scripts that are used to start or stop individual programs.
The /boot directory contains the files needed to boot the system — for example, the GRUB boot loader's files and your Linux kernels are stored here.
The opt directory is used for installing the application software from third-party vendors that are not available in the Linux distribution. Usually, the software code is stored in the opt directory and the binary code is linked to the bin directory so that all users can run that software.
It contains secondary users home directory.
Directory that contains temporary files created by system and users.
Files under this directory are deleted when system is rebooted.
#pwd → it shows the present working directory
#ls → it shows available files and directory list in the present working directory.
#uname → it shows the name of the kernel (OS)
#uname -r → it shows version of the kernel
#cd → it use for change directory
#clear → it use for clear screen
#whoami → it show currently login user name
#history → it show list of previously used commands
#date → it show time and date1. For create single directory
mkdir directory_name2. For create multiple directory
mkdir dir1 dir2 dir33. For create directory path (directory inside directory)
mkdir -p parent/child/grandchild4. For create number of directory
mkdir dir{1..10}Touch command is use for create empty file, we can't write data in a file, can't edit or save file.
1. Create single file with touch command
touch filename2. Create multilpe file
touch file1 file2 file33.Create number of files
touch file{1..10}cp command is used for copy and paste file or directory
Syntax:
#cp <option> <source> <destination>Options
- -r for recursive
- -v for verbose
- -f for forcefully
1. For copy file
cp source_file destination2. For copy all data which start form D alphabet
cp D* destination1. For delete file or directory
rm filename
rm -r directory_name1. For move file or directory
mv source destination2. For rename file or directory
mv old_name new_nameuseradd usernameid usernamepasswd usernamechage -l usernamesu usernamesu - usernameexitOr
logoutuserdel usernameusermod -l new_name old_nameA group is a collection of user accounts that is very use full to administrators for managing and applying permission to a number of users.
groupadd groupnamegetent group groupnamegpasswd -A admin_user groupnamegroupdel groupnamegpasswd -a username groupnamegpasswd -M user1,user2,user3 groupnamegpasswd -d username groupnamegpasswd -A username groupname- Basic Permission
- Special Permission
- Access Control List (ACL) Permission
ls -l filename| Permission | Link | Owner | Group owner | Size of file | Date & time of file creation | Name of file |
|---|
ls -ld directory_name- Owner (u) → Permissions used for the owner of the file
- Group (g) → Permissions used by members of the group
- Other (o) → Permissions used by all other users
| Permission | Description |
|---|
- Basic Permission
- Special Permission
- Access Control List (ACL) Permission
chmod u+r filenamechmod g+rw filenamechmod o-r filenameSyntax:
chown new_owner filenameSyntax:
chgrp new_group filename- r (read) = 4
- w (write) = 2
- x (execute) = 1
chmod 755 filenameAccess control list (ACL) provides an additional, more flexible permission mechanism for file systems.
Access control list is a service which is used for providing special permission to specific users and group to particular directories and file
Think of a scenario in which a particular user is not a member of group created by you but still you want to give some read or write access, how can you do it without making user a member of group, here comes in picture Access Control Lists, ACL helps us to do this trick.
Syntax:
getfacl filenamesetfacl -m u:username:permissions filenamesetfacl -x u:username filenamesetfacl -m g:groupname:permissions filenamesetfacl -x g:groupname filenamesetfacl -b filenameRegular expressions are special characters which help search data, matching complex patterns.
The grep filter searches a file for a particular pattern of characters, and displays all lines that contain that pattern.
grep "string" filenamegrep "string" file1 file2 file3grep -i "string" filenamegrep -r "string" directorygrep -v "string" filenamegrep -c "string" filenamegrep -l "string" *.txtgrep -L "string" *.txtgrep -n "string" filenamegrep "^string" filenamegrep "string$" filenamegrep "string" filename > newfileThe Linux Find Command is one of the most important and much used command in Linux systems.
Find command used to search and locate the list of files and directories based on conditions you specify for files that match the arguments.
Find can be used in a variety of conditions like you can find files by permissions, users, groups, file type, date, size, and other possible criteria
find /home -name filenamefind / -perm -4000find / -perm -2000find / -perm -1000find / -user usernamefind / -group groupnamefind /path -size -10Mfind /path -size +10MThe wc command is use for the count word and line numbers.
wc -l filenamewc -w filenameHead command is used for to display top line of the file.
head filenamehead -n 5 filenameTail command is used for to display the bottom line of the file.
tail filenametail -n 5 filenameThe Linux "tar" stands for tape archive, which is used by large number of Linux/Unix system administrators to compress size or drives backup. For create archive tar used some compression algorithms Such as gzip,bz2 and xz
Archiving is the process of combining multiple files and directories (same or different sizes) into one file. Archive process is very useful for backup and compression size of data in Linux.
#tar <options> <files>- c -for create
- x -for extract
- v -for verbose
- f -for forcefully
- t -for test
- z -for gzip
- j -for bz2
- J -for xz
- C -for specific destination
tar -cvf archive.tar files/ls -lh archive.tartar -xvf archive.tartar -xvf archive.tar -C /path/to/destination/tar -czvf archive.tar.gz files/tar -xzvf archive.tar.gztar -cjvf archive.tar.bz2 files/tar -xjvf archive.tar.bz2tar -cJvf archive.tar.xz files/tar -xJvf archive.tar.xzJob automation allows us to perform tasks automatically in OS by using tools.
This feature is very useful for the administrator to assign tasks to OS whenever he is not present or performing daily basis work.
- at — command is used to execute a job only one time.
- crontab — Crontab command is used to execute a job multiple times.
at timeatqatrm job_numberecho "username" >> /etc/at.denysystemctl start crondsystemctl enable crondcrontab -ecrontab -lcrontab -rOr,
Go to the crontab file and remove the job line
crontab -u username -ecrontab -u username -lecho "username" >> /etc/cron.denysudo ("superuser do", or "switch user do") allows a user with proper permissions to execute a command as another user, such as the superuser.
sudo allows a permitted user to execute a command as another user, according to specifications in the /etc/sudoers file.
# vim /etc/sudoers# vim /etc/sudoers
root ALL=(ALL) ALL
amir ALL=(ALL) ALL (add this line appro. 101 lines)
:wqFor edit configuration file:
# vim /etc/sudoers
%punegrp ALL=(ALL) ALL (line number 108)
:wqBy default, all members of punegrp group got sudo privileges
Wheel is a system group that by default has sudo privileges, if we add any member to that group then that user got sudo privilege
#grep wheel /etc/group
#useradd shub
#passwd shub
#gpasswd –a shub wheelBy default, all members of the wheel group got sudo privileges
For edit configuration file:
# vim /etc/sudoers
amir ALL=(ALL) NOPASSWD: ALL
%punegrp ALL=(ALL) NOPASSWD: ALL
:wqip aOr,
ifconfigNetwork Manager is a daemon that monitors and manages network settings.
nmcli command used to manage networking
nmcli con shownmcli con shownmcli con show --activenmcli con show "connection_name"nmcli dev statusnmcli con add type ethernet con-name "citynet" ifname ens33#nmcli con mod "citynet" ipv4.add 192.168.0.100
#nmcli con mod "citynet" gw4 192.168.0.254
#nmcli con mod "citynet" ipv4.dns 192.168.0.254
#nmcli con down citynet
#nmcli con up citynet
#nmcli con show — active
#nmcli con show citynetnmcli con up "connection_name"nmcli con down "connection_name"nmcli con up "new_connection"
nmcli con down "old_connection"nmcli con delete "connection_name"nmcli con del "connection_name"hostnamectl set-hostname new_hostnamehostnamenmtuiAll created connections with nmcli and nmtui by default are stored in the following file
/etc/sysconfig/network-scripts/
We can also modify the connection using the above connection file, but it not recommended.
If update the file, restart NetworkManager service to update IP-configuration
systemctl restart NetworkManager