- mount - Mount a filesystem if ran without options, it will display currently mounted filesystem
- umount - Unmount a filesystem
find a filesystem. will display mounted filesystem information in a tree view by default
Filesystem commands:
- df - display filesystem disk usage. display the filesystem, mount point, and utilization detials
- lsblk - list block devices. Display information about block storage devices, including the devices size and any mounted filesystem. display colums can be customized
- blkid - list block devices. Display information about blocl storage devices, including the device size. and any mounted filesystem. Display
- /etc/fstab system file that contains information about file tthat are available for the opOS to mount at startup
$type mv
It is equivalent to man command with -k option
$chsh --shell /bin/sh satish
$vi /etc/passwd
echo $PS1
\d : the date in "Weekday Month Date" format (e.g., "Mon May 04")
\t : the current time in 24-hour HH:MM:SS format
\w : the current working directory, with $HOME abbreviated with a tilde
$lspci
$ lshw
$systemctl set-default multi-user
- lsmem lists memory blocks and their state; these reflect physical memory and are counted in units of memory blocks, i.e. 128MiB on your system. To do this, lsmem reads information made available by the kernel in /sys/devices/system/memory. On your system, the kernel tracks 64 memory blocks for a total of 8GiB.
- free lists memory that’s usable by the system; “total” is the amount of physical memory, minus memory reserved by the system (for the firmware’s purposes mostly) and the kernel’s executable code. free reads this information from /proc/meminfo.
- The difference in output is explained by this difference in what is measured. In all cases, free’s total memory will be smaller than lsmem’s total online memory.
$hostnamectl set-hostname NAME
$cat missing_file 2>> error.txt
$cat missing_file 2> /dev/null
$echo $SHELL | tee shell.txt
$echo $SHELL | tee -a shell.txt
curl command in Linux :
tr
uniq command in Linux :
sort command in Linux :
date command in Linux:
Set timezone in Linux:
$ timedatectl list-timezones
$sudo timedatectl set-timezone Asia/Kolkata
Create a user with non interactive shell.
Linux Access Control List:
ACL gives you flexibility and grenular level permission technique to manage file systems.
## Now suppose you don't want user pankaj to have access to PRE-PROD folder
## you only want vikas to access it
$ cd /home/root
$ getfacl PRE-PRD
## add permission to specific user
$ setfacl -m "u:pankaj:rwx" /home/root/PRE-PROD
## for group
$ setfacl -m "g:pankaj:rwx" /home/root/PRE-PROD
$ setfacl -m "u:vikas:---" /home/root/PRE-PROD
Create a user with expiry date:
$ chage -l pankaj
## set expiry of the account
$ chage -E "2022-07-15" pankaj
## set number of days to expiry
$ chage -M 120 pankaj
SELINUX installation:
$ sestatus
$ cat /etc/selinux/config | grep SELINUX
$ cat /etc/selinux/config
SELINUX=disabled
$cat /etc/selinux/config | grep SELINUX
$sestatus
Create Group in Linux :
$sudo useradd -m -d /users/username -s /bin/bash -g sysadmin -G wheel username
$sudo useradd -u 1098 -d /users/username -s /bin/bash -g sysadmin -G wheel -m usernameChange user home directory, Primary Group, Shell, UID and GID:
$usermod -g sysadmin username
$usermod -s /bin/ksh username
$usermod -u 666 -g 777 username
Create User in Linux by Specifying Home Directory, Primary group, Secondary group, Shell :
$sudo useradd -m -d /users/username -s /bin/bash -g sysadmin -G wheel usernameChange user home directory, Primary Group, Shell, UID and GID:
$usermod -g sysadmin username
$usermod -s /bin/ksh username
$usermod -u 666 -g 777 username
See the user information:
killall command in Linux - To kill running process with the given name
killall PROCESS_NAME || echo "print this if Process was not running"Synchronize Time on Linux Machine using Network Time Protocol (NTP) service:
#Add ntp server details in this file /etc/ntp.conf
cat /etc/ntp.conf
server ntp_server.domain.com
See the file type of a file/directory:
#-s, --special-files
$file -sL /dev/sda1
$file file_names
$file directory_name/*
cut command in Linux:
cut is mainly used when you want to cut a part of a line based on some delimiter and send that data to standard output using pipe(| ) command.
hello amit
world in
java point
$cut -c 3 file.txt
l
r
v
$cut -b 1,2,3 file.txt
hel
wor
jav
$cat file.txt | cut -d " " -f 1 | sort -r
world
java
hello
$cat file.txt | head -n 2
hello amit
world in
$cat file.txt | tail -n 2
world in
java point
sdiff or vimdiff command in Linux:
When you want to compare file side by side we use sdiff command.
and when you want to only see the differ lines then use it with -s parameter
$sdiff file1.txt file2.txt
$sdiff -s file1.txt file2.txt
$vimdiff file1.txt file2.txt echo command to write a file:
tee command in Linux:
tee is very useful when you want to read the data on standard output and also want to write data to a file.
$df -h | tee disk_info_usage.txtcat command in Linux to write a file:
> My Name is satish kumar
> I am 21 years old
> I am from Mumbai
> EOF
$ cat newfilename.txt
My Name is satish kumar
I am 25 years old
I am from Mumbai
When do we use colon (:-) in bash variable:
This will set the default variable value as '' if you are not providing any value to then either by declaring or by passing argument.
export USER_NAME=$(username:-'')
rsync = remote synchronization
ssh deamon must be running
## Reverse
$rsync -a satish@1.2.34.4:/home/satish Pictures/
## Local
$ rsync -a Pictures/ /backups/Pictures
Boot, reboot, and shutdown a system safely
$systemctl reboot
$systemctl reboot --force
$systemctl reboot --force --force
## For shutdown
$systemctl poweroff
$systemctl poweroff --force
$systemctl poweroff --force --force
## Shutdown 00:00 to 23:59
$sudo shutdown 02:00
## Shutdown after 15 minutes
$sudo shutdown +15
$sudo shutdown -r 02:00 ##reboot
$sudo shutdown -r +15 ##reboot
### wall message
$sudo shutdown -r +1 'Scheduled restart to do an offline-backup of our database'
Boot or change system into different operating modes
Install, configure and troubleshoot bootloaders
Use scripting to automate system maintenance tasks
Manage the startup process and services (In Services Configuration)
When we boot up linux some important application start automatically and can be in very specific order.Init does many jobs and the logic part of it is written in Units
Units can be of various types such as- service
- socket
- device
- timer
Service Units
Service Units has clear instructions about things such as what command to issue to startup the program, what to do if the program crashes, what command to issue when the program is restarted and so on, basically to manage lifecycle of certain application.
Startup processes and services
Diagnose and manage processes
Locate and analyze system log files
Schedule tasks to run at a set date and time
- cron job
- anacron - small unit is -> day, week, month and also useful when you want to run the cron no matter when the power was on, cron job won't work if the system get power on after scheduled task time. cron can miss jobs when computer is power off.
- at - is foucused on task that should only runs once
cron
cron job
/usr/bin/touch testfile
##ctrl+d





0 Comments