AllTechWiki



A Place for All Technical Stuff Linux Cloud etc

AZURE LINUX COMMANDS

 1) How to use specific interface(enp0s3) to connect remote host

curl -I --interface enp0s3 https://google.com

2) traceroute and tcpdump example commands

traceroute -I www.google.com

tcpdump -D - shows all interfaces

tcpdump -i eth0 src SRC_IP

tcpdump -i eth0 dst DST_IP

tcpdump -n -i eth0 port 8099

curl -v http://183.82.106.240:8099

tcpdump -n -i eth0 port 8099  -c 10

tcpdump -n -i eth0 -w /home/naveen/tcpdump.pcap

3) How to  check VM is connected with internet or not from command line

curl -I https://www.google.com/

if you get HTTP/1.1 200 OK , then internet is working 

4) How to find the large size of file in current directory

find . -type f -exec du -Sh {} + | sort -rh | head -n 10

5) find the 10 largest directories in current / 

find / /proc -prune -type d -print0 | xargs -0 du 2>/dev/null | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh 2>/dev/null {}

6) find the 10 largest files in / 

find / -path /proc -prune -o -type f -print0 | xargs -0 du 2>/dev/null | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh 2>/dev/null {} 

du -shx ==> exclude the directories

7) SAR Handy Commands

sar -u -f sa05 ==> CPU Statictics  ( sar -u -f sa05 | sort -k7 -n ==> print output sort wise by 7th column with numeric)

sar -r -f sa05 ==> Memory          ( sar -r -f sa05 | sort -k5 -n)

sar -b -f sa05 ==> I/O Statictics

sar -p -d -f sa03  ==> Disk Statictics

sar -r -n DEV -f sa03 ==> Ethernet Statictics 

sar -n DEV  --iface=eth0 ( shows current VM ethernet staticstics)

sar -n EDEV --iface=eth0

For More : https://alltechguru99.blogspot.com/2020/10/how-to-check-cpu-memory-utilization-at.html

8) lsof - list of open files Handy Commands

a) shows list of open top consumed 15 files ( non customize format)

lsof / | sort  -r -s -n -k 7 | head -15

b) shows list of open top consumed deleted 15 files ( non customize format)

lsof / | sort  -r -s -n -k 7 | head -15 | grep -i deleted    ==> this one good

lsof / | grep -i deleted | sort  -r -s -n -k 7 | head -15

c) shows list of open top consumed 15 files along with pid and user ( customize - Print output in MB format)

lsof / | awk '{if($7 > 1048576) print $7/1048576 "MB" " " $9 " " $1 " " $2 " " $3}' | sort -nu | tail -n15   

d) shows list of open top consumed deleted 15 files with pid and user ( customize - Print output in MB format)

lsof / | grep -i deleted | awk '{if($7 > 1048576) print $7/1048576 "MB" " " $9 " " $1 " " $2 " " $3}' | sort -nu | tail -n15 

Note: By default output shows in BYTES , so we can convert to MB by dividing 

1 Mebibytes = 1048576 Bytes

9) Command Info

nfs - no_root_squash

Treat the remote root user as local root — If this option is on, it enables the remote root user host accessing your shared directory to save and modify files as though he or she were the local root user. 

Having this on is a security risk, since the remote user can potentially modify critical files. (This sets the no_root_squash option.)

--------------------------------------------------------------------------------------------------------------

last -x reboot    shows the VM start time and till reboot/shutdown time (simply total uptime of server)

last -x shutdown  Shows the shutdown start time till start of the VM (simply total downtime of server)

----------------------------------------------------------------------------------------------------------------------

parted command with sector print

parted /dev/sda unit s print <= this shows sector wise information

fdisk -l /dev/sda      <= this shows sector wise information

------------------------------------------------------------------------------------------------------------------------

10) cat and grep command options for find out white space or blank space in any file 

cat -vet <filename>

Remove spaces and # in the file and disply only content
grep -v -e ^# -e ^$ file_name

Remove spaces and # in the file and disply only content
cat FILE_NAME | grep -v "#" >> NEW_FILE_NAME
grep '^..' NEW_FILE_NAME

Remove Blank or white spaces and commented lines of the file
SIMPLE WAY (working)
cat FILE_NAME | grep -v "#" | grep '^..'

11)check booting logs from journelctl from OS end

/usr/bin/journalctl --no-pager --boot 0  ==> Boot logs after VM up 

12)OS logs Collect Examples

Command to collect sosreport( Redhat/CentOS/OracleLinux/Ubuntu)

sosreport --all-logs

Untar sosreport

tar -Jxvf sosreport-RHEL8-8888-2022-04-07.tar.xz

search with below keywork in sosreport

find . -type f -print0 | xargs -I {} -0 grep -i -H --color 'KEYWORD' "{}"

https://access.redhat.com/discussions/469323  - XSOS Good Tool but have  not tried

Command to collect supportconfig( SUSE 12/15)

supportconfig -l (it collects rotated logs in addition to the current log file) - aLL logs

supportconfig    ( collect witout rotated logs)

supportconfig -m ( collec minimal logs option)

untar supportconfig

tar -Jxvf scc_SUSE12.txz

tar.bz2 ==> tar -xvf file.tar.bz2

tar.gz ==>  gunzip file.tar.gz && tar -xvf tar

Compressed Archive Folder (.xz)

file.xz 

unxz file.xz

tar xvf file

mpio.txt ==> This file will be having fstab entries 


12)  rsync and multithread copy examples

rsync -anv --progress /pbsrestore/test.txt /pbsdata/test_data/

a=Archive;n= ;v=verbose;z=compress

rsync multithread copy advanced

cd source-dir;ls -1 | xargs -n1 -P4 -I% rsync -ar % destination-dir/

cd /test-rsync; ls -1 | xargs -n1 -P4 -I% rsync -ar % /data/rsync-data/ ===> works for local data copy

ps aux | grep rsync

pstree | grep rsync

top -c

For each file/directory its asking password 

cd /test-rsync; ls -1 | xargs -n1 -P2 -I% rsync -ar % root@192.168.0.6:/data/rsync-data/


13) How to check current run level of RHEL7/8/SUSE12/15/Ubuntu 20/22/24

systemctl get-default ==> shows the current run level

sudo systemctl set-default multi-user.target ==> will change to multi-user.target 
sudo systemctl set-default graphical.target  ==> will change to graphical.target 


14) How to Find Public IP Address from command line

curl ifconfig.co => not working for some servers 
curl -s https://icanhazip.com           => This shows IPv6 public IP if VM has been configured with both IPv4 and IPv6 ,If VM is having only IPv4 then it shows IPv4 only
curl -s https://checkip.amazonaws.com   => This shows only IPv4 public IP
wget -O - -q https://icanhazip.com      => This shows IPv6 public IP if VM has been configured with both IPv4 and IPv6 ,If VM is having only IPv4 then it shows IPv4 only
wget -O - -q https://checkip.amazonaws.com => This shows only IPv4 public IP

15) How to find VM using BIOS or UEFI 
In Azure /boot/efi will be there for both bios and uefi based boot and we can't conclude by seeing the /boot/efi 
#dmesg | grep "EFI v"
#ls -ld /sys/firmware/efi   ## if file exist then its booted with UEFI , if file not there then its BIOS.
## if in Azure VM is build with V1 then its BIOS AND if buit with V2 then its UEFI , observation only

[root@Redhat8 efi]# dmesg | grep "EFI v"
[    0.000000] efi: EFI v2.70 by Microsoft

[root@Redhat8 efi]# yum install efibootmgr

EFI based output below
[root@Redhat8 efi]# efibootmgr 
BootCurrent: 0003
Timeout: 0 seconds
BootOrder: 0003,0001,0002,0000
Boot0000* EFI Network
Boot0001* EFI SCSI Device
Boot0002* EFI SCSI Device
Boot0003* Red Hat Enterprise Linux
[root@Redhat8 efi]# 

BIOS based output
[root@rescuecentos firmware]# efibootmgr 
EFI variables are not supported on this system.
[root@rescuecentos firmware]# 

16) Having issue with lib and bin while going to chroot environment

sudo sed -i 's/defaults/defaults,nofail/g' /etc/fstab

You can change the or update the file

17) How to skip password enter while switching sudo su each time for user

add below users in sudoes /etc/sudoers 
naveen ALL=(ALL) NOPASSWD:ALL

18) Difference between power off and halt in Linux

halt  - Stops all running processes and halts the system without powering off the machine.
poweroff - Stops all running processes, halts the system, and then powers off the machine (if supported by hardware).

  • In systems using systemd (like RHEL 7 and later):
    • Both halt and poweroff are linked to systemctl commands.
    • halt: Equivalent to systemctl halt (halts the system).
    • poweroff: Equivalent to systemctl poweroff (halts and powers off the system).

Command Comparison in systemctl:

CommandBehavior
    systemctl haltHalts the system without cutting power.
    systemctl poweroffHalts the system and powers it off.
    systemctl reboot           Restarts the system after halting all processes.

19) journalctl command examples

The journalctl command in Linux is used to view logs collected by the systemd journal
journalctl --since="2024-12-01"
journalctl --since="today"
journalctl --since="yesterday"
journalctl --since="2024-12-01" --until="2024-12-07"
journalctl --since="2024-12-01 08:00:00"


journalctl -u sshd/sssd --since="2024-12-01"
journalctl -u sshd/sssd --since="2024-12-01" --until="2024-12-07"
journalctl -u sshd/sssd --since="2024-12-01 08:00:00"

Post a Comment

Previous Post Next Post

Basic Useful Links