Useful Commands in Linux and Unix

From Luis Gallego Hurtado - Not Another IT guy
Jump to: navigation, search


Hardware Information

  • Displays information about the CPU architecture
  • See Running processes
ps aux
  • See top running processes and free memory
Click "E" to change the memory unit: KB, MB, GB.
  • See Virtual Memory stats updated every second
vmstat 1

Disk and filesystem

  • Get file content in directory
ls –lah
  • Get directory size
du –h
  • Get information of filesystem
df –h
  • Create an empty file of 1024KBs (1MB)
dd if=/dev/zero of=file.txt count=1024 bs=1024
  • Automate deletion of partition table and creation of partition on $device_path
echo o # Clear the in memory partition table 
echo n # Add a new partition 
echo p # Primary partition 
echo 1 # Partition number 
echo   # First sector (Accept default: 1) 
echo   # Last sector (Accept default: varies) 
echo w # Write changes 
) | sudo fdisk $device_path

Logical Volumes

  • Creating physical volume for $device_path
pvcreate $device_path
  • Creating volume group for $device_path
vgcreate $VOLUME_GROUP_NAME $device_path
  • Creating logical volume thin pool $LOGICAL_VOLUME_POOL_NAME in group $VOLUME_GROUP_NAME
  • Creating logical volume $LOGICAL_VOLUME_NAME in group $VOLUME_GROUP_NAME
  • Formatting logical volume $LOGICAL_VOLUME_NAME in ext4
  • Creating mount point at $mount_path
mkdir -p -m777 $mount_path 
echo "/dev/$VOLUME_GROUP_NAME/$LOGICAL_VOLUME_NAME $mount_path ext4 defaults,nofail 0 0">>$FSTAB_FILE_FULL_PATH


  • Check open ports
netstat -tulpn | grep LISTEN
lsof -i -P -n | grep LISTEN
  • Time synchronisation with chrony
    • On demand synchronisation
chronyd -q 'server <IP> iburst'
    • Show details of sources and stats
chronyc sources
chronyc sourcestats