Here are some useful Linux CLI commands, I will do more good examples in the future. For Germans: #maleben
Remove duplicated empty lines of a text file:
cat -s file.txt
Find and display the Windows OEM license keys in BIOS:
strings /sys/firmware/acpi/tables/MSDM | grep ".*-.*-.*-.*-.*"
Copy file between two hosts directly without third one:
scp -3 host1:/src.file host2:/dst.file
Prepend all lines with timestamp:
ls -la | ts '[%Y-%m-%d %H:%M:%S]'
Resize QEMU disk image:
qemu-img resize image.qcow2 +10G
Rescan disk size without restart:
echo 1 > /sys/block/sda/device/rescan
Reload udev rules without reboot:
udevadm control --reload-rules && udevadm trigger
Reset an USB device via software:
usb_modeswitch -v 3911 -p 7000 -R
Rotate an PDF clockwise:
pdftk input.pdf cat 1-endeast output output.pdf
Replace something in a file inplace:
sed -i 's/ONE/TWO/g' file.txt
Show SW/HW information of a host:
neofetch
Display a ‘show’ like the do it in hacker movies:
hollywood
List all block devices (disks), but no loop type:
lsblk -e 7
Convert a filesystem to xfs without dump/restore:
fstransform /dev/sda2 xfs
Show amount of dirty (unwritten) disk cache memory:
grep Dirty /proc/meminfo
List all network interfaces:
lshw -c network -businfo
Show the IPMI/IDRAC/ILO IP address:
ipmitool lan print | grep "^IP Address *:"
Re-read the partition table:
partprobe /dev/sda
Resize a partition:
parted
-or-
resizepart
-or-
growpart
Disable cloud-init:
touch /etc/cloud/cloud-init.disabled
-or-
echo 'GRUB_CMDLINE_LINUX="cloud-init=disabled"' >> /etc/default/grub
grub-mkconfig -o /boot/efi/EFI/ubuntu/grub.cfg
-or-
echo "DefaultEnvironment=KERNEL_CMDLINE=cloud-init=disabled" >> /etc/systemd/system.conf
Show disk space usage:
ncdu /home
Set all relevant megacli options:
megacli -AdpSetProp -NCQEnbl -aALL -NoLog
megacli -AdpAutoRbld -Enbl -aALL -NoLog
megacli -LDSetProp -CachedBadBBU -Immediate -Lall -aAll -NoLog
megacli -LDSetProp -Cached -Immediate -Lall -aAll -NoLog
megacli -LDSetProp -EnDskCache -Immediate -Lall -aAll -NoLog
megacli -LDSetProp -WB -Immediate -LAll -aAll -NoLog
megacli -LDSetProp -ForcedWB -Immediate -Lall -aAll -NoLog
megacli -LDSetProp -NORA -Immediate -Lall -aAll -NoLog
megacli -AdpSetProp BgiRate 90 -aAll -NoLog
megacli -AdpSetProp RebuildRate 90 -aAll -NoLog
-or- (for slower init/rebuild, but longer)
megacli -AdpSetProp BgiRate 20 -aAll -NoLog
megacli -AdpSetProp RebuildRate 20 -aAll -NoLog
Last updated on 2024:08:22 at 03:14 UTC