Sponsored Content
Full Discussion: list command
Top Forums UNIX for Dummies Questions & Answers list command Post 50829 by jim mcnamara on Monday 3rd of May 2004 05:00:06 PM
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);
}

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
eX_setup.h(3)							    libeXosip2							     eX_setup.h(3)

NAME
eX_setup.h - eXosip setup API SYNOPSIS
#include <eXosip2/eXosip.h> #include <osipparser2/osip_message.h> #include <time.h> Functions int eXosip_init (void) void eXosip_quit (void) int eXosip_execute (void) int eXosip_set_option (int opt, const void *value) int eXosip_lock (void) int eXosip_unlock (void) struct osip_naptr * eXosip_dnsutils_naptr (const char *domain, const char *protocol, const char *transport, int keep_in_cache) int eXosip_dnsutils_dns_process (struct osip_naptr *output_record, int force) int eXosip_dnsutils_rotate_srv (struct osip_srv_record *output_record) int eXosip_listen_addr (int transport, const char *addr, int port, int family, int secure) int eXosip_set_socket (int transport, int socket, int port) void eXosip_set_user_agent (const char *user_agent) const char * eXosip_get_version (void) int eXosip_set_cbsip_message (CbSipCallback cbsipCallback) void eXosip_enable_ipv6 (int ipv6_enable) void eXosip_masquerade_contact (const char *public_address, int port) int eXosip_find_free_port (int free_port, int transport) int eXosip_transport_set (osip_message_t *msg, const char *transport) int eXosip_guess_localip (int family, char *address, int size) Detailed Description eXosip setup API This file provide the API needed to setup and configure the SIP endpoint. Author Generated automatically by Doxygen for libeXosip2 from the source code. Version 3.1.0 Sun Jun 24 2012 eX_setup.h(3)
All times are GMT -4. The time now is 06:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy