Cheatography
https://cheatography.com
grouping all linux based commands
This is a draft cheat sheet. It is a work in progress and is not finished yet.
List files
listed view |
|
show hidden files also |
|
show size in human readable |
|
showfile created today |
ls -ltr | grep "$(date '+%b %e')"
|
show files in tree structure |
tree [/path/to/folder]
|
vi editor
quit |
|
force quit |
|
save and quit |
|
find foo and replace all with bar |
|
install loadbalancer
install lb |
|
enable ip forwarding |
echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.conf
|
reload |
|
check ip forwarding enabled |
sysctl net.ipv4.ip_forward
|
create config file |
sudo touch /etc/sysconfig/ipvsadm
|
start service |
sudo systemctl enable --now ipvsadm
|
clear iptable rules |
|
add a virtual service |
ipvsadm -A -t [ServiceIP:Port] -s [Distribution method]
|
ansible
export inventory |
export ANSIBLE_INVENTORY=/home/user1/inventory/
|
run adhoc command in all nodes |
ansible all -a 'uname -r'
|
run command with multiple forks (default:5) |
ansible all -a 'uname -r' -f 15
|
run command as different user |
ansible all -a uptime -u userx
|
copy file |
ansible all -m copy -a "src=testfile dest=/tmp/testfile"
|
check if yum package is present |
ansible all -m yum -a "name=docker state=present"
|
check if yum package is absent |
ansible all -m yum -a "name=iperf3 state=absent"
|
check if installed yum pacakage is latest |
ansible all -m yum -a "name=docker state=latest"
|
sudo pass in ansible-playbook |
--extra-vars "ansible_sudo_pass=abcd"
|
encode
encode |
echo 'password@123' |base64
|
encode without newline |
echo 'password@123' |base64 | tr -d \\n
|
decode |
echo 'cGFzc3dvcmRAMTIzCg==' |base64 -d
|
curl
ignore certificate error |
curl -vk https://localhost:8080
|
to grep pattern |
|
curl tcp |
|
system stats
get RHEL version |
cat /etc/redhat-release
|
get kernel version |
|
get cpu count |
cat /proc/cpuinfo | grep processor | wc -l
|
get processor model |
cat /proc/cpuinfo | grep 'model name' | uniq
|
get memory |
cat /proc/meminfo |grep MemTotal
|
get ip addresses |
|
get all ip details |
|
get list of logged in users |
|
get free disk space |
|
get disk usage details |
|
get id of current user |
|
get id of other user |
|
TCP dump
get tcp dump |
tcpdump -i bond0.60 dst 137.10.10.10 and dst port 30000
|
extend partition
RHEL 6 |
check volume group |
|
volume group extend (if no free space) |
vgextend /dev/VolGroup00 /dev/sda3
|
extend logical volume |
lvextend -L +2G /dev/mapper/vg_data-lv_docker
|
resize |
resize2fs /dev/mapper/vg_data-lv_docker
|
RHEL 7 |
|
xfs_growfs /dev/mapper/vg_data-lv_docker
|
iperf3
install iperf3 |
|
run iperf server on default port 5201 |
iperf3 -s -f K
(k, m, g for Kbits, Mbits, Gbits or K, M, G for KBytes, Mbytes, Gbytes) |
run iperf server on specific port |
|
run iperf as daemon |
|
run iperf client |
iperf3 -c 192.168.10.1 -f K
|
run 2 parallel session |
iperf3 -c aedup1mst1 -f G -P 2
|
run test in reverse direction |
iperf3 -c aedup1mst1 -f G -R
|
run test in bi direction |
iperf3 -c aedup1mst1 -f G -d
|
get server output in client |
iperf3 -c aedup1mst1 -f G --get-server-output
|
set windos socket/buffersize |
iperf3 -c 192.168.10.1 -f K -w 500K
|
iPerf3 is a tool for active measurements of the maximum achievable bandwidth on IP networks. It supports tuning of various parameters related to timing, buffers and protocols (TCP, UDP, SCTP with IPv4 and IPv6). For each test it reports the bandwidth, loss, and other parameters.
find
find file matching pattern |
|
find files based on content |
|
Generic
Cancel |
ctrl + c |
Exit |
ctrl + d |
Clear screen |
clear |
Clear screen |
ctrl + l |
|
|
zip
zip a folder |
zip -r [output.zip] [folder name]
|
unzip a folder |
|
tar
tar a folder |
tar -cvf [output.tar] [/dirname]
|
untar a file to diff folder |
tar -C [/myfolder] -xvf [yourfile.tar]
|
untar to current folder |
|
untar a .tar.gz file |
tar -zxvf [yourfile.tar.gz]
|
change host name
#method 1 |
edit file hostname |
echo "geeklab" > /etc/hostname
|
reboot server |
|
check hostname |
|
#method 2 |
check current hostname |
|
update hostname |
hostnamectl set-hostname geeklab
or hostnamectl set-hostname "Geeks LAB"
|
relogin and verify |
hostnamectl |
session timeout
open file |
sudo vi /etc/ssh/sshd_config
|
edit params |
ClientAliveInterval
and ClientAliveCountMax
|
reload sssh |
sudo systemctl reload sshd
|
Timeout value = ClientAliveInterval * ClientAliveCountMax
password less login setup
create key in host machine |
|
Copy key to target |
|
copy content from .ssh/id_rsa.pub to .ssh/authorized_keys
stop kernel messages
open file |
sudo cat /etc/sssd/sssd.conf
|
add in last line |
ad_gpo_ignore_unreadable = True
|
restart sssd |
sudo systemctl restart sssd
|
reboot if still persists |
|
output formatting
capture pattern in output |
|
capture x lines after pattern |
|
capture x lines before pattern |
|
print only column x |
|
count output lines |
|
grep curl output |
|
edit gateway
#temp |
delete existing gateway |
sudo route delete default gw 10.10.10.10 bond0.200
|
add new gateway |
sudo route add default gw 137.10.10.10 bond0.60
|
#permanent |
edit file |
sudo vi /etc/sysconfig/network-scripts/ifcfg-bond0.200
|
restart network |
sudo /etc/init.d/network restart
|
kernel upgrade
go to yum folder |
|
create a bkup folder |
|
move all repos to it |
'mv x.repo bkp1' |
enable rhel 7 rpms |
subscription-manager repos --enable rhel-7-server-rpms
|
list available kernel |
|
install required kernel |
yum install kernel 3.10.0-1127.18.2.el7
|
reboot |
reboot |
create partition
create physical volume |
sudo pvcreate /dev/nvme0n1
|
create volume group |
sudo vgcreate vg_data /dev/nvme0n1
|
list volume group and check |
|
create logical volume |
sudo lvcreate -n lv_docker -L +100G vg_data
|
list logical volume and check |
|
create a directory to map (if not exists) |
sudo mkdir /var/lib/docker
|
check file system packages |
sudo ls -l /usr/sbin/mkfs.*
|
|
sudo mkfs -t xfs /dev/mapper/vg_data-lv_docker
|
add entry in /etc/fstab |
sudo sed -i '$a /dev/mapper/vg_data-lv_docker /var/lib/etcd xfs defaults 0 0' /etc/fstab
|
mount |
|
check if mounted |
|
delete partition
list volume group |
|
remove volume group |
|
start disk utility |
|
list partition |
|
delete partition |
|
save and exit |
|
remove entries from /etc/fstab and unmount first.
|