Posts in Command & Utility
August 21, 2011 Posted in Command & Utility
My simple backup script
It runs daily with cron job.
#!/bin/sh
# directory to backup
BACKUP_DIR=’/home/’
# directory to store backup files
DEST_DIR=’/backup/’
# number of days to store backup files
MAX_DAYS=30
# base backup file name
BASE_FILENAME=’home’
# remove files that are 30 or more days old.
find $DEST_DIR -mtime +$MAX_DAYS -maxdepth 1 -name ‘*.tgz’ -exec /bin/rm -f ‘{}’ +
# generate backup file name with date stamp, no hour/minute info for easier remote backup.
destfilename=$BASE_FILENAME`date “+%Y%m%d”`.tgz
cd $BACKUP_DIR
tar czf $DEST_DIR$destfilename . &
Read More
February 22, 2010 Posted in Command & Utility
To extract a single file from an archive:
# tar zxvf tarfile.tgz –include=”desiredfile”
Use patterns:
# tar zxvf tarfile.tgz –include=”desiredfile*”
‘desiredfile’ must use full path. To check file’s fullpath:
# tar tf tarfile.tgz
Note: It’s double ‘-’ before include.
January 19, 2009 Posted in Command & Utility
Copy a local file to remote host with ssh port 123
# scp -P 123 /backup/localefile username@remotehost.com:/backup/
Copy file from remote host
# scp -P 123 username@remotehost.com:/backup/remotefile /backup/
October 31, 2008 Posted in Command & Utility
Condensed version for my own reference, only those commands I didn’t use but will make life easier. Read More
October 27, 2008 Posted in Command & Utility
Some useful terminal control characters:
Ctrl-C Terminate current process.
Ctrl-U Erase current input line.
Ctrl-S Stop output for easy read.
Ctrl-Q Resume output after stop.
Ctrl-Z Suspend process. use fg command to restart.
Read More
April 20, 2006 Posted in Command & Utility
Portsnap is another tool for updating Ports tree, compared to CVSup, it’s more secure, faster and easier to use. You should give it a shot, especially when you build a new server.
Update ports tree
# portsnap fetch update
For complete guide, check out the handbook “Using Portsnap“.
August 27, 2005 Posted in Command & Utility
To backup the directory /home/ to file /backups/home.tgz, and exclude /home/apachelog/ : Read More
July 30, 2005 Posted in Command & Utility
Obviously, keeping the server time accurate is very important. I should have done this before the server was public.
Adjust server time manually
# ntpdate pool.ntp.org Read More
April 12, 2005 Posted in Command & Utility
Tar can detect an archive with gz compression and extract the files properly, I used to call gunzip first
. Read More
November 6, 2004 Posted in Command & Utility
My Windows XP suddenly crashed when I was running a long-time Linux script, then I tried to find a way to regain the lost output, but it seems not possible, during the search on Google, I found a very useful Linux command: Read More
November 3, 2004 Posted in Command & Utility
Cron job is a very convenient tool in Linux, there are lots of information if you search “cron job” on Google. Read More