Monday, October 30, 2006

Remove a File or Directory Recursively

# rm filename (removes a single file)
# rm filename? (matches single character. e.g. filename1, filename2, filename3)
# rm filename[1-5] (matches filename1 thru filename5)
# rm filename* (removes everything that matches filename. e.g. filename122, filename222, filename.backup)

# rm -rf /home/esofthub/directoryname (the -r deletes directoryname recursively and all its contents without prompting (-f) read only files/directories)
# rm -Rf /home/esofthub/directoryname (the -R deletes directoryname recursively and all its contents without prompting (-f) read only files/directories)

# pwd
Note: Make darn sure you're in the right directory!! For example, you might be inadvertently deleting the contents of /etc instead of user defined etc, such as, /tmp/etc/ or /raid/etc or /home/esoft/etc.
# rm * ((wildcard *) removes everything within a directory

# rmdir /home/esofthub/directoryname (deletes empty directories)

Saturday, October 21, 2006

Restore OS After Major File System Crash

How to restore a file system?

#/usr/lib/fs/ufs/ufsrestore 0f - /dev/rdsk/c0t0d0s7 | (cd /export/opt; ufsrestore xf -)

Restore incremental backups from tape:
Use Bourne Shell at the command line

#for i in 0 1 3 4 6 7 (These numbers represent the partitions you have configured as file systems)
#/usr/lib/fs/ufs/ufsrestore 5cfu /dev/rmt/0 /dev/rdsk/c0t0d0s$i (If Friday's tape, use 3 instead of 5)
#echo $i done

Repeat incremental backup process until incremental archives are exhausted.

Dump File System and Suggested Backup Schedule

How to dump (archive) a file system to tape?

To dump the entire root filesystem -- level 0 (full dump):

ufsdump 0cfu /dev/rmt/0 /dev/rdsk/c0t0d0s0

If you want to dump an all the file systems:

Use Bourne Shell at the prompt

#for i in 0 1 3 4 6 7 (These numbers represent the partitions you have configured as file systems)
#ufsdump 0cfu /dev/rmt/0 /dev/rdsk/c0t0d0s$i
#echo $i done

Suggested and a common backup schedule:
Sun Mon Tue Wed Thu Fri
Week 1: Full 5 5 5 5 3
Week 2: 5 5 5 5 3
Week 3: 5 5 5 5 3
Week 4: 5 5 5 5 3

For the incremental backups:

Use Bourne Shell at the prompt.

#for i in 0 1 3 4 6 7 (These numbers represent the partitions you have configured as file systems)
#ufsdump 5cfu /dev/rmt/0 /dev/rdsk/c0t0d0s$i (If Friday's tape, use 3 instead of 5)
#echo $i done

Tuesday, October 17, 2006

A Quick and Dirty Tutorial on VI Editor


i (insert before cursor)
a (insert after cursor)
A (insert at the end of the line)
o (open new line below cursor)
O (open new line above cursor)


Return (moves to beginning of line)
x (deletes single character), 3x (deletes three characters), ...nx (deletes n characters)
dd (deletes single line), 5dd (deletes 5 lines), ...ndd (deletes n lines)
d^ (deletes to beginning of line)
d$ (deletes to end of line)
D (deletes to end of line)
J (joins current line with next line)
dG (deletes to end of file)
yy (copies single line), 5yy (copies 5 lines), ...nyy (copies n lines)
y$ (copies from cursor to end of line)
p (pastes lines)
dw (deletes single word)
cw (changes single word)
r (replaces single character)
n (repeat previous search)
N (reverse previous search)
. (repeats previous command)
u (undo last command)
U (undo a line of changes)
G (go to last line)
1G (go to start line)
7G (moves to seventh line)
0 (zero goes to start line)
^ (go to beginning of line)
$ (go to end of line)
w (moves to word)
W (moves to next space delimited word)
b (moves back a word)
B (moves back a space delimited word)
~ (transpose a case)
control+f (moves forward a screen)
control+b (moves back a screen)
control+u (moves up half a screen)
control+d (moves down half a screen)

/PATTERN_TO_MATCH (move forward to pattern)
?PATTERN_TO_MATCH (move backward to pattern)

:1,5d (delete lines 1-5)
:1,5m 10 (move lines 1-5 to 10)
:1,5t 10 (copy lines 1-5 to 10)

Access Unix commands

Replaces topbloglist to topbloglists
:13,25:/topbloglist/topbloglists/ (replaces lines 13-25)
:1,$:s/topbloglist/topblogists/g (global replace)

:set list (displays non-printable characters)
:set nu (set line numbers)
:set ts=number (sets tab stops)
:set all (show all settings)
:set wm=5 (wrap lines 5 from right margin)

*Use keyboard arrows to move (1 character left/right OR 1 line up or down) around or <- h, j - down, k - up, l ->

To save and exit vi:
:w filename
:w (if filename was provided when vi was invoked)
:w >> filename (append to existing file)
:q! (quit without saving)
:wq! (quit and save--overrides write permissions)
:ZZ (quit and save--does not override write permissions)

vi filename
(now press ESC)

Friday, October 13, 2006

Detailed Hardware Specification Information --- Solaris

Customer requested detailed information on 1.2GHz CPU's which are installed in a SB 2000 workstation. The information was procured with the following command:


Be forewarned that the output can be fairly verbose.

Thursday, October 12, 2006

View Processor Speed and RAM Size --- Solaris

Today I had a request for processor speeds, clock, RAM size, and the type of framebuffer for a Sun Blade 2000 workstation. I used the prtdiag command to get this information.

Here is the path.

# /usr/platform/sun4u/sbin/prtdiag -v

If you want the CPU speed(s) only:
# psrinfo -v

If you want RAM only:
# prtconf | grep Memory

Wednesday, October 11, 2006

Write to An Unwritable Partition

You can write to an unwritable partition using this simple syntax. Many security engineers strongly encourage SysAds to lock down (read only) their/usr partitions. However, this can present problems during upgrades. Here's a quick and dirty workaround.

#mount -F ufs -o rw,remount /usr

Frankly speaking, I've only been able to remount /usr to write. I've always had to reboot the system for read only to take effect. Suggestions?

Create a Directory and its Subdirectories All At Once

Make a directory, set permissions, and create subdirectories all at once.

#/usr/bin/mkdir -m 777 -p /home/esofthub/newsubdirectory/newsubdirectory/...

Tuesday, October 10, 2006

Get Time and Then Set Date and Time

Get the date
# date +%T
shows hh:mm:ss

Set the date/time
# date 10102248
sets the date and time to Oct 10, 10:48 pm
# date 2251.34
sets the time to 10 hours 51 minutes 34 seconds pm

Display Date
# date
Tue Oct 10 22:49:55 KST 2006
# date '+%h %d, 20%y'
Oct 10, 2006

Dump Filesystems to Tape via Command Line

Dump all your filesystems to tape via command line. You can insert the information below in a shell script or do an inline script like the one below. This example also rewinds and ejects the tape.

#for i partition in 0 3 4 6 7; do; /usr/sbin/ufsdump 0uf /dev/rmt/0n /dev/rdsk/c3t0d0$partition; done; mt offline

First 10 Lines and Last 10 Lines of a File

Often we need to display the first or last few lines of a logfile. Normally, we do this for debugging purposes.

Here are a few examples:

This shows the first line
# head -1 logfile
This shows first 5 lines
# head -5 logfile
This shows first 10 lines
# head logfile (default is 10 lines -- no options required)
This shows first 50 lines
# head -50 logfile
This shows first 100 lines
# head -100 logfile

You should get the picture by now

This shows last line
# tail -1 logfile
This shows last 5 lines
# tail -5 logfile
This shows last 10 lines
# tail logfile (this is the default and it shows you the last 10 lines)
This shows last 50 lines
# tail -50 logfile
This shows last 100 lines
# tail -100 logfile

If you want to continuously monitor a logfile, do the following:
# tail -f logfile

This gives you the first line
# sed q logfile
This show you the first 10 lines
# sed 10q logfile

Find and Delete Files

Sometimes there is a requirement to find numerous file and then delete as they are found. One type of file that is commonly deleted is the core file. When something goes wrong with a program, the operating system generates it for debugging purposes. Normally, they are just deleted upon detection.

/usr/bin/find / -name core -type f -exec rm {} \;

You can replace the file named core with your specified filename. The "/" is the absolute path for root but you can replace it with any path name, e.g. /home/esofthub, /usr, /var/adm, /opt, /etc.

Monday, October 09, 2006

Split Up a Big Binary or ASCII File and Email

We had to email a 75 megabyte binary file to the states. Unfortunately, the email server doesn't allow for attachments over 10MB. We had to split it up and have it reconstituted at the distant end.

Here is what we did to accomplish this task.

# split -b 5m FileToBeSplit

This instance splits FileToBeSplit into 16X 5MB segments named xaa xab xac...xap.

Now reconstitute at the distant end:

# cat xaa xab xac xad xae xaf xag xah xai xaj xak xal xam xan xao xap > ReconstitutedFile
# cat * > ReconstitutedFile -- ensure xa* are the only files in the directory when using the wildcard

For ASCII files: Split lines -- This example splits a document into 1000 line segments.

# split -l 1000 FileToBeSplit
After this syntax change, the procedures are the same as binary.

--For larger files, find a ftp server or make your filesize increments bigger.

Sunday, October 08, 2006

Copying a File/Directory

Copy a file or directory is very easy. Well, it's always easy once you know... You will need to use the the cp (copy) utility. It's a very easy utility to use.

Here are some quick points.

cp originalfile newfile -- Copies contents of originalfile into newfile. The permissions and attribute information are not preserved.

cp -p originalfile newfile -- same as above, except the permission and attribute information are preserved.

cp -pr originaldirectory newdirectory -- same as above, except the permissions/attribute information are preserved. One big thing here, the -r is recursive. It copies the directory and its contents.

#cp esofthub.dat esofthub1.dat (permissions not preserved and user/group information possibly different)
#cp -p esofthub.dat esofthub1.dat (permissions and attribute information preserved)
#cp -pr esofthub_dir esofthub1_dir (permissions and attribute information preserved)

Renaming a File

So you want to rename a file? You will need to use the mv utility, which is short for move. Here's what you will need to do.

mv orginalfilename newfilename

#mv esotfhub.dat esofthub.dat
or #mv -f esotfhub.dat esofthub.dat (the -f option forces the command -- turns off interactive mode)

If you want to move the contents of a file or directory to another partition, it behaves like the cp (copy) utility. Here's the exception -- it deletes the original source file/directory once its task is completed unlike cp.

Saturday, October 07, 2006

Open Floppy Disk Sometime Today!

Recently I had a frustrated customer ask me, in coy manner, how to open a floppy. I had to chortle a bit. Window systems are a no-brainer for this task but UNIX systems are not as trivial.
You can use the file manger GUI and use its open floppy option. This should be the easiest method for newbies.

Find the file manager (picture of drawer) on the desktop panel and double click it. File-> Open Floppy drive

or via command line

#filemgr & (The ampersand runs the file manager in the background)


#volcheck -v (runs the volume manager and mounts the floppy drive.)
#cd /floppy

Your floppy is now mounted and available for viewing. The -v is for verbose mode.

Server/workstation Uptime Please

Yesterday, I was asked how long the server had been up. I told the inquirer, "quite awhile." Apparently, he wanted firmer statistics. Here's what I did to satisfy the request. I used the UNIX uptime utility.


Here's an example of the output.
12:19pm up 65 day(s), 42 mins, 13 users, load average: 0.39, 0.56, 0.10

Don't Remove Those Log Files! -- Zero Them Out.

Here's a technique I use periodically to empty the log files. I simply could remove the file but then I would have to recreate the file and then reset the attributes, i.e. permissions, ownership, ACLs, etc.

Here's the technique.

# cat /dev/null > logfile

This preserves the attributes of the logfile and resets the byte count to zero.

Combine Contents of Multiple Files Into One.

Two days ago, I had to combine 8 large data files into one. Each file contained a list of CSV data that needed to be parsed into one file. Here's what I did.

#cat file1 file2 file3 file4 file5 file6 file7 file8 > mynewfile

more examples...

#cat file1 file2 > newfilename

#cat file1 file2 file3 > newfilename

#cat file1 file2 file3 file4...filen > newfilename (You should be getting the idea by now...)

The ">" system is a redirect.

By the way, cat is short for concatenate or join.

Thursday, October 05, 2006

Install 4mm Tape Drive

We connected a 4mm tape drive to our workstation; however, customer didn't want to take the system down to reconfigure (boot -r) the device. We performed the following actions.

For Solaris 8 or higher, you can use the following command:

#devfsadmin (automatically finds device)

Else use legacy style:

#drvconfig -i st (in this case, specifies scsi type, i.e. tape drive )
tapes (command to create /dev links)

Wednesday, October 04, 2006

Installing LTO3 tape drives

Today we attempted to install a LTO3 tape drive unit onto the baseline system. However, the tape drive would not respond to user initiated commands. Why? Apparently the operating system was not patched correctly per LTO3 documentation. How did we figure that out?

showrev -p | grep patch number

In this case, it was the following:

#showrev -p | grep 108725

This outputs information regarding the LTO3 tape driver.