esc + .
in the terminal
grep -e pattern1 -e pattern2
-e
used for combine the logical OR orerator
grep 'pattern1.*pattern2'
This is used for cobine the logical
AND
operator
cat /var/log/mail.log | grep 200 | awk -F' ' 'substr($13,2) > 200 {print $1}'
Here substr() is the function to subsitute the charater from the variable This code is useful to subsitrute the first letter from the variable and check the condition of status is greater than 2000 and print that line
Exit and Save the file
Shift + zz
(( expression ))
this is used for advance mathmatically operation
var ++
val --
++ var
-- val
<< left bitwise shift
>> right bitwise shift
& bitwise and
| bitwise or
&& logical and
|| logical or
ls -lah /etc | more
ls -lah /etc | tail -1
ls -lah /etc | head -1
Here -(hyphen) is represntas arguement like -f or -100
- hosts: Host1, Host2, Host
- hosts: Groups1
- hosts: Host*
- hosts: *.company.com
ls | grep .mp3 | xargs -I '{}' cp '{}' /home/user
Here
.mp3
is the search term you can specifydate
orname
and/home/user
is the paste location you can also use for other opearions likemoving
ordeleing
the files
ls | grep .mp3 | xargs -I '{}' rm -rf '{}' /home/user
sudo !!
Here
!!
is the operator which is used for pick up the last command you enterd also you can make this command as dynamic as you want like this !! stands for fetch the previous command
docker
sudo !! ps
fc
wget -O - https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> | bash
So outputting to -
will actually write the files content to STDOUT
and then you simply pipe it to bash
or whatever shell you prefer. If you script needs sudo
rights you need to do sudo bash
at the end so the line becomes:
wget -O - https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> | sudo bash
wget -O - https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> | bash -s <arg>
wget -O - https://raw.githubusercontent.com/vortexdude/src/main/script.sh | bash -s setup_role_dir
Run the history command and copy command number and put the ! mark before the number
history
!123
apt list --installed | grep name
you can check the status of the command 0
for Not found and 1
for found
apt list --installed | grep name | wc -l
sudo code --user-data-dir="~/.vscode-root"
mkdir -p /folder/{sub1,sub2}/{sub1,sub2,sub3}
Here
-p
used for creating parent directories if dosen`t exist
disown -a && exit
sudo apt update -y && sudo apt install nfs-common -y
mkdir -p /mnt/nfs
mount -t nfs 10.0.0.0:/mnt /mnt/nfs
Here
10.0.0.0
is the ip that you have to mount and/mnt
is the directory that is shared in that server and/mnt/nfs
is the local directory
command 2>/dev/null
Here
2
difines the standed erors wich are redirected to the/dev/null
drectory this is file where all the data will be lost so that the erros are not apprearing on the terminal
you can use this with any commands where you dont want to get any type of errors this is extremly useful in automation where you dont want to get the errors on the terminal
ls | grep .mp3 | wc -l
for redirect the standerd output
ls >log.txt
for append the standerd output
ls >>log.txt
lablk --fs /dev/sdb
openssl passwrd -1 -salt name password
Where
name
is apeended on the hashed form andpassword
is actual password
for localhost
rpcinfo -p
for server
rpcinfo -p <server_ip>
ssh-agent bash -c 'ssh-add /your-key-path; git clone [email protected]:user/project.git'
scp -r <file> user@<new_server_ip>:<dest_path_path>
C:\Windows\System32\drivers\etc\hosts
/etc/hosts
cat /etc/os-release
firewall-cmd --zone=public --permanent --add-port {port}/tcp
firewal-cmd --reload
systemctl enable <Service Name>
:%s/foo/bar
:%s/foo/bar/gc
git clone -b <branch> <remote_repo>
sftp {user}@{ip}:{file_location}
expl - sftp [email protected]:/mnt/sftp_share/test.txt
for fetch the values from the JSON file using terminal
jq '.data.id' file.json
use -r for remove the double quotes
jq -r '.data.id' file.json
awk -F: '{print $1}'
awk -v FS=: '{print $1}'
awk '{print $1}' FS=:
awk 'BEGIN{FS=":"} {print $1}'
umount -l /PATH/OF/BUSY-DEVICE
umount -f /PATH/OF/BUSY-NFS (NETWORK-FILE-SYSTEM)
arch
echo $(arch)
you must add the
-e
with echo to see the color changes
#!/bin/bash
# Color variables
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
blue='\033[0;34m'
magenta='\033[0;35m'
cyan='\033[0;36m'
# Clear the color after that
clear='\033[0m'
# Examples
echo -e "The color is: ${red}red${clear}!"
echo -e "The color is: ${green}green${clear}!"
echo -e "The color is: ${yellow}yellow${clear}!"
echo -e "The color is: ${blue}blue${clear}!"
echo -e "The color is: ${magenta}magenta${clear}!"
echo -e "The color is: ${cyan}cyan${clear}!"
echo -e '\033[0;31m Nitin \033[0m'
Parameter
Output
date +”%m/%d/%Y”
03/25/2019
date +”%d-%b-%Y”
25-Mar-2019
date +”%Y %b %m”
2019 Mar 25
date +”%H:%M”
14:40
date +”%I:%M %p”
02:40 PM
date +”%H:%M:%S”
14:40:32
date +”%I:%M:%S %p”
02:40:32 PM
date +”%m/%d/%Y %H:%M”
03/25/2019 14:40
date +”%A, %m %d %Y %H:%M”
Monday, 03 25 2019 14:40
date +”%A, %b %d, %Y %I:%M %p”
Monday, Mar 25, 2019 02:40 PM
date +”%A, %b %d, %Y %H:%M:%S”
Monday, Mar 25, 2019 14:40:32
ibmcloud login --sso
ibmcloud plugin install vpc-infrastructure
ibmcloud is instance-initialization-values <INSTANCE_ID> --private-key @<PRIVATE_KEY>