basename & dirname : NIX classes

Hi Friends..
Here I am going to describe some commands which can help us in day to day task.

The basename command will strip off the directory portion of a filename path and return only the filename itself. In the following example, basename is used to strip the directory path from the filename so it returns simply

linux@atul $ basename /home/atul/script/WORKING_FINE/

Removing extensions
The basename utility also allows the extension or suffix to be stripped from a file basename. The extension to be stripped is added after the file path. In the following example, .sh is added after the filename. The return from basename is the single word file:

linux@atul $ basename /home/atul/script/WORKING_FINE/ .sh

The dirname utility is the complement of basename. It returns the “path” component of a file pathname string, as shown in the following listing. In the second dirname example, dirname also removes the trailing slash before attempting to understand the string. The result is that the dirname portion of

linux@atul $ dirname /home/atul/script/WORKING_FINE/

dirname has no options for the command and simply returns the directory portion of a file path. It is not used as often as basename.

keep scripting…….


About victimizeit
This is Atul.. working for IBM as a DataStage Developer. I may not be an expert on any particular DataStgae technology, but I'm sure I do know a few things about DB2, AIX, Unix, Windows, and DataBase. In this blog, I'll give out some tips on these subjects. If you find them useful, great, I'll be happy. Thanks for stopping by !!

What is your opinion ?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: