cli

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:

Using a Webcam with Linux

It's actually surprisingly easy. Install fswebcam (preferably via RPM) and then run this command:

/usr/bin/fswebcam --quiet --background --loop 120 --skip 40 \
--timestamp "%d-%m-%Y %H:%M:%S (%Z)" --png --palette png \
--font /usr/share/fonts/liberation/LiberationMono-Regular.ttf \
--resolution 640x480 --info "Web Cam Stream" --top-banner \ --save /var/www/webcam/webcam.png

SQL Command Reference

Deactivate all inactive users in the last year:
UPDATE `smf_members` SET `is_activated` = 0, `validation_code` = `dateRegistered` WHERE (UNIX_TIMESTAMP() - `lastLogin`) / 86400 >= 365 AND (UNIX_TIMESTAMP() - `dateRegistered`) / 86400 >= 365;

Search and replace text in the "body" field (note that it must be updated in 2 places):
UPDATE smf_messages SET body = replace(body,'OLD','NEW');
Append a value to a field, if it's not already present:

How to check for an open relay

To see if yourserver.com is an open relay, you can run through the following sequence on any box that has a telnet client:
telnet yourserver.com 25
HELO myserver.ca
MAIL FROM:
RCPT TO:
DATA
From: "Relay Test" 
To: Mike 
Subject: Open Relay Test
This is a relay test. A properly configured mail server
should decline to relay this message.
 
.
QUIT

Wireshark and tcpdump Reference

Wireshark and tcpdump are extremely powerful network troubleshooting tools. Here are some command examples that may be useful.

Wireshark Display Filters

Show all ARP:
arp
Show ARP from a specific MAC:
arp.src.hw_mac == 00:16:D3:4A:CE:7D
Show all traffic to a specific IP:
ip.src == 10.14.1.16
Show all traffic to/from a specific IP:
ip.addr == 10.14.1.16
Show only SYN packets:
tcp.flags.syn
Show all web traffic:
tcp.port == 80

OpenSSL Tips & Tricks

Get into the correct directory:

cd /etc/pki/tls/certs

Generate key

openssl genrsa -des3 -out mike.key 4096

chmod 600 mike.key

Generate signing request

openssl req -new -key mike.key -out mike.csr

chmod 600 mike.csr

Get the CA to sign the request

openssl x509 -req -days 10000 -in mike.csr -out mike.cert \

-CA /etc/pki/tls/certs/army.ca/Army.ca_CA.cer \

Linux Package Management Commands

Yes, some distros still use rpm.

Extract files from an RPM:

rpm2cpio filename.rpm | cpio -idv

Unpack an RPM into /tmp/deleteme without installing it:

rpm -ivh -root /tmp/deleteme --nodeps --noscripts package.rpm

Install

rpm -ivh

Upgrade (use this except for kernels)

rpm -Uvh

Find out what's installed

rpm -qa

See which package a file belongs to

rpm -qf