list command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers list command
# 1  
Old 05-03-2004
list command

Hi,
"ls -l" would not display the year for the files created in the current year. Is there an option in "ls" that would display the year for those files?

Thanks!
# 2  
Old 05-03-2004
what about check out the man page to find out?

what better way to learn about a command then to read its manual.
# 3  
Old 05-03-2004
ls generally displays the year for files older than six months.

The only relibel way to get a complete file time is with C or perl or python.

Code:
/* this displays files times to the second: ctime & mtime */
/* usage filetime <file name> [file name...[]] -  for HPUX */

/* jmc 4/25/1997 10:09AM */

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <sys/stat.h>   
#include <string.h>
#include <errno.h>


void statfile(char *, struct stat *);
void usage(void); 
void bail(void);  
void filetimes(char *, struct stat *);    

int main(int argc, char *argv[]){      
       struct stat st;
       int i=0;    
       char tmp[256]={'\0'};
       if(argc <2) usage();       
       for(i=1; i<argc;i++){       
               strcpy(tmp,argv[i]);
               statfile(tmp,&st);
               filetimes(tmp,&st);            
       }        
       
       return 0;
}                         
void filetimes(char *fname,struct stat *st){  /* display the file times */
       struct tm *tmptr;            
       struct stat lst;           
       char output[91]={'\0'};
       lst = *st;   
       printf("File times for %s\n",fname);
       tmptr=localtime(&lst.st_atime);
       strftime(output,80,"Last status change: %D %T",tmptr);
       printf("\t%s\n",output);
       tmptr=localtime(&lst.st_mtime);
       strftime(output,80,"Last modify time  : %D %T",tmptr);
       printf("\t%s\n",output);

       
}
void statfile(char *fname, struct stat *st){
       int result=0;   
       result=stat(fname,st);
       if(result == (-1)) bail();
}               
void usage(void){
    printf("usage:  filetime <filenames> \n");
    errno=0;
    bail();
}                

void bail(void){
    if (errno) perror("Fatal error");
    exit(EXIT_FAILURE);
}

# 4  
Old 05-03-2004
I believe you mean it would not display it for the past six months. Being that six months have not occured yet in the year 2004, your statement is true. However, It will also not display the year for a file created in December 2003.

I don't see an option within ls to change this. It may be a scripting task involving several of the ls options.
# 5  
Old 05-03-2004
If you're using GNU ls (part of the coreutils package - I'm using version 4.5.8), you can format the date in any way you want, just like the date +FORMAT command.

Code:
ls -l --time-style=+'%d-%m-%y  %H:%M'

This prints dates in the British format of dd-mm-yy, such as 01-12-03, followed by the time, e.g. 23:45

Try man date for the other formatting characters.

Cheers
ZB
http://www.zazzybob.com
# 6  
Old 05-04-2004
Zazz is right - GNU is good.

Doing simple things like displaying file times to the second can be a pain in some flavors of unix. GNU coreutils often has a simple solution. Anybody who's been around the older proprietary versions of unix has scripts/code to get around the shortcomings.
These always work, but are really clunky.

For example, in HPUX LC_TIME can be changed to get file dates/times to display differently. In 11.0 b, the LC_TIME changes don't work reliably. We probably need a patch, but I don't know which one. So we use filetime (C code). It always works.

Unix is about workarounds. There are usually many ways to do the same thing, you find one you can implement.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

convert list in a command

Hello, i would make a script that generate SWITCH commands to create zone in a SAN, i have this file: ## zone:z_CGBVMH1_FC0_to_EVA1_CTRL_A_1 p_CGBVMH1_FC0; p_EVA1_CTRL_A_1 ## zone:z_CGBVMH1_FC0_to_EVA1_CTRL_B_1 p_CGBVMH1_FC0; p_EVA1_CTRL_B_1 ## zone:z_CGBVMH1_FC2_to_EVA1_CTRL_A_1... (2 Replies)
Discussion started by: alen192
2 Replies

2. AIX

list command issue

Hi, We are using AIX operating system. Issue with the first two files which we need to get month and year but it is not coming. When I use the ls -lrt command, I am having the problem. ls -lrt command output -rw-r----- 1 abc_dev devdatagrp 1234 17 Dec 08:30 -rw-r----- ... (7 Replies)
Discussion started by: onesuri
7 Replies

3. UNIX for Dummies Questions & Answers

Complete command list/argument using ps

Hi, Using ps, I can't work out what is the right options to use to show full listing of the process or command, can someone please advise what options I should be using? Example output of a "trimmed" process is as below and I know this is not the complete command line that I've executed,... (8 Replies)
Discussion started by: newbie_01
8 Replies

4. UNIX for Dummies Questions & Answers

command to list a only sub-directories

provide me the command to list all the subdirectories from the /home (1 Reply)
Discussion started by: mail2sant
1 Replies

5. UNIX for Dummies Questions & Answers

list out a file using unix command

Hi, Iam a new member of this group I have got one issue I wanna to find out one file like *.pll in a remote server using unix command i tried giving ls but it wont work acc to my expectation since ls list out the file only in a particular directory eg in C DRIVE I SHUD BE ABLE TO... (2 Replies)
Discussion started by: dmerin
2 Replies

6. UNIX for Dummies Questions & Answers

what does the ls -ltr command list

Hi, THe following is the output when i run the command ls -ltr can anyone explain the meaning of the field in red -rw-r----- 3 orca orca 20924 Sep 08 19:21 BTL027SASI.gnt -rw-r----- 3 orca orca 20924 Sep 08 19:21 BTL027RITD.gnt -rw-r----- 3 orca orca ... (2 Replies)
Discussion started by: ranjita.c
2 Replies

7. UNIX for Dummies Questions & Answers

Command to list all files

Hi Is there a command(s) which can be used to get a list of all files, including all files in all subdirectories on a given volume? Thanks :) All My Best, Jeffrey (6 Replies)
Discussion started by: groundlevel
6 Replies

8. UNIX for Dummies Questions & Answers

Command to list used space in VG?

Hello. Must be simple enough, but i am trying to find the quickest command to list the used disk space within my VGs. For example, lets say my workvg has 3 logical volumes. I can df -g -I to find the used space of each LVs and adding them up. Is there a command to list the VGs with the used... (2 Replies)
Discussion started by: Stephan
2 Replies

9. UNIX for Dummies Questions & Answers

list last few lines command

Hi If my ls -l results in 1000 lines and i just want to see the last few lines in the list what arguments do i pass eg lets say i want to see only the last 5 lines of 'ls -l' result (2 Replies)
Discussion started by: zomboo
2 Replies

10. Programming

list directory without use ls command?

Hi i need C code to list direcoty without using ls command and it sould take the path of the directory from the user? "please help me it is so important" (3 Replies)
Discussion started by: ashamry
3 Replies
Login or Register to Ask a Question