help with ls commad


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers help with ls commad
# 1  
Old 02-04-2008
help with ls commad

hi
I want to display the latest file in script.
say for example

file.txt1
file.txt2
file.txt3(latest)

in the script

var1=`ls -ltr file.txt* | tail-1`
echo $var1


This is what i am using. But this says that file.txt*: No such file or directory


To the same script if I pass file.txt* as parameter and
when i use the below it is working

var1=`ls -ltr $1 | tail-1`
echo $var1


Can some help me with first method

Thanks in advance
Ammu
# 2  
Old 02-04-2008
Not sure I uderstood your question:
var1=`ls -ltr $1 | tail-1`
echo $var1

---
Perhaps you are trying to achieve the output of:
ls -ltr $1 | head -1
# 3  
Old 02-04-2008
I will make it clear

file.txt1
file.txt2
file.txt3(latest)

I want to display the latest file file.txt3 (file.txt* series).
I need the something like below

var1=`ls -ltr..............`
echo $var1

Thanks in advance
Ammu
# 4  
Old 02-04-2008
var1=`ls -tr1 file.txt* | tail -1`
echo $var1

does it help?
# 5  
Old 02-04-2008
I still dont see where is the problem...
Here on aix 5.3:
vbe@ it34: /usr/tivoli/tsm/client/ba/bin> ll dsm.o*
-rw-r--r-- 1 root system 345 Jan 24 17:23 dsm.opt
-rw-r--r-- 1 root system 419 Jan 20 2005 dsm.opt.adsm2
-rw-r--r-- 1 root system 419 Jan 20 2005 dsm.opt.adsm3
-rw-r--r-- 1 root system 421 Jan 20 2005 dsm.opt.adsmsrv
-rw-r--r-- 1 root system 782 Nov 27 2006 dsm.opt.smp
vbe@ it34: /usr/tivoli/tsm/client/ba/bin> VAR1=`ll -ltr dsm.o*|tail -1`
vbe@ it34: /usr/tivoli/tsm/client/ba/bin> echo $VAR1
-rw-r--r-- 1 root system 345 Jan 24 17:23 dsm.opt
vbe@ it34: /usr/tivoli/tsm/client/ba/bin>
# 6  
Old 02-04-2008
I guess that globbing is disabled in your script,do you find anything of this sort
set -f or set noglob in your script?

Thanks
Nagarajan G
 
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Programming

UNIX commad in COBOL

Hi guys, i used the call "sytem" using ... in a cobol program. At the moment i stoped at an empasse, how cam I retrive the execution's result of unix command? Explenation, I made an 'pwd' command, and I must to have the directory inside the program. How can have this result? (2 Replies)
Discussion started by: Prosy60
2 Replies

2. UNIX for Dummies Questions & Answers

Need help in excluding a particular directory using Find commad

Hi, I have a directory structure as below /home/gad/Merl/a/a1.txt /home/gad/Merl/b/a1.txt /home/gad/Merl/c/a1.txt How can I find the file a1.txt but not from directory 'a' and it(the filw) should loaded 6 days ago.. Can any one pls help,quick reply much appriciated.. Thanks. (1 Reply)
Discussion started by: jagadish_gaddam
1 Replies

3. UNIX for Advanced & Expert Users

Script commad implementation - urgent help

I modified the .profile of a user id to start "script" when the user logs in. When the user logs out, I have added a trap command in the .profile file to capture the exit signal. And in that trap command, I have added the creation of a file called .logout. And in the .logout file, I have added... (3 Replies)
Discussion started by: ggayathri
3 Replies

4. Filesystems, Disks and Memory

Commad to Delete Nested Directory

Can someone please tell me the command to delete a NESTED DIRECTORY. here is my email address: firewalls007@hotmail.com (2 Replies)
Discussion started by: Javed Akram
2 Replies
Login or Register to Ask a Question