Untitled Document
basename Command

Example 1 -

When basename is used with pathname as an argument it will remove the prefix up to the last ( '/' ) character and esult result -

   basename /mangu.the.geek/bs-final/js    
   output - js 

Example 2 -

When basename is used with two arguments , it strips off the second argument from the first argument

   basenmae list.txt txt ---------------------------- txt will be stripped off  
   output - list

Example 3 -

Is there any convenient way by which we can convert all the .ksh files present in an directory to .txt ? The answer is yes , combination of for loop , basename and mv command will does this task easily . Write below code in new file and save it as bas.ksh and run the script

   for file in *.ksh ; do   
     org_name=`basename $file ksh`  
       mv $file ${org_name} txt
         done 
 
The basename change that we see are temporary except for the example 3.
Untitled Document