Your shopping cart is empty.

Linux Command Reference

Included below are some commands that I have found, created or tweaked to help make life easier along the way. I have collected them here so I can easily refer to them instead of buildling up the commands from scratch. Some are very simple, others are approaching "script" level. Hopefully others will find them useful as well.

Misc Linux Commands

Find and compress all PNG files under the apache web root:

dir="/var/www/html" ; presize=`du -bs $dir | gawk '{ print $1 }'` ;
for a in $(find $dir -name '*.png'); do /home/bobbitt/bin/pngout $a; done ;
postsize=`du -bs $dir | gawk '{ print $1 }'` ; diff=`expr $presize - $postsize` ;
echo -e "Size before: $presize\nSize After: $postsize\nDifference: $diff"

Create a cron job from the command line (via STDIN):

crontab -e - <<< "*/15 * * * * top -n 1 -b"

Find all rpmnew and rpmsave files:

for a in $(find /etc /var -name '*.rpm?*'); do diff -u $a ${a%.rpm?*}; done

Redirect both stdout and stderr:

ping > /tmp/pingresult 2>&1

Debugging with strace:

strace -p

Network troubleshooting:


To configure the services started/stopped at a specific run level:

/usr/sbin/ntsysv --level 5

Reboot a different way (useful once when the reboot command was removed!):

/sbin/telinit 6

Ring a bell when a script completes (once for success, 2 beeps if it fails): && echo -e '\a' || (echo -e '\a'; sleep 1; echo -e '\a')

finding stuff

Find and delete all empty directories:

find -depth -type d -empty -exec rmdir {} \;

A simple recursive grep (yeah, grep -r works here too...):

find . -exec grep -H "searchtext" {} \;

Find files/dirs that have "tight" permissions:

find . -exec ls -ld {} \; | grep -e "---"

Find world writable files under the web root (but ignore symlinks):

find /var/www -perm -o+w -not -type l

Update permissions on all directories (but not files):

find . -type d -exec chmod 755 {} \;

Find all files modified on a specific date (2020/08/24 here):

find / -type f -name "*" -newermt 2020-08-24 ! -newermt 2020-08-25

Finding all files ending in .pl:

find . -name "*.pl"

Find files over 10 megs, modified in the last 3 days:

find / -size +10000k -mtime -3

Count the number of files (not directories) recursively:

find . -not -type d | wc -l

Finds all core dumps using regex:

locate -r "/core\.[0-9]"

Find all "temp" png files (png.X where X is a digit):

locate -r "png\.[0-9]"

List all files with differences between /dir1 and /dir2

diff -ENwburq /dir1 /dir2 | sort

Find any files not part of a package

find . -exec rpm -qf {} \; | grep -v "package-6.0.18-01.noarch"

Find what process is using a port

lsof -i tcp:514