home news blogs forums events research newsletter whitepapers careers


UBM Network Computing
TechWeb
HOT PICKS

IMMERSE YOURSELF:

SOA

  |

Data Center

  |

802.11n

  |

Data Privacy

  |
APO  |

Virtualization

  |

NAC

  |

Security

  |

Network Mgmt

  |

Enterprise Apps

  |

Storage & Servers



 

   Linux and Unix Q and A



October 30, 2000

Got Questions?
We've Got Answers!

Thank you for submitting your questions to Neil Matthew and Richard Stones, joint authors of Beginning Linux Programming.

Brought to you by:




Check It Out!




Question 1:

Q: I have to virtually change system date and time (many times during script execution) to skip the limit of software which I use. It would be best if I just increment the date. If I try to set the date and time, it only works the first time, but the next iteration changes the time.

Rick Stones responds:

A: Leaving aside the question of why you need to adjust the date to keep your S/W running, there is no standard 'only set the date' function from shell scripts; you have to set both the date and the time. Your method of finding the date and time then incrementing the date portion should work fine. It sounds more like you have a bug in your script than a problem with the operating system.

Here is a simplistic script (it doesn't check for the month changing!) that increments just the day:

for i in 1 2 3 4 5
do
NOWDATE=$(date +"%m %d %l %M")
set $(echo $NOWDATE)
DAY=$2
DAY=$(expr $DAY + 1)
date $1$DAY$3$4$5
echo date is now `date`
done

Question 2:

Q: This is regarding Global Search & Replace. How do I replace a string "NSPay" with the String "/applications/name1/name2/reports"? The slashes are giving me errors.

Rick Stones responds:

A: I presume this is because you are trying to use a command such as s/ NSPay /
/applications/name1/name2/reports/

All you need to do is use '=' as the delimiter instead, like this:

s= NSPay = /applications/name1/name2/reports=


Question 3:

Q: What makes UNIX better than Windows NT or other operating systems? What special features does it have that other OSes don't?

Rick Stones responds:

A: Well that debate could rage for a while!

I'd sum it up briefly as:

Much easier to program, more stable, more performance and more scalable under load.

A bonus is that with Linux you don't have to pay a tithe to Bill Gates every time you want to use a computer :)


Question 4:

Q: I am finding the learning curve from Windows to Linux is difficult for me. I think Bill has me brainwashed. I don't understand how to "see" other machines on the mixed network or Windows2000/NT 4/Mandrake Linux. I have the SAMBA thingy loaded, (I think) and someone said I have to mount the share? How can you "see" the server to mount it? And if you can't see it, then how do you know the name of it to mount it? Is this confusing or am I way out in left field? Or am I just looking through the wrong window? ;)

Rick Stones responds:

A: I'm assuming here that you are trying to mount a filesystem shared out from an NT box so it is visible from Linux. SAMBA has components for working both ways, so you can share out Linux directories for Windows to mount, and mount Windows shares under Linux.

First, the command line program you need to look round is sbmclient. It's possible that you only have the base components of SAMBA installed, so if you don't have an sbmclient command, go back to your distribution and dig out the rest of the SAMBA components. Then you can use 'smbclient -L <servername>' to list the shares and workgroups. To actually mount a drive you need to first create the target directory under Linux, then use a command such as smbmount //server/sharename /mnt/localdirname -U username.

SAMBA is a big topic. There are loads of information on www.samba.org, and also at http://samba.linuxbe.org/. Wrox's 'Pro Linux Deployment' has a chapter (2) on the subject, and O'Reilly has a whole book (Using SAMBA) on the topic.


Question 5:

Q: How do you do a disk partitioning to have Unix and Windows 98 in one machine?

Neil Matthew responds:

A: You can persuade Windows and Linux to share a single hard disk by partitioning the disk into separate areas and installing each of the operating systems into one or more of these areas.

If you have an empty hard disk you can boot from a floppy disk (the Windows 98 Emergency Boot Disk is good for this) and run the FDISK program to create a partition to install Windows into. You need to make sure that the partition you create does not entirely fill the disk, to leave room for Linux.

If you already have Windows on the PC you need to resize the partition that it is using. This can be done either by using a commercial product such as Partition Magic, or the free utility FIPS. You can find a copy of FIPS on most Linux distribution CDs.

As long as there is unallocated space on the hard disk, most Linux installations will be able to use it. If you boot from the first CD of a modern Linux distribution you will be able to direct the install to use the free space, without disturbing Windows.

You can arrange to run either Windows or Linux when the PC boots if you allow Linux to install LILO, its boot manager. I prefer to arrange install LILO on the same partition as Linux (rather than the Master Boot Record option), and make the Linux partition the "active" one by using FDISK again - so that Linux boots by default. You can add an option to LILO to allow Windows to be selected whenever you need to return to the Microsoft world.

Your Linux distribution CD should contain documents that you can read under Windows to learn more about installation before you actually do it, so if some of the terms I've used are unfamiliar they will be explained there.


Question 6:

Q: How do you set the present working directory as the prompt in the C-shell?

Neil Matthew responds:

A: I can only answer this question for a version of the C-shell available on Linux systems, but they may provide a clue if you are using another UNIX system.

The C shell uses a variable called "prompt" for the prompt. Essentially it just prints the value of this variable before reading the next command from the user.

You can set the prompt variable just like any other, so to get a personal prompt you might do this:

set prompt = "Yes? "
Yes? date
Wed Sep 20 22:09:33 BST 2000
Yes?
Here we have set the prompt to the string "Yes? ". The prompt variable can contain some special sequences which are substituted for various things. In tcsh (the version of the C shell on Linux) some of these are:

%~ the current directory
%C the last component of the current directory
%m the hostname
%t the current time
%d the current day
%n the current user
So we can get a nice prompt with

set prompt = "%n@%m %d %~> "
neil@gamer Wed ~/Ciphers>
If you don't have tcsh on your system, I suggest you grab it from the 'net and install it. You should find source here:

ftp://ftp.astron.com/pub/tcsh/

Some versions of csh that do not have these sequences may respond to the following 'hack'. You can set the prompt to be the current directory and then define your own change directory command (cd) which resets the prompt ans well as changing directory. Try putting this in your .cshrc file to see it it works for you:

alias cwdcmd 'set prompt="$cwd:t> "'
alias cd 'chdir \!* && cwdcmd'

Question 7:

Q: I have a 3D Rage Pro AGP 2X video card with 8MB ram and I'm using the 2.2 release of Debian. My problem is that my Helix-Gnome wm looks grainy as opposed to what I see in helixcode's website. I have setup X to use 1024x768 resolution but still I get the grainy desktop. How can I make my helix-gnome look like what it should be?

Neil Matthew responds:

A: One thing that occurs to me is that the color depth may be set incorrectly. It is possible that your X is setup with configurations for 256 color mode, 65536 colors and possibly 16.7 million colors as well, since the Rage Pro is capable of all of these.

When you start X it has a habit of defaulting to the first color depth it finds, and this may well be 256 color mode. If this is the case then X has to reduce the colors it uses to just 256. This results in grainy graphics, especially if they have been designed to use more colors.

You can force X to use a larger number of colors by specifying the color depth when you start X with start x. The option you need is bpp (for bits per pixel), and you choose 8, 16 or 24 (for 256, 65536 or 16.7M colors). This is a server option, so it has to be separated from client options to startx. In practice you just need to type:

startx -- -bpp 16
or
startx -- -bpp 24
You can change the default behaviour of X by editing its configuration. Look at the XF86Config file (its location varies, on RedHat it's in /etc/X11) and in the "Screen" section add a line:

DefaultColorDepth 16
(or 24)
Or, try running the X setup program again (whichever one you used) and selecting just the screen resolution and color depth you want.


Question 8:

Q: How can I run my application on a separate console/terminal window?

Neil Matthew responds:

A: I assume you are running with the X Window System. You can use xterm to start an application in a new console-type window. Just use the -e option like this:

$ xterm -e program argument argument ... &
This creates a new window and runs the specified program in it. When the program ends, the window closes. The -e option to xterm tells xterm to run just the program given and then quit.


Question 9:

Q: What minimum hardware configuration would you recommend for a Unix network server?

Neil Matthew responds:

A: For a Linux-based server the minimum specification is probably something like this:

Pentium 200
64Mb RAM
2Gb hard disk

although I have run a useful server (in fact a network bridge) with

386 20MHz
2Mb RAM
No hard disk

It booted Linux from a floppy and acted like a router, controlling network traffic between two network interfaces.

The best answer I can really give is "it depends what you need it to do". Often you can get good results for a print server from very low-spec servers, but a database server will benefit from lots of CPU power and RAM.

The approach top take is to try to think about the applications it needs to support, the number of users, the predicted network traffic and try to calculate what you need.


Question 10:

Q: To find out whether a TCP port is opened on a machine, what's the command?

Neil Matthew responds:

A: Try netstat -a

This lists all of the open sockets on a UNIX system, including those waiting for connections. It also lists the port number being used by the remote end.


Question 11:

Q: How do I FTP a one gig directory from an NT server to a Unix machine? Is it realistic to expect to FTP to a Unix machine for such a large directory with HTML files?

Neil Matthew responds:

A: The approach I would take would be to pull the files from the NT box to the UNIX box by using a program, such as mirror, that has been designed for creating replicas of directory structures.

I would not attempt to push from the NT box as the NT FTP client is in my experience very unreliable.

There is a Perl-based version of "mirror" that can run on any UNIX platform that has Perl installed. It will FTP all the files in all of the directories you need, and as a bonus will only transfer files that have changed next time you need to do it. You will need to setup NT with an FTP server.

Get mirror here: http://sunsite.org.uk/packages/mirror/


Question 12:

Q: How do we install Linux from an ISO image? Once burnt on a CD, will the ISO image be readily bootable as the present-day distribution CDs are?

Rick Stones responds:

A: All you need to do is ensure that when you write the ISO image you set the burning S/W to make the image bootable. It's that easy.


Question 13:

Q: I am a small system consultant in Louisville, KY. My clients typically are small, very conservative companies with an installed base of Windows applications in an NT environment. Does it make any sense to try to get them to move to a UNIX or Linux environment, or do you think I would be better with the "status quo?"

Rick Stones responds:

A: Probably the best way, assuming you want to install Linux, is to appeal to the bottom line - i.e. it's cheap but reliable. Start with a potential customer who only needs basic services, such as file and print sharing, or maybe a basic Internet gateway, and offer them a Linux solution that requires no license costs and runs on smaller H/W than the equivelent M$ installation. It's probably best to pick something that requires almost no user intervention, so they don't get users complaining "It's not Windows. I don't know how to..."

Once you get someone that accepts the offer, you can tell the next customer, "Client X of mine uses Linux, it saved them Y and they are finding it a very stable solution."


Question 14:

Q: Which is the best book for Unix that even a layman can understand? It should be a complete reference manual for Unix administration and networking with syntax and examples.

Rick Stones responds:

A: There are surprisingly few UNIX-specific books, probably because most UNIX vendors want to sell you courses or provide extensive manuals along with the operating system. There are also significant differences between the different vendors' versions. For Linux, which is much less fragmented, there is a wide choice. There are five books I'd suggest you look at initially:

Browsing in a book store before purchase is probably the most sensible option, especially if you are not sure of the appropriate technical level for your needs.

For programming Linux, try 'Beginning Linux Programming' (Wrox Press) as a "get you started book."


Question 15:

Q: What is the full form of UNIX? Also, what are the various flavors of UNIX and what is the difference between them?

Neil Matthew responds:

A: If you mean, what does UNIX the abbreviation stand for, the answer is that it is not an acronym, but rather a pun. When UNIX was developed it was originally going to be an operating system rather like one current at the time, Multics. It would support just one user in the beginning, so the idea was that is was "Uni" rather than "Multi", hence UNIX.

There are many different flavors of UNIX, but they generally arise from idea in two main variants, known as BSD and System V, which differ in a number of aspects, including terminal handling, disk devices and some applications.

BSD was developed at the University of California at Berkeley and System V by AT&T.

These days there has been a kind of re-integration with the advent of the POSIX standards. Any system able to call itself UNIX must comply with a UNIX standard (aka SPEC1170), although not all conforming systems have been through the branding process.

If you stick to functions and applications defined in the POSIX standard, your programs will run all variants (probably!).

UnixHelp has some information on UNIX variants and commands. You can find it at: http://unixhelp.ed.ac.uk/index.html


Question 16:

Q: Regarding the article "Hooking Linux (Red Hat 6) to the NT - HDPC Server," can you provide me with some information about connecting Linux comp to NT_HDPC Server? This will be highly appreciated.

Neil Matthew responds:

A: Getting Linux to cooperate on an NT network is fairly easy these days. The SAMBA free software product is available for Linux and many other UNIX-like operating systems.

With SAMBA you can share files, use NT printers and even act as a domain controller. Most Linux distributions come with a version of SAMBA ready to install. For more information see http://us4.samba.org/samba/samba.html.

The Wrox book, "Professional Linux Deployment," contains case studies and step-by-step instructions for using SAMBA. More details can be found at http://www.wrox.com/Consumer/Store/Details.asp?ISBN=1861002874.


Question 17:

Q: I have several questions for you:

1. I've created a folder in /bin directory as root, but it is inaccessible to other users. How do I make it available to all users?

2. During forking a process, how can I make the child process wait till the parent finishes its task completely?

3. By mistake, I installed a fishtank background as wallpaper and now I am unable to remove it. Help!

4. How do you install programs for Linux (such as an office suite) from CDs available for free with magazines, for example?

Neil Matthew responds:

A: To make a directory visible to other users, you must change the permissions. The chmod program can do this for you.

To make a directory readable to all users, do this:

chmod a+rx <folder-name

This also makes it searchable, which means users can see what is in the folder, rather than just access files by name directly. Make sure that programs you have stored are also executable by all users by doing this:

chmod a+x <program-name ...

To manage the termination of processes, check out the manual page for wait.

If Linux software is distributed in a package format such as RPM or DEB files, you need to use the corresponding program to install them -- in these cases, rpm and dpkg. If you are running Gnome or KDE, you can use a graphical installer such as gnorpm or kpackage.


Question 18:

Q: What do you think about the future of Unix?

Rick Stones responds:

A: I think the Unix market place will narrow into a smaller range of players, with Linux being a significant part of that. The vendors who have the strongest hardware offerings in the Unix server market will continue to be able to sell their Unix OSes, because when you are buying a 24-processor server with 500 GB of RAID disk space, some money for the OS is not significant. Plus, there are generally specialist tools, such as volume managers, that give you added benefits over Linux (at least at the moment). However, we are already starting to see some cracks. For example, Solaris 8 is "free" for systems with small numbers of CPUs (you still get to pay for media and shipping).

So, I think Unix in the wider sense will continue to have a strong presence in the server market place. It's a stable, scalable and proven platform. At the low end, Linux offers almost unbeatable price/performance. At the higher end, the main vendors (such as Sun, IBM and HP) are generally trying to sell hardware, so they can afford to drop the price of the OS. Microsoft has to make money from its software.


Question 19:

Q: How do I find and replace in the VI editor? Could you please give me the exact syntax of the command?

Rick Stones responds:

A: The short answer is that you are running the wrong editor. You should use Emacs :)

I'm assuming you mean a global replace throughout a file. Put yourself into the command mode: "ESC:". Then you specify the lines over which you want to replace. For the first to the last, use "1,$", then the substitute command "s", then the old and new strings delimited either with a / or = characters. Finally add a "g", if you want to replace all the occurrences of the string on a line, rather than just the first. So, to replace all occurrences in a file of the sequence "qwerty" with "xyzzy," you would type:

ESC:1,$s/qwerty/xyzzy/g

Many Linux systems use vim as a replacement for vi. Just type vi without a file name, and then try ESC:help, and if it's vim you will get to a tutorial.


Question 20:

Q: How do I extract a .gz file so that I can download it to my PC and read it?

Rick Stones responds:

A: On Linux, the answer is simply 'tar zxvf <filename' so I assume you mean on Microsoft Windows. The best tool is probably winzip. See http://www.winzip.com for more information.


Question 21:

Q: How does Unix manage main memory and secondary storage to back up main memory? Could you give me an example with an algorithm?

Rick Stones responds:

A: If you are happy looking directly at code, just download the Linux kernel and have a look! There may be descriptions in some of the Unix/Linux books, but I don't know of a particular book to recommend.


Question 22:

Q: I hope this is an easy one. I've been searching for hours and can't find the answer anywhere!

Programs, particularly things like CGI scripts, are often shown as being written to run on Unix. My question is: What percentage of Web servers use Unix as their operating system? In other words, if one wrote a script for use on Unix, what percentage of sites would be able to use it?

I hope you can help.

Rick Stones responds:

A: The answer to what sites run Unix or Linux is reasonably easy. Have a look at the Web server survey on http://www.netcraft.com. It's probably a good guess that almost all the Apache sites are Unix or Linux, so that gives you a rough estimate, say 60 percent to 70 percent, given that some of the other Web servers are probably also Unix/Linux, excluding IIS, of course.

The second part, what percentage could you run a CGI script on, is a different question, because many Internet service providers are not going to let you upload a CGI scripts and execute those scripts on their Web servers. Depending on the language you use, Perl being a favorite, some will allow you, but they run the script in a restricted environment. Without knowing the problem you have in mind, I'd suggest a better solution: Rather than a CGI script, consider PHP. Support for that is much more common, and it's easy to learn. See http://www.php.net, which also has a list of sites known to support it. Wrox also has a "Professional PHP" book, which tells you quite a lot, and it will soon be joined by "Beginning PHP," which is targeted at people just getting started with dynamic Web sites. Oh, and it works under Windows as well... :)


Question 23:

Q: I have Windows 98 on my PC and have installed Red Hat 6.2. I have made a mount to DOS if I need to go from Windows to Linux, but I have a problem: I can't see the drive Linux from Windows. What must I do to go from Windows to Linux without a floppy disk (I have used the command fdisk/mbr)?

Rick Stones responds:

A: Assuming you still have the floppy to get into Linux, then (as root) just run '/sbin/lilo' which will replace the MBR. If you have lost the ability to get into Linux at all, then boot from the Red Hat CD, with the options 'root=/dev/hda??? single' (where ??? is the partition where you installed Linux), and then run lilo as before. You might also want to look out for a (Windows) program called loadlin, which allows you to boot Linux from a DOS prompt in Windows 9x Have a look round the FTP archives such as sunsite.unc.edu and tsx-11.mit.edu , usually in the Linux-boot or dos_utils directories.


Question 24:

Q: I am running Solaris 2.6 OS on a Sun and while looking at a list of my files I noticed some strange dates. Not the correct date of creation. Is there a way for me to change the file creation date back to the original, correct date?

Rick Stones responds:

A: Now I must admit you have me stumped on that one. You can change the access and modification times with the 'utimes' system call, but there doesn't appear to be an easy way of correcting the creation time. Sorry.


 





Ready to take that job and shove it?

Function:

Keyword(s):

State:
SPONSOR
RECENT JOB POSTINGS
CAREER NEWS
Go beyond Google and get vertical. These specialized search sites will help you find the business information you need -- fast.

Ari Balogh was named to the post of chief technology officer as the companys for a "realignment" of employees.










InformationWeek U.S. IT Salary Survey 2008
Salaries for business technology professionals are falling. Here's what you need to know in order to make good hiring decisions and personal career choices. Purchase Today: $299
 
ROLLING RIGHT ALONG
Follow key Network Computing Reviews from conception to completion. This Week: Holistic APM.



Network Computing Reports Emerging Enterprise Podcast Series: Secrets to Success








TechSearch


Microsite of the Week


Powerful Information at Your Fingertips



App Infrastructure   |   Messaging & Collaboration   |   Network & Systems Mgmt   |   Network Infrastructure   |   Security  |   Storage & Servers   |   Wireless   |   Enterprise Apps
About Us  |  Contact Us  |  Site Map  |  Media Kit  |   Briefing Centers
Other Techweb Sites:   InformationWeek Reports  |  Intelligent Enterprise  |  Light Reading  |  InformationWeek
Techweb  |  Dark Reading  |  Network Computing Germany  |   Byte & Switch  |  bMighty  |  Small Biz Resource  |  InformationWeek Analytics
Copyright © 2008  United Business Media LLC  |  Privacy Statement  |  Terms of Service  |  Your California Privacy Rights