My Linux cheatsheet

09 Nov Tagged bash, centos, cheatsheet, code, FLOSS, shell

I have a text file with some of my favorite Bash commands and I thought I'd share them. Some are specific to CentOS/RHEL/Fedora but most are simple and useful. Feel free to comment if you can improve on any of them. Cheers.

Show all installed packages and order by size

rpm -qa --queryformat "%12{SIZE} %{NAME}\n" | awk {'print $1"    "$2'} | sort -n +0

Show all installed packages and order by date

rpm -qa --queryformat '%{installtime} %{name} %{version}-%{release} %{installtime:date}\n' | sort -nr +1 | sed -e 's/^[^ ]* //'

Display RPM files then extract specific directories or files

rpm -qlp file.rpm
rpm2cpio file.rpm | cpio -ivd ./etc/*
The second line extracts all /etc files from the rpm to ./etc

Install packages required for remote X (SSH X forwarding)

I use this one mostly for running Wireshark on Cygwin so I've also included wireshark.

On CentOS 4:
yum install fonts-xorg-base xorg-x11-xauth wireshark-gnome
On CentOS 5:
yum install xorg-x11-fonts-Type1 xorg-x11-xauth wireshark-gnome
Note: There will be other dependencies but Yum will resolve them automatically.

Identify Eth device physically by blinking its LED

ethtool -p eth0 5
Substitute eth0 with the device you wish to identify.

Watch a threads of a process

watch ps um -C processname

Check syntax of all PHP files in a directory

for i in *.php; do php -l $i; done

Check for updated packages and email the results

I set this up as a weekly cron job.
yum --exclude=none check-update | /bin/mail <your email address> -s "hostname.example.com yum available packages"
And for up2date
up2date --nox -l | /bin/mail <your email address> -s "hostname.example.com up2date available packages"


All code on this site is free for use at your own risk and provided as-is under the WTFPL license unless otherwise stated. Attribution is appreciated but not required.
Blog content, with the exception of externally quoted material, is licensed under the Creative Commons Attribution 3.0 license