LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   stat function in BASH... (https://www.linuxquestions.org/questions/programming-9/stat-function-in-bash-34232/)

PokerFace 10-31-2002 02:58 AM

stat function in BASH...
 
Hello,

I have a bit of a problem with this command in bash:
DATE=$(date -d "+$(stat $file | grep Modify | cut -c 9-)" +%Y%m%d)

this should normally give me the last modification date of the "$file", and it works when I use it normally, but when the $file is in a "linked" ( ln -s ) directory, he says that he cannot stat the file... (gives an error on stat).

Is there a workaround for this? so that I can stat the files in the "linked" directory?

Many thanks in advance,

PF

Hko 11-04-2002 11:31 AM

Install the "realpath" utility and call it on your file in your script.
IIRC it's more or less Debian-specific. So if you use Debian:

apt-get install realpath

If not, get the sources from the debian site or compile your own quick & dirty one from this source:

Code:

#include <limits.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
      char rpath[PATH_MAX];
      if (argc != 2) {
          printf("\n%s <path>\n", argv[0]);
          exit(1);
      }
      if (realpath(argv[1], rpath) == NULL) {
          fprintf(stderr, "Error resolving path.\n\n");
          exit(2);
      }
      printf("%s\n", rpath);
      return 0;
}



All times are GMT -5. The time now is 09:09 AM.