Friday, December 29, 2006

Quick and Dirty Setup of the Internet

I had several Sun workstations that needed Internet access. But first I need to point to a nameserver and then properly configure the name service.

Here's what I did.

Modified the /etc/resolv.conf file. I put these entries into it.

#vi /etc/resolv.conf
:wq! (saves and quits vi)

Modified the /etc/nsswitch.conf file. I added the dns entry into it.

#vi /etc/nsswitch.conf
hosts: nis files dns [NOTFOUND=return]
:wq! (saves and quits vi)

Sunday, December 24, 2006

How to Check email via Command Line

Check your mail with mailx

Here's how to do that.

--If you type "?", you will get a list of help messages. For example, if you want to save all messages to a file, type the following:

(Type "?" for help)
s * saveallmail (hit enter)
quit (hit enter to exit mail)

Troubleshooting with mailx -v (Sendmail and Mail)

On a number of occasions, I have used mailx -v to trouble shoot problems with Mail and Sendmail. Here's what I do.

#mailx -v (hit enter)
Subject: Top Blog Lists (hit enter)
Top Blog Lists has hit 100 members in less than 3 weeks. Join other successful bloggers at (hit enter)
. (hit enter)

--Watch the output scroll--

mailx coupled with -v are very useful because they provide the verbose output of Sendmail. It shows the connection, session and disconnect. It's very useful for troubleshooting purposes (e.g. viewing IPs, DNS, mail configurations, version numbers, etc).

Attach a File to Message via Command Line

I'm frequently asked how to attach a file(s) to an email message via the command line. Here's how I do it. By the way, the mail recipient will need to use uudecode.

Here's an example of an email attachment.

# uuencode my_binaryfile1 | mailx -s "Email binary as attachment"

For multiple attachments, I use a mail client such as dtmail, Netscape or FireFox. But I've seen this done too.

# uuencode my_binaryfile1 my_binaryfile2 | mailx -s "Email binary as attachment"

For NON-binary type files

Please note the ~r (tilde command followed by r)
# mailx (hit enter)
Subject: End of Week Status Report (hit enter)
~rendofweekstatus.dat (hit enter)
~. (hit enter)

The above procedure (non-binary) works great for inline text files.


# cat endofweekstatus.dat | mailx -s "End of Week Status Report"

Set up a Cron Job and Email the Results

Last week I setup a cron job to email a weekly status report to a group of logins. The group of logins was defined by an alias in the /etc/mail/aliases file. The crontab was modified to accomplish this task. Here's what I did.

# crontab -e (crontab editor)
45 06 * * 05 sort /home/esofthub/endofweeklystatus.dat | mailx -s "End of Week Status Report" aliasedgroup
:wq! (save results)

The minute is 45
The hour is 06
The day of the month is any (*)
The month of the year is any (*)
The day of the week (05) is Friday

Wednesday, December 13, 2006

Convert a ISO Standard to DOS and vice versa

Occasionally, there is a need to convert a UNIX formatted file (or files) to a DOS format and vice versa. As a unix system administrator, I’ve performed this task many times. In the examples below, I’ll demonstrate the task singly and then multiple using an inline loop.

Convert an ISO Standard formatted file to DOS standard formatted file

# csh
# unix2dos filenameUNIX > filenameDOS
# foreach i (*)
? unix2dos $i > $i.$$
? mv $i.$$ $i

Convert a DOS formatted file to ISO standard formatted file

# dos2unix filenameDOS > filenameUNIX
# foreach i (*)
? dos2unix $i > $i.$$
? mv $i.$$ $i

Saturday, December 09, 2006

How to Capture xterm/cmdtool Output

When you are performing an upgrade/installation via command line, you might want to capture the steps/procedures in real-time. There is a convenient way of doing this task.

#script -a /tmp/outputfilename (whatever is typed after this command execution is captured)

When you are done, enter control d to terminate the capture process.

How to Change the Values of the PROM (EEPROM)

For security purposes, you might want to password protect your Open Boot Prom (OBP). This will prevent unauthorized changes of your prom settings.

#eeprom (gives you a default listing)
#eeprom security=command
enter new prom password (it prompts you for a new password)

To remove the OBP password
#eeprom security=noneopen

Sunday, December 03, 2006

Append an Entry to a File

There are many situations in which you may want to append an entry to a file. Here are two ways of doing it.

#echo " myhost" >> /etc/hosts
#cat >> /etc/hosts
" myhost" (hit enter)
then execute a control d

Display Only Unique Lines From a File

There are many situations in which you may only want to display unique lines. Here is an easy way of doing it.

#uniq filename

e.g. #uniq filename > outputfile (All of the duplicate lines are filtered out. outputfile only has unique lines in it.)

Thursday, November 23, 2006

Create Tables and Add Constraints -- Oracle

Here's an easy way to create, configure and populate Oracle tables. It can be done from the command line but that can be quite cumbersome, especially if you need to make changes.

Open up a new file in Notepad
Populate it with your create, constraint, drop, insert and etc statements.
Save the file as filename.sql (don't forget the .sql extention)

**you will be prompt for login/password information**
--The "@" symbol executes the contents in the filename.sql file
--If you have errors/modifications, simply open the filename.sql in Notepad and make the necessary changes
--Then rerun the file using the "@" symbol

Friday, November 17, 2006

Drop Database Table Command -- Oracle

When a table is no longer needed in the database, you may want to drop it. But if it has referential integrity, a simple "drop table tablename" won't suffice.

You will need to do the following:

SQL>drop table tablename cascade constraints (which removes the referential constraints)

Monday, November 13, 2006

How to Mount and Eject a Floppy

How to mount and dismount a floppy on a Solaris box.

#volcheck -v (to mount)
#cd /floppy (check contents)
To eject
#cd /
#eject (to remove floppy or CDROM)

You can also use the filemanager (GUI based) to do the same as the aforementioned.

Saturday, November 11, 2006

How to Add a Disk (hard drive)?

For Solaris 7 and below...

You can add the hardware and issue the following commands depending on driver:
#drvconfig -i sd
#drvconfig -i dad


You can reboot the system after adding the hardware.
#touch /reconfigure
#init 6


At the OBP
boot -r

You can use the same commands for Solaris 8 but you can also use the following command:
#devfsadm (it automatically detects the hardware)

Add a Tape Drive

For Solaris 7 and below...

You can add the hardware and issue the following commands:
#drvconfig -i st


You can reboot the system after adding the hardware.
#touch /reconfigure
#init 6


At the OBP
boot -r

You can use the same commands for Solaris 8 but you can also use the following command:
#devfsadm (it automatically detects the hardware)

Tuesday, November 07, 2006

How to get Files From a Remote Server

You will be asked for login/password information following the first step unless anonymous.

ftp>cd /tmp/TEMP (on remote workstation)
ftp>ls (on remote--file named filename)
ftp>lcd /tmp/MYLOCAL (on local workstation)
ftp>get filename (places filename into /tmp/MYLOCAL)

Use mget (multiple files) instead of get if you want to FTP everything from the remote directory into the local directory

Wednesday, November 01, 2006

How to FTP Local File(s) to a Remote Server

You will be asked for login/password information following the first step unless anonymous.

ftp>cd /tmp/TEMP (on remote workstation)
ftp>lcd /tmp/MYLOCAL (on local workstation)
ftp>!ls (on local--file named filename)
ftp>put filename (puts filename into remote's directory, /tmp/TEMP)

Use mput (multiple files) instead of put if you want to FTP everything from the local directory into the remote directory

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.

Wednesday, September 27, 2006

Change User/Group Attributes to a File

It's very simple.

For User:
chown username filename
chown username directoryname

chown -R username directoryname

For Group:
chgrp groupname filename
chgrp groupname directoryname

chgrp -R groupname directoryname

Change groupname and username at the same time.
chown username:groupname filename
Change username and groupname at the same time recursively.
chown -R username:groupname directoryname

File Permissions -- Solaris

To change the mode on a file or directory. I prefer the octal (0-7) format.

r -- read (has value of 4)
w -- write (has value of 2)
x -- execute (has value of 1)

rwxrwxrwx chmod 777 filename
rw-rw-rw- chmod 666 filename
r--r--r-- chmod 444 filename
-w--w--w- chmod 020 filename
--x--x--x chmod 001 filename
--------- chmod 000 filename

To make it recursive, use the -R option.

e.g. #chmod -R 777 directoryname

Dump File and Load File -- Sybase

We have a script to dump user created databases on daily basis via a cron job. However, you can dump and recover a user database on demand.

Here are the steps.

To dump a user database to file:
Ensure that you have permissions to write to the destination directory.
1>use master
1>dump database databasename to '/raid/sybdumps/dump.dat'

To recovered from a database dump file:
Ensure that you have permissions to read the dump file.
1>use master
1>load database databasename from '/raid/sybdumps/dump.dat'
1>online database databasename

Exit Sybase interactive mode

Monday, September 25, 2006

Archived one RAID to Another

We archived the contents of one RAID to another. It takes awhile but it works.

Here’s what we did in single user mode.

#mount /dev/dsk/c1t3d0s0 /DATA1
#mount /dev/dsk/c1t4d0s0 /DATA2

#cd /DATA1; tar cvfp - . | (cd /DATA2; tar xvfp -)

mount – utility used to mount the UFS block devices to /DATA1 and /DATA2 directories
UFS – UNIX File System
cd – change directory utility
tar – tape archive utility

Sunday, September 24, 2006

Create a Database Table -- Oracle

A co-worker and I added a table into one of our Oracle databases. Here's what we did.

sql> create TABLE tablename
(columnname1 number(4),
columnname2 varChar2(10),
columnname3 varChar2(10),
columnname4 varChar2(10)
Table created.

create – command

TABLE – type of object to be created

tablename – name given to table, e.g. car

( – begins parameter list

columnname – attribute information, e.g. color

number – datatype e.g. 4, 5 and column width e.g. (4)

varChar2 – datatype e.g. Phoenix123 and column width e.g. (10)

); – ends parameter list

Friday, September 22, 2006

Finding a User With Niscat

Today, I was asked to lookup a user who left over a year ago. We maintain three different name services. The local name service is files and the organizational name service is NIS+. The third one is DNS, which is used to lookup external addresses.

How did I quickly find the user via command line?

I used the following commands:
For files: more /etc/passwd | grep -i username (if you know it or some other known string)
For NIS+: niscat passwd.org_dir | grep -i username

By the way, the user was located in the NIS+ domain. The user was deleted.

Thursday, September 21, 2006

Create an Index for Manual Pages

Built a Solaris box today. I had to search for a couple utilities to complete the task, but the OS doesn't come configured with an index. I executed the catman utility to build the windex database. Here's the syntax:
#catman -w

Now I can use the man -k pattern to search the database. The -k is the keyword option.

e.g. man -k hme (finds 100Mb NIC interface information)

Restrict Row Count (Database) -- Sybase

Yesterday, a co-worker of mine asked me how to restrict the number of rows for his select statements. He only wanted 10-20 row returns but his queries returned thousands. By the way, we are running Sybase 12.0 DBMS.

Here's what we came up with.
1>use database
1> set rowcount 10
2> go
1> select * from table where ID='XXXXX'
2> go

Reset to default definition.
1> set rowcount 0
2> go

Wednesday, September 20, 2006

Extracting an Archive From 4mm/8mm Tape

I'm continuing to build on my last post. Moreover, I use tar to extract archive files and directories from tape. This is a lifesaver when you have to restore critical file(s) or directories.

1. tar xvfp /home/directory/filename.tar directoryname

e.g. #tar xvfp /home/esofthub/esofthub.tar esofthub

The aforementioned action extracts the esofthub directory from the esofthub.tar file.

tar – Tape archive utility
xvfp – Extract, verbose, file, preserves permissions -- flags/options
/home/esofthub/esofthub.tar – A tarball
esofthub – The esofthub directory and its contents

2. #tar xvfp /dev/rmt/0 /home/esofthub/esofthub.tar
/dev/rmt/0 – Here’s how to extract a tarball file from tape.

3. #tar xvfp /dev/rmt/0
/dev/rmt/0 – Here’s how to extract all the contents from tape.

Monday, September 18, 2006

Creating an Archive to 4mm/8mm Tape

Tape archive is another utility that I use frequently. I used it to archive files and directories. It is really handy when you want to ftp a group of files or directories.

1. tar cvfp /home/directory/filename.tar directoryname

e.g. #tar cvfp /home/esofthub/esofthub.tar esofthub

tar – Tape archive utility
cvfp – Create, verbose, file, preserves permissions -- flags/options.
/home/esofthub/esofthub.tar – A tarball file
esofthub – The esofthub directory and its contents

2. #tar cvfp /dev/rmt/0 /home/esofthub/esofthub.tar
/dev/rmt/0 – Here’s how you archive to a tape device.

Saturday, September 16, 2006

An Inline Shell Script with a For Loop

Often I'm asked how to traverse a list of items in a file. You can easily go through a list of items using a for loop. Here's an example of copying selected contents of originalDir to destinationDir via the command line.

#for i in `cat /home/esofthub/mylist.dat`
#cp -pr /originalDir/$i /destinationDir/.
#echo $i done

sh – shell

cat – lists each item in the list one iteration at a time

cp – the copy utility for a local workstation (plain files and directories, no symbolic links)

-pr – these options preserve the permission, "p" and copies recursively, "r"

echo – lists the item copied

Perform Recursive Searches for Strings in Hidden Files

I am often asked how to locate certain strings in a directory path. Most of the time, the user is looking for a string they saved into a file in their home directory. But often they forget which file the string was saved to and only remember parts of the string. I had one user who forgot he saved a control sequence to a hidden file. He only remembered a few characters of the string.

This is only an example and for illustration purposes.

# cd $HOME
# find . -type f | xargs grep -i 43Y

Note: More info on hidden files (Find, Copy or Delete Hidden Files)

Find, Copy or Delete Hidden Files in a Directory

I'm often asked where are the hidden files located on a system. My response to a user: Mostly in your home directory. Most are probing for their .profile or .cshrc file. I tell them to use the ls command coupled with the "-a" option. The "-a" shows the hidden files.

# cd /home/esofthub
# ls -la

Bonus: Copy hidden files or directories to a directory or delete hidden files and directories from a directory (per reader's request).

# cp -p .hiddenfile my_destination_directory
# cp -p .login my_destination_directory
# cp -pr .hiddendirectory my_destination_directory
# cp -pr .* my_destination_directory (copies all hidden files and hidden directories recursively)

To delete a hidden file or directory, make sure you know where you are at before performing the activities below.

# pwd
# rm .hiddenfile
# rm -r .hiddendirectory

To delete hidden files and directories as a wildcard (deletes all hidden files in the current directory and directories recursively)
# rm -r .*

Even though I was referring to $HOME, this reader makes a good where you are at on the system - pwd

Petr Smid said...

Be CARFEUL!!! If you do rm -rf .* you will delete the entire disk (because .* applies to .. as well)