Questions tagged [stat]

The stat(2) system call on POSIX systems. For statistics, use the statistics instead.

The stat(2) system call is used to retrieve information about a named file (or directory).

Links:

For statistics, use the tag instead.

829 questions
9
votes
2 answers

stat() error 'No such file or directory' when file name is returned by readdir()

I'm not able to identify the error thrown by stat. The below program reads all files in a directory and prints the file name: DIR *dp; struct dirent *dirp; struct stat sb; if((dp = opendir(argv[1]))==NULL) { perror("can't open…
John Eipe
  • 10,922
  • 24
  • 72
  • 114
9
votes
1 answer

Why do file permissions show different in Python and bash?

From Python: >>> import os >>> s = os.stat( '/etc/termcap') >>> print( oct(s.st_mode) ) **0o100444** When I check through Bash: $ stat -f "%p %N" /etc/termcap **120755** /etc/termcap Why does this return a different result?
FlowRaja
  • 677
  • 3
  • 6
  • 15
9
votes
1 answer

R : stat_smooth groups (x axis)

I have a Database, and want to show a figure using stat_smooth. I can show the avg_time vs Scored_Probabilities figure, which looks like this: c <- ggplot(dataset1, aes(x=Avg.time, y=Scored.Probabilities)) c + stat_smooth() But when changing…
Jeffery Chen
  • 323
  • 2
  • 4
  • 13
9
votes
3 answers

Get file attributes (hidden, readonly, system, archive) in Python

Just started learning Python. How can i get a status of file's attributes in Python? I know that os.chmod(fullname, stat.S_IWRITE) delete readonly attribute, but how can i get status without changing it? I need to get all of the attributes of…
Evgeny Gerbut
  • 390
  • 1
  • 4
  • 10
9
votes
4 answers

How can I get the high-res mtime for a symbolic link?

I want to reproduce the output of ls --full-time from a Perl script to avoid the overhead of calling ls several thousand times. I was hoping to use the stat function and grab all the information from there. However, the timestamp in the ls output…
kbro
  • 4,754
  • 7
  • 29
  • 40
9
votes
3 answers

php clearstatcache() performance and parameters explanation

i'm using filemtime for fingerprinting external resources in html, like: I noticed a significant delay between the effective updating and the timestamp returned by…
Giona
  • 20,734
  • 4
  • 56
  • 68
8
votes
4 answers

In Posix how is type dev_t getting used?

What I am after is the meaning of such type and what interface can use it. It is explained in Posix spec that dev_t is used for device IDs. However, what device id means for any object described by a path, which can be a file, a directy, a fifo or a…
Mengfei Murphy
  • 1,049
  • 3
  • 11
  • 16
8
votes
2 answers

Using stat() after fopen() to Avoid TOCTOU Problems?

Title says it all: can one use stat() after fopen() to avoid Time of Check to Time of Use (TOCTOU) race conditions? Some details: I am writing a C program that only reads files, but needs to error properly when asked to read a directory. As of right…
Gavin D. Howard
  • 371
  • 4
  • 9
8
votes
1 answer

How to get the center and scale after using the scale function in R

It seems a silly question, but I have searched on line, but still did not find any sufficient reply. My question is: suppose we have a matrix M, then we use the scale() function, how can we extract the center and scale of each column by writing a…
陈见聪
  • 101
  • 1
  • 4
8
votes
1 answer

Inconsistency in modified/created/accessed time on mac

I'm having trouble using os.utime to correctly set the modification time on the mac (Mac OS X 10.6.2, running Python 2.6.1 from /usr/bin/python). It's not consistent with the touch utility, and it's not consistent with the properties displayed in…
Seth Johnson
  • 14,762
  • 6
  • 59
  • 85
8
votes
2 answers

What are st_flags (user defined flags) for a file Mac OS X?

I am trying to detect when Dropbox is busy updating a file in a user's Dropbox in Mac OS X. By running stat(1) or stat(2) on a file, I see that the user defined flags for file (st_flags) are normally 0x40, but while Dropbox is updating the file…
Jerry Krinock
  • 4,860
  • 33
  • 39
8
votes
2 answers

Determining if two file paths point to same file under Linux / C?

Under Linux, I have two file paths A and B: const char* A = ...; const char* B = ...; I now want to determine, should I open(2) them both... int fda = open(A, ...); int fdb = open(B, ...); ...will I get two filehandles open to the same file in the…
Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319
8
votes
1 answer

Windows and ctime / st_ctime

Does Windows offer anything like POSIX stat's st_ctime field, which gives the timestamp of last metadata change? Background: I have some data files that I'd like to check if they've been modified since a particular timestamp. Checking the modified…
Josh Kelley
  • 56,064
  • 19
  • 146
  • 246
8
votes
3 answers

What is lstat() alternative in windows?

In linux, when stat() is used with broken link files, it fails with -1. So I used lstat() which succeeded. For the same case in windows, _stat() fails with broken shortcuts, but there is no _lstat() in windows. Please help to find the alternative…
Gautham Polisetty
  • 155
  • 1
  • 1
  • 5
8
votes
1 answer

Binutils stat illegal option -c

I use stat two times in my script once to find the file files permissions and once to find the size of the file. `stat -c %A "$directory/$file"` `stat -c %s "$directory/$file"` I am using OSX 10.7 and directory and file are variable of the…
Joe Tyman
  • 1,417
  • 5
  • 28
  • 57
1 2
3
55 56