Skip to content

Vortexdude/linux-cmds

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 

Repository files navigation

linux-cmds


Fetch the previous arguement in terminal

esc + . in the terminal


Grep Command

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


Remove the first character from the string via awk command

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


Vim Commands

Exit and Save the file

Shift + zz

Use advance mathmaticall expression in bash

(( 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
See the large content with only one page at a time by more command
ls -lah /etc | more
get the last line
ls -lah /etc | tail -1 
get the first line
ls -lah /etc | head -1 

Here -(hyphen) is represntas arguement like -f or -100


You can use the patterns for ansible host to run the playbook

- hosts: Host1, Host2, Host
- hosts: Groups1
- hosts: Host*
- hosts: *.company.com

copy serched files with ls,cp and grep command

ls | grep .mp3 | xargs -I '{}' cp '{}' /home/user

Here .mp3 is the search term you can specify date or name and /home/user is the paste location you can also use for other opearions like moving or deleing the files

ls | grep .mp3 | xargs -I '{}' rm -rf '{}' /home/user

Run the previous command with sudo previlage

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

Fix a really long commd with text editor {last command}

fc

Run the bash script that is place into the github

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
Give arguement to the file
wget -O - https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> | bash -s <arg>
Example
wget -O - https://raw.githubusercontent.com/vortexdude/src/main/script.sh | bash -s setup_role_dir


Run the any previous command with its number

Run the history command and copy command number and put the ! mark before the number

history
!123

Search the installed packed is exist or not
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

Run VS code as sudo

sudo code --user-data-dir="~/.vscode-root"

Create folder structure

mkdir -p /folder/{sub1,sub2}/{sub1,sub2,sub3}

Here -p used for creating parent directories if dosen`t exist


Exit the terminal but leave all procces runnig

disown -a && exit

Mount the nfs server

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


Clean the output with no errors

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


Count the result

ls | grep .mp3 | wc -l

Redirect or append the standerd output into a file

for redirect the standerd output

ls >log.txt

for append the standerd output

ls >>log.txt

Get the UUID of the partition

lablk --fs /dev/sdb

Generate hashed password with openssh

openssl passwrd -1 -salt name password

Where name is apeended on the hashed form and password is actual password


RPCInfo for the nfs server or ther stats for the server

for localhost

rpcinfo -p 

for server

rpcinfo -p <server_ip>

Git clone with ssh Key

ssh-agent bash -c 'ssh-add /your-key-path; git clone [email protected]:user/project.git'

Copy Files over servers

scp -r <file> user@<new_server_ip>:<dest_path_path>

Host file location windows

C:\Windows\System32\drivers\etc\hosts

Host file location linux

/etc/hosts

Check the os linux

cat /etc/os-release

Open the ports in the firewall and iptables

firewall-cmd --zone=public --permanent --add-port {port}/tcp
firewal-cmd --reload

Start the service for system reboot

systemctl enable <Service Name>

Vim seach and replace all

:%s/foo/bar
:%s/foo/bar/gc

Git clone in specific branch

git clone -b <branch> <remote_repo>

Fetch the file from the sftp server

sftp {user}@{ip}:{file_location}

expl - sftp [email protected]:/mnt/sftp_share/test.txt

JQ for terminal

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

You have multiple ways to set : as the separator:

awk -F: '{print $1}'

awk -v FS=: '{print $1}'

awk '{print $1}' FS=:

awk 'BEGIN{FS=":"} {print $1}'

Unmount busy device forcefully

umount -l /PATH/OF/BUSY-DEVICE
umount -f /PATH/OF/BUSY-NFS (NETWORK-FILE-SYSTEM)

Check the architecture of linux

arch
echo $(arch)

Color schemes for terminal

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'

Getting time in bash using the diffent styles

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

IBM Cloud Dcrypt Password with ssh key

ibmcloud login --sso

ibmcloud plugin install vpc-infrastructure

ibmcloud is instance-initialization-values <INSTANCE_ID> --private-key @<PRIVATE_KEY>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published