The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 01-02-2009
Hangman2 Hangman2 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 27
Getting file name ?

Assuming /dir1/dir2 has two file

file1
file2

If I get the file name which includes the dir name using command

file_name=`ls -ltr /dir1/dir2/* | grep '^-' | tail -1 | awk '{print $9}' `

then I get file_name which includes the /dir1/dir2 also.

if I want to get just the filename which should be file1 or file2 then how can I do that?