this is obsolete doc -- see instead

Miscellaneous Unix tips (doesn’t fit anywhere else) 


Clean up comments 

Strip down your config files e.g. for Redhat LVM2, 

cp lvm.conf lvm.conf.dist
sed '
' lvm.conf.dist > lvm.conf


Broken links 

Look for broken links, 

find . -type l | (while read FN ; do test -e "$FN" || ls -ld "$FN"; done)


Clean up old logs or backups 

Remove those older than 6 days, 

find /var/dir -type f -name "*.log" -mtime +5 -exec rm -f {} \;


Report syslog messages 

When copy/pasting syslog messages to send them by email, you may want to clean the headers first, 

vi inputfile #paste here
sed 's/^...  [^:]*:[^:]*:[^:]* \(.*\): \(.*\)/\1: \2/' inputfile


Whole system with tar 

Prepare the exclude list, 

mkdir -p /var/backup
cat > /exclude.list <<EOF9


Launch the backup, 

cd /
tar cz -X /exclude.list -f /var/backup/backup.tar.gz .


To restore, boot with a rescue media (for example slackware install) and, 

tar xzf /var/backup/backup.tar.gz -C /


Code format 

Format your code with GNU indent ( 


Convert tabs to spaces with GNU coreutils (, 

mv file file.dist
expand file.dist > file


Proxy config 

export http_proxy=
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy

Note. yes, 'http: //' for ftp_proxy 

Note. on C shells, use setenv instead 


Device busy 

Determine what's using a file, directory or mount point, 

fuser -u /data

kill the processes, 

fuser -ku /data

Note. -m might be helpful too 



Search for files changed between 0 and 1 minute before, 

find . -cmin 1

between 1 and 2 minute before, 

find . -cmin 2



This may or may not work on all UNICES. To fix the permissions accordingly to file and directories, 

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

Note. there's also '-type l' on GUN/Linux distros 


Using cpio 

Create a cpio archive, 

cd folder/
find . | cpio -ocm > ../archive.cpio
#find . | cpio -co | gzip -9 > ../initrd.img
#(find . | cpio -co | gzip -9) > ../initrd.img


Extract an archive, 

mkdir -p folder
cd folder/
cpio -icdm < ../archive.cpio
#gzip -dc ../initrd.img | cpio -id


Time & date 

Beside distribution's specific way to setup time, there's always NTP, 

ntpdate -u

Note -u behind firewalls. -b at boot time. -s to report to syslog or >/dev/null to stay quiet. 


Add this to root's conrtab (crontab -e), 

0 6 * * *       ntpdate -u -s >/dev/null


Or the NTP daemon, 

ntpq -q



Good old crontab way works everywhere (no freacking /etc/cron.*), 

crontab -e


The ‘at’ job scheduler 

To plan the execution of a command at a precise time, 

at 20070818
... ^D

To check, 


To remove the AT job, 



Tricky usermod 

To add a secondary group for some user, best practice is to edit /etc/group directly, 

vi /etc/group

because with usermod, you need to reenter the existing secondary groups : "usermod -G group2,group3 username" 

Note. -g for primary group, or simply vipw 

Note. -a to append a secondary group is available on Linux, not HP/UX. 


Usual commands 

Identify what user you are and in what primary group you're in, 

whoami; id
who; w


Check services' ports, 

lsof -i:3260
netstat -apne | grep 3260
netstat -tulpn | grep 3260


Go to the last folder you where in, 

cd -



To turn a process into a daemon, 

nohup ...

Otherwise use Daemon ( 


Mesure how much time a command takes, 

time command...



"strace" may be helpfull, 

strace command



Unix Sysadmin Cross Reference : 

UNIX® Load Average Part 1: How It Works : 

Solaris versus HP-UX : 

Unix Toolbox : 

UNIX in a Nutshell: System V Edition. :