LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-31-2002, 02:58 AM   #1
PokerFace
LQ Newbie
 
Registered: Aug 2001
Posts: 8

Rep: Reputation: 0
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
 
Old 11-04-2002, 11:31 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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;
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Bash function mijohnst Programming 13 10-23-2005 12:40 PM
*NIX systems programming: error using stat function MDBlueIce Programming 7 06-27-2005 06:42 AM
Bash function pazvant Linux - Software 1 03-08-2005 07:47 AM
Linux stat to Windows Stat sridurai Programming 3 09-24-2004 04:07 PM
Write own stat() function... indian Programming 1 09-14-2004 07:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration