esc + . in the terminal
grep -e pattern1 -e pattern2
-eused for combine the logical OR orerator
grep 'pattern1.*pattern2'
This is used for cobine the logical
ANDoperator
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/userHere
.mp3is the search term you can specifydateornameand/home/useris the paste location you can also use for other opearions likemovingordeleingthe 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
fcwget -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
!123apt list --installed | grep nameyou can check the status of the command 0 for Not found and 1 for found
apt list --installed | grep name | wc -lsudo code --user-data-dir="~/.vscode-root"mkdir -p /folder/{sub1,sub2}/{sub1,sub2,sub3}Here
-pused for creating parent directories if dosen`t exist
disown -a && exitsudo 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.0is the ip that you have to mount and/mntis the directory that is shared in that server and/mnt/nfsis the local directory
command 2>/dev/nullHere
2difines the standed erors wich are redirected to the/dev/nulldrectory 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 -lfor redirect the standerd output
ls >log.txtfor append the standerd output
ls >>log.txtlablk --fs /dev/sdbopenssl passwrd -1 -salt name passwordWhere
nameis apeended on the hashed form andpasswordis actual password
for localhost
rpcinfo -p
for server
rpcinfo -p <server_ip>ssh-agent bash -c 'ssh-add /your-key-path; git clone git@github.com:user/project.git'scp -r <file> user@<new_server_ip>:<dest_path_path>
C:\Windows\System32\drivers\etc\hosts/etc/hostscat /etc/os-releasefirewall-cmd --zone=public --permanent --add-port {port}/tcp
firewal-cmd --reloadsystemctl enable <Service Name>:%s/foo/bar
:%s/foo/bar/gcgit clone -b <branch> <remote_repo>sftp {user}@{ip}:{file_location}
expl - sftp igor@10.204.68.51:/mnt/sftp_share/test.txtfor 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.jsonawk -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
-ewith 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>