Thursday, December 16, 2004

Using "find" command

The basic format of the find command is:

$ find startdirectory options matchcriteria [actionoptions]

If you know the name of a file, or even part of the name, but not the directory it is in, you can do this:

$ find . -name 'test*'
./test
./jdevhome/mywork/EmpWS/EmpBC4J/test


Unlike classic UNIX systems, the -print action at the end is not required in Linux, as it is assumed if no other action option is designated. A dot ( . ) in the startdirectory position causes find to begin a search in your working directory. A double dot, .., begins a search in the parent directory. You can start a search in any directory.

Note that you can use wildcards as part of the search criteria as long as you enclose the whole term in single quotes.

$ find . -name 'test*' -print
./test.out
./test2.out

To produce a list of files with the .out extension:

$ find /home -name '*.out'


Remember, however, that you will probably get numerous "Permission denied" error messages unless you run the command as supersuser.

One of the most powerful search tools is the -exec action used with grep:

$ find . -name '*.html' -exec grep 'mailto:foo@yahoo.com' {} \;

Here we have asked find to start in the current directory,., look for an html file, *.html, and execute -exec the grep command on the current file, {}. When using the -exec action, a semicolon, ;, is required, as it is for a few other actions when using find. The backslash, \, and quotes are needed to ensure that BASH passes these terms through so they are interpreted by the command rather than the shell.

Wednesday, September 29, 2004

BASHing Your Prompt

Customizing how your command line prompt looks like isn't just cool. It can also be rather useful. You can change your prompt by running the following command: PS1=" ". For example, PS1="[\t] [ \u@\h \W]\$ " will change your command line to something that resembles this: [21:52:01][user@hostname :~]$. To permanently change this, you'll have to alter this in ~/.bashrc

Here are the options available:

\a an ASCII bell character (07)
\dthe date in "Weekday Month Date" format (e.g., "Tue May 26")
\ean ASCII escape character (033)
\hthe hostname up to the first `.'
\Hthe hostname
\jthe number of jobs currently managed by the shell
\lthe basename of the shell's terminal device name
\nnewline
\rcarriage return
\sthe name of the shell, the basename of $0 (the portion following the final slash)
\tthe current time in 24-hour HH:MM:SS format
\Tthe current time in 12-hour HH:MM:SS format
\@the current time in 12-hour am/pm format
\uthe username of the current user
\vthe version of bash (e.g., 2.00)
\Vthe release of bash, version + patchlevel (e.g., 2.00.0)
\wthe current working directory
\Wthe basename of the current working directory
\!the history number of this command
\#the command number of this command
\$if the effective UID is 0, a #, otherwise a $
\nnnthe character corresponding to the octal number nnn
\\a backslash
\[begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
\]end a sequence of non-printing characters

Friday, August 27, 2004

Linux Filesystem

A filesystem is a method for storing and organizing computer files and the data they contain to make it easy to find and access them. Filesystems may use a storage device such as a hard disk or CD-ROM and involve maintaining the physical location of the files, or they may be virtual and exist only as an access method for virtual data or for data over a network (e.g. NFS).


Like UNIX, Linux chooses to have a single hierarchial directory structure, everthing starts from the root directory represented by / and then expands into the subdirectories. Some or all of the following directories, or symbolic
links to directories, are required in /.
/the root directory
/bin
Essential command binaries - /bin directory contains several useful commands that are of use to both the system administrator as well as non-privileged users. It usually contains the shells like bash, csh, etc.... and commonly used commands like cp, mv, rm, cat, ls
/bootStatic files of the boot loader contains files required for booting process
/dev
It is a very interesting directory that highlights one important aspect of the Linux filesystem - everything is a file or a directory. hda1, hda2 etc.... - which represent the various partitions cdrom & fd0 - CDROM & floppy drive This may seem strange but it will make sense if you compare the characteristics of files to that of your hardware. Both can be read from and written to. Take /dev/dsp, for instance. This file represents your speaker device. Any data written to this file will be re-directed to your speaker. If you try 'cat /boot/vmlinuz > /dev/dsp' (on a properly configured system) you should hear some sound on the speaker. That's the sound of your kernel! A file sent to /dev/lp0 gets printed. Sending data to and reading from /dev/ttyS0 will allow you to communicate with a device attached there - for instance, your modem.
/etcHost-specific system configuration
This is the nerve center of your system, it contains all system related configuration files in here or in its sub-directories. A "configuration file" is defined as a local file used to control the operation of a program

/initrdinitrd is mainly designed to allow system startup to occur in two phases, where the kernel comes up with a minimum set of compiled-in drivers, and where additional modules are loaded from initrd
/lib
The /lib directory contains kernel modules and those shared library images (the C programming code library) needed to boot the system and run the commands in the root filesystem, ie. by binaries in /bin and /sbin. Libraries are readily identifiable through their filename extension of *.so. Windows equivalent to a shared library would be a DLL (dynamically linked library) file. They are essential for basic system functionality.

/lost+found
Linux should always go through a proper shutdown. Sometimes your system might crash or a power failure might take the machine down. Either way, at the next boot, a lengthy filesystem check (the speed of this check is dependent on the type of filesystem that you actually use. ie. ext3 is faster than ext2 because it is a journalled filesystem) using fsck will be done. Fsck will go through the system and try to recover any corrupt files that it finds. The result of this recovery operation will be placed in this directory. The files recovered are not likely to be complete or make much sense but there always is a chance that something worthwhile is recovered.

/media
Mount point for removeable media This directory contains subdirectories which are used as mount points for removeable media such as floppy disks, cdroms and zip disks
/mnt
Mount point for mounting a filesystem temporarily This is a generic mount point under which you mount your filesystems or devices. Mounting is the process by which you make a filesystem available to the system. After mounting your files will be accessible under the mount-point. This directory usually contains mount points or sub-directories where you mount your floppy and your CD.Standard mount points would include /mnt/cdrom and /mnt/floppy.
/opt
Add-on application software packages This directory is reserved for all the software and add-on packages that are not part of the default installation. For example, StarOffice, Kylix, Mozilla and WordPerfect packages are normally found here.
/proc
is very special in that it is also a virtual filesystem. It's sometimes referred to as a process information pseudo-file system. It doesn't contain 'real' files but runtime system information (e.g. system memory, devices mounted, hardware configuration, etc). For this reason it can be regarded as a control and information centre for the kernel.

/sbin
Essential system binaries /sbin should contain only binaries essential for booting, restoring, recovering, and/or repairing the system in addition to the binaries in /bin. Normally, these directories are never part of normal user's $PATHs but only of roots. Some of the commands are shutdown, fastboot, etc.
/srvData for services provided by this system
/tmpTemporary files
This directory contains mostly files that are required temporarily. Many programs use this to create lock files and for temporary storage of data. Do not remove files from this directory unless you know exactly what you are doing! Many of these files are important for currently running programs and deleting them may result in a system crash.

/usrSecondary hierarchy - /usr usually contains by far the largest share of data on a system. Hence, this is one of the most important directories in the system as it contains all the user binaries, their documentation, libraries, header files, etc.... X and its supporting libraries can be found here. User programs like telnet, ftp, etc.... are also placed here.
/varVariable data -
Contains variable data like system logging files, mail and printer spool directories, and transient and temporary files. Some portions of /var are not shareable between different systems. For instance, /var/log, /var/lock, and /var/run. Other portions may be shared, notably /var/mail, /var/cache/man, /var/cache/fonts, and /var/spool/news.

/homeUser home directories (optional)
Linux is a multi-user environment so each user is also assigned a specific directory that is accessible only to them and the system administrator. These are the user home directories, which can be found under '/home/$USER' (~/). It is your playground: everything is at your command, you can write files, delete them, install programs, etc.... Your home directory contains your personal configuration files, the so-called dot files (their name is preceded by a dot). Personal configuration files are usually 'hidden', if you want to see them, you either have to turn on the appropriate option in your file manager or run ls with the -a switch. If there is a conflict between personal and system wide configuration files, the settings in the personal file will prevail.

/rootHome directory for the root user (optional)

While using different flavors of Linux (also called various distributions). Some distributions put mount directories for external media into the / directory,others into /mnt. Red Hat based distributions feature the /etc/sysconfig sub-hierarchy for configuration files concerning input and network devices. Other distributions do not have this directory at all and put the appropriate files elsewhere or even use completely different mechanisms to do the same thing. Some distributions put KDE into /opt/, others into /usr.

If you, say, install a KDE RPM from the SuSE Linux distribution on your Mandrake system, the binary will be put into /opt/kde2/bin. And thus it won't work, because Mandrake expects it to be in /usr/bin.

These problems will not arise once you get accustomed to the specific flavor and start liking it. Once you get a chance to know other flavors you will start knowing the difference. All the leading Linux distributors have joined the Linux Standard Base (LSB) project, which is attempting to create a common standard for Linux distributions. This isn't easy, since changing the file system hierarchy means a lot of work for distributors so it will take time but once a standard has been created then there will be no more hassels in understanding the Linux Filesystem.

Still hungry for more information on Linux Filesystem ? Click here to find out more.


Friday, August 20, 2004

Just a day before authors B'day

This IT Knowledge born just a day before the author's Birthday. I wish the author and the IT K. a Very Happy Birthday.

Dear Birthday Baby ....

Bala, Iniya pirantha naal vazhuthukkal da ...

Thursday, August 19, 2004

How this blog started ?

This piece of chat transcript is the answer

su_sivabalan: ennada... enna nadakkuthu
chennaigv: onnum illai da
su_sivabalan: i have a idea ..
arushiva: whats that tell me
su_sivabalan: will take a topic for each ..will start reading that.. and will discuss that so it will be a knowledge for everyone .. what do u say correct me if iam wrong
arushiva: really wonderful da
arushiva: so tomorrow morning we will start reading some topic
chennaigv: okie thats pretty good idea
su_sivabalan: not some topic.. will fix one for each and start looking more into that
su_sivabalan: its should not be one day for each topic..
su_sivabalan: taking one topic .. and try to explore to its core
su_sivabalan: learn more and more out of it .. till you decide.. nothing more on that
arushiva: really great idea machi
arushiva: come lets discuss now and decide the topic for tomorrow
su_sivabalan: first tell me is it goign to be open source or common
arushiva: common da
su_sivabalan: if its going to be open source we can have topics like perl,java, c++,linux,cgi,xml,
arushiva: first lets explore related to our project then we will move on to microsoft products
chennaigv: i guess we can discuss anything under the sun .. but lets discuss what would be helpful in building our career ....
su_sivabalan: but unless until .. we are serious about the subject.. nobody can learn anything out of it
arushiva: true da... i suggest instead of taking the whole language or scripting language we will take modules of a specific language or DB then discuss on that
su_sivabalan: it could be something like .. you can send a whitepapers, pdfs,documents,ppts related to that particular subject you are going to take.. take sometime of your work to get those.. and if you find those would be helpful.. go thru those article prepare a small document of it and send so it is understood by others..
su_sivabalan: Its not something .. you send a url.. and i read it.. its something everyone should know everything about it
su_sivabalan: there should be a discussion over each artcile.. questions has to be raised.. and the person is responsible to answer to those questions next time..
chennaigv: a wonderful thought bala .. so why dont we do this .. we create a blog and try explain what we have understood .. a small description abt the topic / subject
su_sivabalan: if you feel.. its practically impossible .. will drop these idea
chennaigv: this way we would have a log also and can also be looked again for reference ..
arushiva: y cant we start today by creating a blog
chennaigv: no bala its not .. as u have seen kenni's blog like he explains what he has seen or experienced .... we can explain what we have understood .. quote examples .. give links so that this becomes self explanatory ... comments can be posted ..
arushiva: true machi .... the clarifications can be posted in the comments
arushiva: and we can answer the same immediately
arushiva: it will helpful even if some of our friends missed the discussion
arushiva: dei machi why cant we create a group blog
arushiva: so that only whom ever we invite will be able to participate
arushiva: can we create a site using geocities ?? if its available ?
su_sivabalan: i dunno much about it.. what i meant is not put whatever you read in a page.. but to discuss among ourself and try to understand
arushiva: what blog name shall we have ?
su_sivabalan: the topic and to know more on it
arushiva: ya da i understood that ...
su_sivabalan: if you put as a blog.. it will be something..like cut and paste.. for the sake of putting.. you will put.. and for the sake of reading.. i will read..
arushiva: after we prepare a document of our own on reading the details from any site ... we will upload the document to this bolg
su_sivabalan: again .. we are not publishing anything da.. we are going to understand thing among us..
arushiva: we will prepare doc. , discuss , and then upload to blog... this is what i meant
su_sivabalan: if you are going to put it as blog .. maintenance of it will become another task .. the time we get to explore is very less.. so we cant do that
arushiva: thats what machi ... after understanding ourself and publishing to a common place where we can go back and check wont make any difficulty da
chennaigv: yeah shiv .. i agree with u .. b4 putting we will pass the content among ourselves / correct/ comment / discuss ... and then upload
chennaigv: http://www.blogger.com/
su_sivabalan: can we create a private group blog here
chennaigv: is a wonderful site to create blogs ... this is mantained by google ..
chennaigv: yeah we can .. but again .. the pages finally generated are htmls .. so ppl can access it .. provided they know the url ..
su_sivabalan: dunno .. how far this is going to materialize
arushiva: dont worry bala we will materialize this perfectly
chennaigv: lets start it first .. and be serious abt it .. it will workout ..
su_sivabalan: okies
su_sivabalan: but does it have any size restrictions
chennaigv: bala .. if we are going to put that much content .. i am sure we can register a website .. and start putting our stuff there ... lets first start and face ne problem if it comes ..
arushiva: how will we post our messages
chennaigv: bala what happened .. worried whether it wud work ??
chennaigv: u have interface for it shiv ..
su_sivabalan: hmm..
chennaigv: why dont u guys go ahead and create one ..
arushiva: dei we will have one common thing which we can share ...
chennaigv: yeah .. but why dont you have of creating one blog and put some stuff in it ??
chennaigv: hey u can add team members to it tooo ..
arushiva: oh is it
arushiva: dei if we start creating too many blogs then we cant concentrate da
arushiva: as balan told we will go out of scope
arushiva: better to have one common blog i created on in rediff and drop since u created here
arushiva: i created as techies.rediffblogs.com
chennaigv: dei .. we will have only one blog .. where we will put our contents and add members ...
chennaigv: or we can pass the passwords to every one ..
arushiva: oh ok
su_sivabalan: http://itknowledge.blogspot.com/

Thats it .. now you know how it started ??? :))