- Community Home
 - >
 - Servers and Operating Systems
 - >
 - Operating Systems
 - >
 - Operating System - HP-UX
 - >
 - Re: Print last filename
 
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
 - Entry Storage Systems
 - Legacy
 - Midrange and Enterprise Storage
 - Storage Networking
 - HPE Nimble Storage
 
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
 - Appliance Servers
 - Alpha Servers
 - BackOffice Products
 - Internet Products
 - HPE 9000 and HPE e3000 Servers
 - Networking
 - Netservers
 - Secure OS Software for Linux
 - Server Management (Insight Manager 7)
 - Windows Server 2003
 - Operating System - Tru64 Unix
 - ProLiant Deployment and Provisioning
 - Linux-Based Community / Regional
 - Microsoft System Center Integration
 
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
 - Mark Topic as New
 - Mark Topic as Read
 - Float this Topic for Current User
 - Bookmark
 - Subscribe
 - Printer Friendly Page
 
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
07-08-2009 03:45 AM
07-08-2009 03:45 AM
			
				
					
						
							Print last filename
						
					
					
				
			
		
	
			
	
	
	
	
	
I need to print last file name when executing "ls -ltr" command from a fixed path.
Example:
$ls -ltr
-rw-rw-rw- 1 RT R1 6922674 Jul 8 14:08 abc123
-rw-rw-rw- 1 RT R1 6922674 Jul 8 14:10 abc124
-rw-rw-rw- 1 RT R1 6922674 Jul 8 14:15 abc125
-rw-rw-rw- 1 RT R1 6922674 Jul 8 14:20 abc126
-rw-rw-rw- 1 RT R1 6922674 Jul 8 14:25 abc126
-rw-rw-rw- 1 RT R1 6922674 Jul 8 14:30 abc127
-rw-rw-rw- 1 RT R1 6922674 Jul 8 14:40 abc128
-rw-rw-rw- 1 RT R1 6922674 Jul 8 14:50 abc129
-rw-rw-rw- 1 RT R1 6922674 Jul 8 15:08 abc130
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
07-08-2009 03:49 AM
07-08-2009 03:49 AM
			
				
					
						
							Re: Print last filename
						
					
					
				
			
		
	
			
	
	
	
	
	
#ls -ltr | tail -1
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
07-08-2009 03:54 AM
07-08-2009 03:54 AM
			
				
					
						
							Re: Print last filename
						
					
					
				
			
		
	
			
	
	
	
	
	
It's not clear exactly what you mean, so:
# ls -ltr | awk 'END{print $NR}'
abc130
# ls -ltr | tail -1
-rw-rw-rw- 1 RT R1 6922674 Jul 8 15:08 abc130
# ls -ltr | awk '{print $NF}'
abc123
abc124
abc125
abc126
abc126
abc127
abc128
abc129
abc130
Regards!
...JRF...
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
07-08-2009 04:31 AM
07-08-2009 04:31 AM
			
				
					
						
							Re: Print last filename
						
					
					
				
			
		
	
			
	
	
	
	
	
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
07-08-2009 04:39 AM
07-08-2009 04:39 AM
			
				
					
						
							Re: Print last filename
						
					
					
				
			
		
	
			
	
	
	
	
	
> i just need to print "abc130".
# ls -ltr | awk 'END{print $NR}'
abc130
...as I said...
Regards!
...JRF...
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
07-08-2009 04:58 AM
07-08-2009 04:58 AM
			
				
					
						
							Re: Print last filename
						
					
					
				
			
		
	
			
	
	
	
	
	
Or leave out the long listing and print first:
$ ls -t | head -1
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
07-08-2009 05:17 AM
07-08-2009 05:17 AM
			
				
					
						
							Re: Print last filename
						
					
					
				
			
		
	
			
	
	
	
	
	
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
07-08-2009 05:23 AM
07-08-2009 05:23 AM
			
				
					
						
							Re: Print last filename
						
					
					
				
			
		
	
			
	
	
	
	
	
If you are satistied with the answers you have received, please read:
http://forums.itrc.hp.com/service/forums/helptips.do?#28
Assigning points is both a way of saying "thank you" and a way of showing future readers of your thread what helped you solve your problem.
Most of your threads have no points assigned. You can review those, too, by examining your own profile:
http://forums.itrc.hp.com/service/forums/publicProfile.do?userId=WW217887&forumId=1
Regards!
...JRF...
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
07-08-2009 08:08 PM
07-08-2009 08:08 PM
			
				
					
						
							Re: Print last filename
						
					
					
				
			
		
	
			
	
	
	
	
	
-NKG-