Useful Linux command for working professionals

In the addition to my previous blog https://saifali2017.hashnode.dev/linux-and-common-commands-for-devops I came up with the most useful and important Linux commands for working professionals.
Let me start with
File Management.
To check file permission we have command ls -l here is the example with test.txt file.
ls -l test.txt
-rw-rw-r-- 1 saif saif 30 Mar 23 13:45 test.txt
I am sure already aware of RWX if not let me tell you.
R refers to Read (Numeric value 4)
W refers to Write (Numeric value 2)
X refers to Execute (Numeric value 1)
--- refers to No Permission (Numerical value 0)
To change the file permission we have the command #chmod Group, Owner, Others.
For example.
$ chmod u+r test.txt //add read permission to owner
$ chomd g+r test.txt //add read permission to gropu
$ chmod o+r test.txt //add read permission to others
Instead of it, you can set the permission with numerical values refer below.
$ chmod 751 test.txt
Now Let's start with
Searching practices.
We used regular expressions which help us to search data, and match complex patterns.
GREP stands for Global Regular Expression Print
The grep filter searches a file for a particular word or character and displays all lines that contain that pattern.
You can search a word with the below command
$ grep root/ets/test // will search for test
One of the important command for searching is 'find' and you use it with multiple of various conditions like you can find a file by the file permission, users, group, file type, data, size and many more criteria.
Find the file under the Home directory
$ find /home -name test.txt
Find the file with suid permissions
$ find / -perm 4755
Find the file with suid permissions
$ find /-perm 2644
Find the file with less than 10 MB file in a folder
$ find /tmp -size -10m
Find the file with more than 10 MB file in a folder
$ find /tmp -size +10m
To display the top 10 lines of the file.
$ head /etc/passwd
To Display the bottom 10 lines of the file.
tail /etc/passwd
How to Archive a file to compress the file.

Here are some commonly used options.
c - for create
x - for extracts
v - for verbose
f - for forcefully
t - for test
z - for gzip
j - for bx2
J - for xz
C - for specific destination
To create a tar acrchive file
$ tar -cvf /mnt/backup.tar /var
To show file size in human-readable format.
$ du -sh /var
$ du -sh /mnt/backup.tar
To extract a tar archive file on the default location.
$ tar -xvf/mnt/backup.tar
To extract tar archive file on a specific location.
$ tar -xvf/mnt/backup.tar -C /root/Desktop/

Job automation
Job automation allows us to perform the task automatically in OS by using tools
This feature is very useful for administrators to assign the task to OS whenever he is not present or daily basis work.
There are two types of automation.
at : at command used to execute job only one time.
crontab: crontab command is used to execute jobs multiple times.
To set job with "at" command
#date
#at 8:10 AM
at>useradd saif
at>
///Ctrk+D(write and quit)
To show pending jobs
#atq
To remove at job
$ atrm 2
To restrict the users from accessing at
$ vim /etc/at.deny
Saif(username)
:wq(write& quite)
To start a crond service
$ systemctl start crond
To enable crond service
$ systemctl enable crond
To set cron job
$ crontab -e
To check cron jobs of current user
$ crontab -l
To remove cron jobs
crontab -r
How to set host name
$ hostnamectl set-hostname it.citynet.com
To show host name
$ hostname

Service Management
How to check service status
$ systemctl status servicename
How to start a service
$ systemctl start servicename
How to stop a service
$ systemctl stop servicename
How to restart a service
$ systemctl restart servicename
how to stop permanently.
$ systemctl disable servicename
How to on service permanently
$ systemctl enable servicename
Determine service is enabled
$ systemctl is-enabled servicename
How to check CPU utilisation
$ top
// press 1 then c , high one will on first place
quite - press q
How to check free memory
$ free -g
total used free shared buff/cache available
Mem: 3 1 0 0 1 1
Swap: 1 0 1
How to check disk space.
$ df -kh
Filesystem Size Used Avail Use% Mounted on
udev 1.9G 0 1.9G 0% /dev
tmpfs 389M 1.7M 387M 1% /run
/dev/sdb5 234G 11G 212G 5% /
tmpfs 1.9G 180M 1.8G 10% /dev/shm
I hope it will be helpful in your Linux journey.
Happy Learning.
Thanks & Regards,
Saif Raza Khan



