Errata: Linux Snippets

Setting the Timezone

RedHat sometimes has timezone problems. Try this:

rm /etc/localtime
ln -s /usr/share/zoneinfo/America/New_York /etc/localtime

File management with "find"

Delete all files in a directory not modified in the last week:

find . -mtime +7 -type f -exec rm -f {} \;

Or:

find . -mtime +7 -type f | xargs rm

Delete all files named *.bak:

find . -name *.bak -type f -exec rm -f {} \;

Change permissions on all files:

find . -type f -exec chmod 664 {} \;

Find the size of all directories inside a directory:

find -type d | xargs du -sm | sort -g

find is handy because it will dive into subdirectories.

Running ssh-agent when starting KDE

If you start up in run level 3 and run startx to start your X session, do this:

In your home directory, create a file named .xinitrc if it doesn't exist (and it probably won't). Add the following line:

exec ssh-agent sh -c 'ssh-add > /dev/null & sleep 5; exec startkde'

If you start up in run level 5, do this:

Edit /etc/X11/xinit/Xclients and put the following code at the top of the file:

if [ -z "$SSH_AGENT_PID" -a -x /usr/bin/ssh-agent ]
then
exec /usr/bin/ssh-agent $0 ${1+"$@"} < /dev/null
fi

if [ -r $HOME/.ssh/id_dsa ]
then
/usr/bin/ssh-add $HOME/.ssh/id_dsa < /dev/null
fi

This is a slightly-modified version of the code I found here.

If you bounce around from machine to machine, don't forget to set ForwardAgent yes in /etc/ssh/ssh_config.

Sendmail commands

Take a look at all the messages in the queue:

sendmail -bp

Process messages in the queue:

sendmail -q

Using SMTP AUTH with Sendmail and KMail.

My mailserver runs sendmail on FC2. I found instructions on setting up the server side here. The relevant lines from my /etc/mail/sendmail.mc file are:

define(`confAUTH_OPTIONS', `A p y')dnl
TRUST_AUTH_MECH(`LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `LOGIN PLAIN')dnl
define(`confCACERT_PATH',`/usr/share/ssl/certs')
define(`confCACERT',`/usr/share/ssl/certs/ca-bundle.crt')
define(`localCERT', `/usr/share/ssl/certs/sendmail.pem')
define(`confSERVER_CERT',`localCERT')
define(`confSERVER_KEY',`localCERT')
define(`confCLIENT_CERT',`localCERT')
define(`confCLIENT_KEY',`localCERT')

I looked at this how-to first. I couldn't get these instructions to work for me, but I probably forgot to roll back some of the file edits mentioned.

My email client is KMail on FC3. In the setting for your mailserver, check the box for "Server requires authentication" on the "General" tab. On the "Security" tab, choose TSL for encryption, and PLAIN for authentication method.

Using SRPMs

First, create your local build directories:

mkdir $HOME/rpm $HOME/rpm/SOURCES $HOME/rpm/SPECS \
$HOME/rpm/BUILD $HOME/rpm/SRPMS $HOME/rpm/RPMS \
$HOME/rpm/RPMS/i386

Set up your local config file to use these directories:

echo "%_topdir $HOME/rpm" >> $HOME/.rpmmacros

Put your SRPMs in the ~/rpm/SRPMS directory, and run:

rpmbuild —rebuild my.src.rpm

If you have to tweak the sourcecode to get the RPMs to build, do something like this:

cd SRPMs
rpm -Uvh my.src.rpm
cd ../SPECS
rpmbuild -bp my.spec
make edits to sourcecode
rpmbuild -bc my.spec —short-circuit
rpmbuild -bi my.spec —short-circuit

Help with optimizations is available here.

Access Control Lists

To share files among many users more efficiently, access control lists (ACLs) are helpful. getfacl and setfacl are two tools that allow you to get and set ACL permissions.

To get permissions:

getfacl code.txt
# file: code.txt
# owner: eric
# group: eric
user::rw-
group::rw-
other::r—

To set permissions:

setfacl -m nobody:rw code.txt

More good information on using ACLs is here.

Check Swap Usage Quickly

Are we using any swap?

free -m