Advance Linux Commands Reference 🤳

lsattr : to display the attributes

chattr : to make a file immutable, undeletable, only appendable and many more!

{+|-|=}[aAcCdDeijsStTu]

A set : The a time record is not updated.

S set : The changes are updated synchronously on the disk.

a set : File can only be opened in append mode for writing.

i set : File cannot be modified (immutable), the only superuser can unset the attribute.

j set : All of files information is updated to the ext3 journal before being updated to the file itself.

t set : No tail-merging is allowed.

d set : No more candidate for backup when the dump process is run.

u set : When such a file is deleted, its data is saved enabling the user to ask for its undeletion.

-R : Directories and their contents(files/directories) recursively.

-V : It will display the version of the program.

-a : Used to list all the files of a directory which also includes the whose name starts with a Period(ā€˜.’).

-d : This option will list the directories as regular files instead of listing their contents.

-v : Used to display the file’s version/generation number etc.

āœ” ExampleĀ Ā Ā Ā Ā Ā Ā Ā 

sudo chattr +i file1.txt

sudo chattr +a file1.txt

echo "Prem Nanda" > file1.txt This will not be allowed to replace text, but

echo "Prem Nanda" >> file1.txt This will be allowed to append text

sudo -R +i devops/ : this will make immutable (no modification) to the devops folder recursively.

rm -rf devops : It will not be allowed. Permission denied

sudo -R -i devops/ : this will make mutable (modification) to the devops folder recursively.

rm -rf devops : it will remove the folder recursively.

sudo apt-get update : update with latest

sudo apt install default-jdk : Install Java SDK

🚄User Management

sudo useradd -m newuser1 : to create user

sudo userdel newuser1 : to delete user

su nanda : switch to nanda user

usermod -l nanda ubuntu : to change the username

cat /etc/passwd : to list the users

cat /etc/group : to list the groups and members

sudo groupadd devops_group : to create a group devops_group

sudo gpasswd -a premnanda devops : To add premnanda user to devops group

sudo gpasswd -M premnanda,rio,rigo devops : To add multiple members to devops group

-A : to define group administrator

sudo gpasswd -d nanda devops : to delete nanda from devops group

man gpasswd : to get the manual of the command

sudo chmod u+r /notes.txt : To add/give read permission to user

sudo chmod g+rw /notes.txt : To add/give read/write permission to group

sudo chmod o-r /notes.txt : To remove read permission for others

chown prem /notes.txt : To change the ownership to prem for notes.txt

chgrp devopsgrp /notes.txt : To change the group ownership to devopsgrp for notes.txt

šŸ–grep / find / awk

chmod 751

🚲 grep    : global expression regular print. To search text from the contents of files.

grep -r prem / : Search "prem" word anywhere in the linux system. -r is for recursively

grep devops /home/ubuntu : Search devops word under ubuntu folder

grep TRACE log_file.txt : search TRACE word from the file log_file.txt

grep -i trace log_file.txt : search trace word insensitive (TRACE/trace/Trace/tRace etc) from the file log_file.txt

šŸ›µĀ findĀ Ā Ā Ā  Ā Ā Ā  : search for files in a directory tree given starting-point by evaluating the given expression/pattern/type/actions etc

find (Where) (what)

find $HOME -mtime 0 : Search all files under home directory which are modified in the last twenty-four hours.

find /home -name log.txt : search log.txt file under home directory

find /home/ubuntu -type f : search everything under home/ubuntu which are of type file

find /home/ubuntu -type d : search everything under home/ubuntu which are of type directory

find /home/ubuntu -type d -name prod : search everything under home/ubuntu which are of type directory named as prod

find /home -group devops : find the groups whose name is devops

find /home -group devops -name log.txt : find log.txt under devops group available under /home directory

find /sbin /usr/sbin -executable \! -readable -print : Search for files which are executable but not readable.

find . -perm 664 : search files which have read and write permission for their owner, and group, but which other users can read but not write to.

find . -perm /222 : Search files which are writable by anybody (owner, group, or others).

Search files which are writable by either their owner or their group.

$ find . -perm /220 : by Octal representation / is used as OR

$ find . -perm /u+w,g+w : by symbolic form

$ find . -perm /u=w,g=w : by symbolic form

Search files which are writable by both their owner and their group.

$ find . -perm -220 : - is used as AND

$ find . -perm -g+w,u+w

find /home -name log* | grep -i trace : find files starting with log under home, then grep the word trace (insensitive)

šŸŽ awk : kind of combination of grep and find. It can filter from the searched result data also.

awk /INFO/ log_file.txt : search INFO word inside log_file.txt

awk '/INFO/ {print $1}' log_file.txt : search the word INFO from log_file.txt and print only the first column

awk '/INFO/ {print $1,$3}' log_file.txt : search the word INFO from log_file.txt and print only the first and 3rd column

awk '/INFO/ {print NR,$1,$2}' log_file.txt : along with Row/line number

awk 'NR>20 && NR<40 && /INFO/ {print NR,$1,$2}' log_file.txt > final_report.txt : where line number > 20 and line number < 40 and text contains INFO

ACL : Access Control List

An access control list (ACL) contains rules that grant or deny access to certain digital environments. There are two types of ACLs: Filesystem ACLs━filter access to files and/or directories. Filesystem ACLs tell operating systems which users can access the system, and what privileges the users are allowed.

sudo apt-get install acl

getfacl report.txt : to see the access permission of report.txt. This is similar as ls -l report.txt

setfacl -m u:ubuntu:rwx report.txt

also umask can be utilized. It is a kind of numbering value similar as chmodcd .ssh/ : It contains the information with whom it can be connected.

cat authorized_keys : this file contains public key information, to which other private key holders will connect.

sudo apt-get install acl getfacl report.txt : To see the access permission of report.txt. This is similar as ls -l report.txt

cd .ssh/ : It contains the information with whom it can be connected. cat authorized_keys : this files contains public key information, to which other private key holders will connect.

Connect AWS EC2 from Git Bash

While creating AWS EC2 instance, one key pair needs to be generated.

There will be an option for private Key file format (.pem or .ppk)

.ppk : This format file is used for Windows OS by PuTTY application

.pem : Can be used by SSH (from Linux or Windows)

Save the .pem file under the folder in your local system, from where you want to connect to EC2 instance.

cd .ssh/ : This directory contains the information with whom it can be connected. cat authorized_keys : this files contains public key information, to which other private key holders will connect.

šŸŽ­To connect to Amazon EC2 from Git Bash

Go to AWS Instance, select SSH client tab, copy the command as mentioned in the example

Open the folder where the .pem file is saved, and start Git Bash from there

ssh -i "prem-xxxxxx-yyy300323.pem" ubuntu@ec2-52-91-122-165.compute-1.amazonaws.com

The EC2 instance is synced with the local system

SCP

SCP (Secure Copy Protocol) is a network protocol used to securely copy files/folders between Linux (Unix) systems on a network. It is used for copying files from a local host to a remote host and copying files from a remote host to a local host. Copying files between two remote servers.

šŸ‘€ Let us start with some practical hands-on

✨ Copy linux.jpg file from local system to EC2 instance server (being in local PC)

$ scp -i prem-xxxx-yy.pem linux.jpg ubuntu@ec2-52-91-122-165.compute-1.amazonaws.com:/home/ubuntu

✨ Copy server_test.txt file from EC2 instance to local system (being in local PC)

$ scp -i prem-xxxxx-yy.pem ubuntu@ec2-52-91-122-165.compute-1.amazonaws.com:/home/ubuntu/server_test.txt . server_test.txt

Would you please help me to add some more topics related to Linux which are mostly required in DevOps process.. šŸ™Œ

Thank you

Prem Kumar Nanda

Coming up .... šŸ‘Øā€šŸ­ Shell Scripting......

Tips: In Windows, press the Window button and dot(period) for emoji

#Azure, #AWS #linuxadmin #linuxadministrator #linux #linuxfoundation #linuxsystemadministration #linuxcommands #linuxengineer #linuxtips #linuxjobs #devopscommunity #devopsjobs #devopstraining #devopstools #devopsdays #devopsarchitect #devops #devopscertified #connectionsmatter #cloud #awscloud #awscommunity #awsdevops #awstraining #itautomation #90daysofdevops #trainwithshubham #devopsengineering #devopslife #devopshiring #devopscertification #devopsengineer #devopsengineers #devopsinstitute #acl #acls #cloudarchitect #cloudarchitecture #cloudengineer #cloudjourney #cloudengineering #cloudinfrastructure #cloudadoption #cloudcertification #cloudjobs #cloudfirst #cloudcomputing #clouddeveloper #cloudcareer #clouddevops #clouddatabase #cloudmigration #cloudformation #gcpcloud #gcpdataengineer #gcpengineer #gcp #gcpl #gcpcloudarchitect #gcps #awscommunitybuilders #awscertified #awscertification #awsarchitect #awsmigration #awscommunitybuilder #awscloudpractitioner #aws #awssolutionsarchitect #awsdeveloper #awsservices #awssolutionarchitect #awsonlinetraining #awsckp #awscareerkickstartprogram #awscgp #project #kubernetes #docker #jenkins #pipeline #github #environment #monitoring #grafana #OpenToWork #connections #wfojobs #opportunities #vacancyannouncement #immediatejoiner #jobs #experienced #hiring #urjentrequiremnts #jobfinder #1to3yearsqajobs #linkedinconnections #JobSearch #CareerChange #NewOpportunities #Networking #JobSeeker #careertransition #aspnetmvc #aspdotnetdeveloper #aspdotnetcore #automation #security #scalability #infrastructure

0
Subscribe to my newsletter

Read articles from Prem Kumar Nanda directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Prem Kumar Nanda
Prem Kumar Nanda

• 15+ years of experience in developing applications using Microsoft.NET technologies. • 11 years of experience in Healthcare product development, worked on almost all modules like Master Data, Patient Registration/ Visit, Clinical Charting, Resouce Scheduling, CPOE, Patient Accounting, Finance, Billing, MAR, Pharmacy, Inventory, Insurance, Claim Processing • Strong knowledge of HIS domain and Customer interaction