Connecting Tech Pros Worldwide Help | Site Map

ls - ltr with Heading

AdusumalliGopikumar's Avatar
Member
 
Join Date: Aug 2007
Location: india
Posts: 43
#1: Sep 29 '08
Can any one tell me how to get the column heading when we type 'ls -ltr ' to list the files in a particular directory..



Thanks in advance
ashitpro's Avatar
Expert
 
Join Date: Aug 2007
Posts: 389
#2: Sep 29 '08

re: ls - ltr with Heading


As far as I know...it is impossible to print the column headers with ls itself..
May be some other soul can help you out in this forum
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,565
#3: Sep 29 '08

re: ls - ltr with Heading


If you are looking for some kind of header that tells you what each section of the ls -lrt output is, then you are just going to have to keep a print out of it next to you. Its not hard to know what is what. You shouldn't need it if you know what is being output to the screen.

Regards,

Jeff
Nepomuk's Avatar
Moderator
 
Join Date: Aug 2007
Location: Germany
Posts: 2,466
#4: Oct 7 '08

re: ls - ltr with Heading


I might be misinterpreting your question, but if you just want to print the first line of the output, use this:
Expand|Select|Wrap|Line Numbers
  1. ls -ltr | head -n 1
Greetings,
Nepomuk
AdusumalliGopikumar's Avatar
Member
 
Join Date: Aug 2007
Location: india
Posts: 43
#5: Oct 7 '08

re: ls - ltr with Heading


Quote:

Originally Posted by Nepomuk

I might be misinterpreting your question, but if you just want to print the first line of the output, use this:

Expand|Select|Wrap|Line Numbers
  1. ls -ltr | head -n 1
Greetings,
Nepomuk


No it is giving me a total.
Nepomuk's Avatar
Moderator
 
Join Date: Aug 2007
Location: Germany
Posts: 2,466
#6: Oct 7 '08

re: ls - ltr with Heading


Quote:

Originally Posted by AdusumalliGopikumar

No it is giving me a total.

Well, that would be the first line of the output. ^^

Greetings,
Nepomuk
AdusumalliGopikumar's Avatar
Member
 
Join Date: Aug 2007
Location: india
Posts: 43
#7: Oct 8 '08

re: ls - ltr with Heading


Quote:

Originally Posted by Nepomuk

Well, that would be the first line of the output. ^^

Greetings,
Nepomuk


That is ok Nepomuk, ls -ltr | head -n 10 will 10 lines ...

but my concern is headings of the columns for 'ls -ltr' ..
like
permissions filename size .. etc
Nepomuk's Avatar
Moderator
 
Join Date: Aug 2007
Location: Germany
Posts: 2,466
#8: Oct 9 '08

re: ls - ltr with Heading


Quote:

Originally Posted by AdusumalliGopikumar

That is ok Nepomuk, ls -ltr | head -n 10 will 10 lines ...

I know, I do understand what head does, I just didn't quite understand, what it was you wanted.
Quote:

Originally Posted by AdusumalliGopikumar

but my concern is headings of the columns for 'ls -ltr' ..
like
permissions filename size .. etc

Ah, now I understand. Well, I checked the man page and couldn't find anything. There might be something in the coreutils info page (info coreutils -> * Directory listing:: -> * ls invocation::), but I couldn't find anything to solve your problem in there either so far. I guess, you're probably out of luck.

Of course, you could always try to write something like that yourself. (Maybe Perl or Python would be a good choice for this? But I know neither...)

Greetings,
Nepomuk
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,565
#9: Oct 9 '08

re: ls - ltr with Heading


That I know of, ls does not output the columns at all. 99.9% of the people using unix just know what each column is, so there is no need. If you need to know, then reference the ls man page. Otherwise, you can write a perl script to output headers and then the ls output.

Regards,

Jeff
Reply