this is obsolete doc -- see http://doc.nethence.com/ 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 '
/^[[:space:]]*$/d;
/^[[:space:]]*#/d;
' 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
/dev
/proc
/root
/sys
/var/backup
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 (http://www.gnu.org/software/indent/).
Convert tabs to spaces with GNU coreutils (http://www.gnu.org/software/coreutils/),
mv file file.dist
expand file.dist > file
Proxy config
export http_proxy=http://USERNAME:PASSWORD@proxy.example.net:8080
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
lynx www.google.fr
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
Search for files changed between 0 and 1 minute before,
find . -cmin 1
between 1 and 2 minute before,
find . -cmin 2
Permissions
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 ntp.obspm.fr
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 ntp1.dedibox.fr >/dev/null
Or the NTP daemon,
ntpq -q
Crontab
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,
atq
To remove the AT job,
atrm
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
uname
netstat
top
Check services' ports,
lsof -i:3260
netstat -apne | grep 3260
netstat -tulpn | grep 3260
Go to the last folder you where in,
cd -
Misc
To turn a process into a daemon,
nohup ...
Otherwise use Daemon (http://libslack.org/daemon/)
Mesure how much time a command takes,
time command...
Troubbleshooting
"strace" may be helpfull,
strace command
References
Unix Sysadmin Cross Reference : http://www.unixporting.com/quickguide.html
UNIX® Load Average Part 1: How It Works : http://www.teamquest.com/resources/gunther/display/5/index.htm
Solaris versus HP-UX : http://www.loudermilk.org/software/solaris-hpux.html
Unix Toolbox : http://cb.vu/unixtoolbox.xhtml
UNIX in a Nutshell: System V Edition. : http://docstore.mik.ua/orelly/unix/unixnut/ch04_03.htm