Linux Lpic 1
INFO : This is not a book for you to pass the exam, this is just my notes and summary for the exam, which you can use this manuscript to practice and remember the material after reading the main sources (I will introduce two of the books below). do. In this book, I try to put some important parts serially but separately, so that the topics I am most involved with can be provided to you in separate parts.
Book1 : LPIC-1 Linux Professional Institute Certification Study Guide
Book2 : https://linux1st.com/archives.html
Note:This book is written by Jadi Mirmirani, which is an online book that Jadi also has complete training videos of Linux. A Note about Jadi: Jadi is someone who has inspired many people who are working in the field of IT in Iran. I also know that I am indebted to Jadi and I hope that one day I will be able to compensate.
Book3 : Lpic-1 Study Guide by Borosan :http://linuxcert.ir
Hardware Setting
=> lsusb
= list of usb devices
=> lsblk
= list of all block devices
=> lspci
= which devices connect via pci
=> lsmod
=> all loded modules with kernel
for removing modules of kernel modes :
=> rmmode
for Loading modules Recursively:
=> modprobe
=> cat /etc/modules
=> cat /etc/modprobe.d
cat /proc/mounts = mounts
=> mount
use Flash Disk and hard disks by uuid :
=> blkid
Boot the System
Grub config :
cat /etc/grub/grub.cfg
show logs until system bootup:
dmesg
show log files in Debian and RedHat:
=> RedHat: cat /var/log/messsages
=> Debian: cat /var/log/syslog
change runlevel & shutdown & boot the system
runlevels
0 : Halt 1 : single mode user(recovery) 2 : Debain/ubuntu(default) 3 : RedHat/Fedora/suse(text mode) 4 : free 5 : RedHat/Fedora/suse(Graphical mode) 6 : reboot
To change the run level:
=> telinit 5
NOTE : variable services are in /etc/init.d directory and we can start and stop this services with init.d for for Example:
sudo /etc/init.d/sendmail stop
or
sudo systemctl sendmail stop
or
sudo service sendmail stop
shutdown
=> shutdown -r 2 Going Down for fun
-r : reboot 2 : minutes Going Down for fun : message
=> sudo shtdown -c
-c : cancle
Disk and Hard Layout
/boot
/etc
/mnt
/media
/opt
/dev
/sbin
/srv
/tmp
/usr
/var
install boot manager
grub2 install /dev/sda
grub-install --help
Note: if i have'nt any config for grub i should use this commmand for creating config
=> sudo grub2-mkconfig --version
=> sudo grub2-mkconfig
Note : We use the following command to create the config file for Grub
=> sudo grub2-mkconfig -o <FILE_PATH>
Note:you want to save the generated GRUB 2 configuration to a file grub.cfg in your user’s HOME directory. To do that, run the following command:
=> sudo grub2-mkconfig -o ~/grub.cfg
Updating GRUB 2 Configuration File (BIOS):
Note:configuration file should be in the /boot/grub/grub.cfg file,To update the GRUB 2 configuration file on BIOS based Linux installation, run the following command:
=> sudo grub2-mkconfig -o /boot/grub/grub.cfg
Note : If you’re expecting any changes, restart your computer with the following command:
=> sudo reboot
Manage Shared Liberary
How install ldd command:
=> sudo apt-get install libc-bin
Find ldconfig file ant which liberaries
=> ldd /sbin/ldconfig
Find ls want witch liberaries with verbose switch
=> ldd -v /bin/ls
=> ldd /usr/bin/find
=> ldd -v /usr/bin/find
in 64bit systems directory is:
=> cd /lib64
and for 32bit systems:
=> cd /lib
For create speedy cash of Liberary
=> sudo ldconfg -v
or => sudo ldconfig -p
This see /usr/bin/ls liberaries needed and then Try to load it and then run command ls.
=> /usr/lib64/ld-linux-x86-64.so.2 /usr/bin/ls
Note: we have command to see what is in ELF Files and show Them
readelf -Wl /usr/bin/ls
package management
Debian:
Important Note: In Debian systems we have File in /etc/apt/sources.list and This File can Set which Types of apps or Repo Update. You can Remove apps update and save Securites.for example in Telecommunication systems They Remove applications Update and save just Security Updates.You can Edit This with /etc/'apt/sources.list
=> cd /etc/apt/source.list
Important Note2: For the software you developed and want to add it to the repositories from the command
=> vi /etc/apt/sources.list.d/KYGnus.list
deb http://www.github.com/KooshaYeganeh jammi KYGNus-AV
Package Managers
Debian:
dpkg_reconfig
apt-get
apt_catch
aptitude
apt-get dist-upgrade
update catch and upgrdae packages:
=> sudo apt get update
=> sudo apt-get upgrade
Simulation mode: =>
sudo apt-get install -s <package name>
Downloading: Note : Just Download not install =>
sudo apt-get install --downloading <package name>
Install: =>
sudo apt-get install <package Name>
Remove: =>
sudo apt-get remove <packageName>
Remove Dependancy: =>
sudo apt-get autoremove <packageName>
Search: =>
sudo apt-get search <packageName>
Reconfig packages: =>
sudo dpkg-reconfig <packageName>
See content of .deb file: =>
sudo dpkg --contents (file.deb>
Status of .deb File: =>
sudo dpkg -s <file.deb>
all information for package: =>
sudo dpkg --purge <filename>
RedHat:
yum update
Upgrade a package using the yum command
yum upgrade
Install software with yum
yum install zsh
Reinstall Package
yum reinstall zsh
Search for software packages
yum search zsh
Uninstall Software with yum
yum remove zsh
List information about a package
yum info zsh
looking for a library for some software that have downloaded and need to know the name of the package which provides a particular file:
yum provides "zsh"
List installed software packages:
yum list installed
yum localinstall KYGnusAV.rpm
yum deplist ansible
View Complete YUM History
yum history
yum upgrade "cal*"
yum info vim
RPM Files (RedHat Package Manager)
How to Check an RPM Signature Package:
rpm --checksig pidgin-2.7.9-5.el6.2.i686.rpm
Install an RPM Package:
rpm -ivh pidgin-2.7.9-5.el6.2.i686.rpm
check dependencies of RPM Package before Installing
rpm -qpR BitTorrent-5.2.2-1-Python2.4.noarch.rpm
Remove a RPM Package
rpm -evv nx
Get the Information of RPM Package Before Installing
rpm -qip sqlbuddy-1.3.3-1.noarch.rpm
Verify a RPM Package:Verifying a package compares information of installed files of the package against the rpm database.
rpm -Vp sqlbuddy-1.3.3-1.noarch.rpm
Verify all RPM Packages
rpm -Va
rpm -q --configfiles
Virtualization
sudo lsmod | grep -i kvm
for Detecting Os Running on Hypervisor:
=> cat /proc/cpuinfo | grep -w hypervisor
Type2 => HardWare -> OS -> Hypervisor -> OS type1 => HardWare -> Hypervisor -> OS
History
=> history
!!
: Run Latest command
!echo
: It executes the last command that was echo inside
history 20
: It shows the last 20 commands
stdin,stdout
sort
=> sort koosha.txt
-od : octal dump - od Ad koosha.txt : this show decimal - od Ah kosha.tct : this show Hexadecimal - od Ad -c koosha.txt : this show characeters - od koosha.txt
split
split -l5 mydata
wc (1) (2) (3)
1-line 2-word 3-character
cat -n koosha.txt : show files with line
uniq : Removes duplicates Note : This command works when the input is sorted
sort koosha.txt | uniq
cut
cut -d":" -f2 koosha.txt
join : Join files together
join koosha.txt and hamed.txt
sed
=> sed 's/A/B/' koosha.txt
=> sed 's/a/A/g' koosha.txt
=> sed 's/hamed/omid is brother/g' koosha.txt
=> ser -r 's/^H/K/g' Frineds.txt
Some Useful Commands
=> tail -f /var/log/syslog
cp
f : force
i : interact
b : backup and copy
p : setting of date and accessiblity
ls
f?
[abc]*
[ab]*
f*
compressing - zip - zip : gzip koosha.txt - unzip : gumzip koosha.txt
clone
=> dd if=/dev/sdb of=/dev/sdc bs=4M
Create,monitor,kill process
=> jobs
=> bg
=> fg
=> kill -9 systemd
or
kill -15 systemd
=> kill 16060
#190160is proccess id
Serach with Regex
egrep
=> egrep "(abc)" friends
=> egrep "(a|b|c)" friends
=> egrep ".a" friends
=> egrep "^.a" friends
sed
=> sed "s/a/b/" friends
=> sed -r "s/^a/b/" friends
Devices
=> ls /dev/sd[a-z]*
=> fdisk -l /dev/sdb1
=> mkfs.ntfs /dev/sdb1
Get information of block Device:
=> blkid /dev/sdb1
GPT = guid Partition Table
=> gdisk /dev/sdb1
Check filesystem
du df fsck e2fsck mke2fsck debugfs
=> ls /sbin/*fsck*
check all system File:
=> fsck -A
check specific system file
=> fsck /dev/sdb1
check by uuid
=> fsck UUID=""
fsck
-A –> Used for checking all filesystems. The list is taken from /etc/fstab.
-C –> Show progress bar.
-l –> Locks the device to guarantee no other program will try to use the partition during the check.
Repair Linux Filesystem Errors:
you may want fsck to automatically attempt to correct the errors:
=> fsck -y /dev/sdb
Similarly, you can ran the same on all filesystems (without root):
=> fsck -AR -y
tune2fs
tune2fs - View Filesystem Information: =>
tune2fs -l /dev/sdb1
Display Filesystem Volume Name: =>
tune2fs -l /dev/sdb1 | grep volume
Change Filesystem Volume Name: Using the "-L" parameter, we can give add/change the filesystem volume name. =>
tune2fs -L Disk_One /dev/sdb1
=>tune2fs -l /dev/sdb1 | grep volume
Displaying Filesystem Check Intervals and Mount Counts:
=> tune2fs -l /dev/sda1 | grep interval
df : disk free
=> df -H
: Human readable
=> df -TH
: type Human Readable
=> df -i
: inode
=> df -ih
: inode human readable
du : disk usage
=> du -h
: human readable
=> du -H
: human readable
=> du -c
: show grant total
=> du -s
: summery
Repairing
=> debugfs /dev/sda2
mount & umount
View All the mount information in Linux: =>
mount
Simple mount: =>
mount /dev/sdb1 /tmp/koosha
=>umount /tmp/koosha
mount all the filesystem of /etc/fstab:
=> mount -a
=> cat /etc/fstab
Remount a mounted Filesystem in Linux:
=> mount -o remount,rw /dev/sdc1
Mount an ISO Image in Linux
=> mount -o loop CentOS.ISO /mnt/iso
Perform Lazy Unmount in Linux:
=> umount -l /dev/sdc1
Check all the mounting information of a Specific Filesystem:
=> mount -t tmpfs
Forcefully unmount a Partition Using umount command:
=> umount -f /dev/sdc1
mount an NFS Partition in Linux:
=> mount -t nfs 192.168.0.108:/mnt/nfs /nfsclient
Manage disk Quotas
Enabling Quota:
usrquota quota grpquota
1- first add quota to /etc/fstab file
for example add usrquota to file /etc/fstab:
uuid "" /boot ext4 defaults.usrquota
2- reboot
3- cd /boot
4- quotacheck -a
check quota for special user:
=> quotacheck -u -a -m -v
5-quotaon -auv
6- edquota -u koosha
blocks is 1k all system get inode soft : just get warning hard : don'y allow to up from that
Note : in Quota you add number of files and usage of files Number of files get afeter of inode and usage of files are get before of inode
copy koosha's Quota to newuser
=> edquota -p koosha amin farhad
get report of all Quota's
=> repquota -u -a
Manage file permissions and ownership
=> whoami
=> groups
=> id
=> cat /etc/group
=> cat /etc/group | grep root
Note : in fedora and redhat root name is wheel
chmod:
sample File in linux.txt
=> chmod u+x linux.txt
=> chmod u+w linux.txt
=> chmod u-x linux.txt
=> chmod u-r linux.txt
=> chmod ug+x linux.txt
=> chmod ugo+wxr linux.txt
=> chmod u=rw linux.txt
=> chmod u=rw,g=rw,o=r linux.txt
rwx = 7 rw- = 6 r-x = 5 r-- = 4 -wx = 3 -w- = 2 --x = 1 --- = 0
suid =>
sudo chmod u=rwxs,g=rx,o=r koosha.txt
-rwsr-xr--. 1 koosha koosha 0 نوامبر 20 15:13 koosha.txtguid =>
sudo chmod g+s project
drwxr-sr-x. 2 koosha koosha 4096 نوامبر 20 15:17 projectsticktbit
Note: if set stickybit of directory , each people can remove his own file
=> sudo chmod o+t project
chown
=> chown koosha:koosha linux.txt
=> chown koosha:root linux.txt
=> chown root:root linux.txt
=> chown koosha:adm linux.txt
=> chown -R koosha:koosha /tmp/project
chgrp (change group)
=> chgrp koosha linux.txt
Simbolik Links
Note : if edit koosha.txt linux.txt file will be edit.
=> ln koosha.txt linux.txt
=> unlink koosha.txt linux.txt
softlink
=> ln -s koosha.txt hamed.txt
=> ln -s kooshadir hameddir
Manage user and gropus
User => useradd koosha
=> passwd koosha
Group
=> groupadd Developers
=> groupdel Developers
add peyman to wheel group
=> useradd -aG wheel peyman
change name of peyman user:
=> usermod -c "Delphi" peyman
change shell of hamed
=> usermod -s /bin/zsh hamed
lock user:
=> usermod -L hamed
unlock user:
=> usermod -U hamed
delete user:
=> userdel hamed
read information data of password of users human redable => chage -l koosha
crontab
=> crontab -e : edit => crontab -l : list
timezone
=> cd /usr/share/zoneinfo
=> cat /etc/localtime
=> locale
=> sudo hwclock -v
: Vebose
=> date
=> date -s
sudo hwclock -u -w
u : set utc
w : sync with system time
cat /etc/rsyslog.conf
facilites : whatis in my home? priorieties : panic/emerg,alert,crit,err/error,warn/warning,notice,info,debug actions : filename or username or ip
example: kern.panic @192.168.1.100 exapmle : kern.panic jadi example : * * /var/log/messages
=> cat /etc/systemd/journald.conf
logger local.info koosha is linux user logger local.warning linux is best
logrotate
=> vi /etc/logrotate.conf
به امید ازادی جادی عزیز
Last updated