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
15
votes
4 answers

How to use the mv command in Python with subprocess

I have a lot of files in /home/somedir/subdir/ and I'm trying to move them all up to /home/somedir programmatically. right now I have this: subprocess.call(["mv", "/home/somedir/subdir/*", "somedir/"]) but it's giving me this error: mv: cannot stat…
CSStudent
  • 425
  • 1
  • 6
  • 14
14
votes
2 answers

How to retrieve the user name from the user ID

I am implementing the (ls) command on Unix while learning from a book. During the coding part of my implementation of the (ls) command with the (-l) flag, I see that I have to prompt the user and group names of the file. So far I have the user and…
CompilingCyborg
  • 4,760
  • 13
  • 44
  • 61
14
votes
2 answers

How to use S_ISREG() and S_ISDIR() POSIX Macros?

This is a C program I wrote to recursively navigate and output directories and regular files. It compiles and runs fine on my Linux machine. But on Solaris, the dit->d_type == 8 check and the other similar ones don't work because there is no d_type…
Zach Alberico
  • 268
  • 3
  • 6
  • 19
13
votes
1 answer

Get a nanosecond-precise atime, mtime, ctime fields for file (stat?)

Some filesystems (e.g. ext4 and JFS) offer nanosecond resolution of atime/mtime fields. How can I read ns-resolution fields? The stat syscall returns time_t which is a second-resolution.
osgx
  • 90,338
  • 53
  • 357
  • 513
13
votes
1 answer

On Linux, is access() faster than stat()?

I would have assumed that access() was just a wrapper around stat(), but I've been googling around and have found some anecdotes about replacing stat calls with 'cheaper' access calls. Assuming you are only interested in checking if a file exists,…
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
12
votes
3 answers

R round exponential number

I just trying to round in R number like: > round(1.327076e-09) I would like it to result in > 1.33e-09 but results in > 0 which function can use?
stefan
  • 171
  • 2
  • 6
12
votes
3 answers

Why are the fields in `struct stat` named st_something?

This is in reference to the structure for information about a file inode: dev_t st_dev; /* ID of device containing file */ ino_t st_ino; /* inode number */ mode_t st_mode; /* protection */ nlink_t st_nlink; /*…
joethecoder
  • 175
  • 5
11
votes
4 answers

History of users modifying a file in Linux

I am wondering if its possible to list who all modified the file with course of time. I am aware that stat or ls -lrt will give the last user who modified the file. But I want to find out if it is possible to find the N-1 user who modified the…
user2809888
10
votes
1 answer

c and LD_PRELOAD. open and open64 calls intercepted, but not stat64

I've done a little shared library that tries to intercept open, open64, stat and stat64 sys calls. When I export LD_PRELOAD and run oracle's sqlplus, I can see the traces of the open and open64 calls, but no traces of the stat and stat64 calls. The…
klayme
  • 145
  • 2
  • 5
10
votes
1 answer

Counting hard links to a file in Go

According to the man page for FileInfo, the following information is available when stat()ing a file in Go: type FileInfo interface { Name() string // base name of the file Size() int64 // length in bytes for regular…
Elle Fie
  • 681
  • 6
  • 21
10
votes
5 answers

What are the advantages of using fstat() vs stat()?

If I have an open file with a known file descriptor, what are the advantages of using fstat(), versus stat()? Why isn't there only one function? int fstat(int fildes, struct stat *buf) int stat(const char *path, struct stat *buf)
Rasteril
  • 605
  • 1
  • 5
  • 16
9
votes
3 answers

How does Mac OS X know what programs are using a mounted filesystem?

This may sound like a silly question but up until recently if you tried to unmount a volume that was in use the Finder reported that it was in use, but not by whom. This is simple Unix functionality, if a file is open on a mount point, do not allow…
awiebe
  • 3,758
  • 4
  • 22
  • 33
9
votes
3 answers

File stat() vs access() to check permissions on a directory

I have successfully used both stat() & access() separately to determine if a user has either read or read/write access to a directory. My question is: - Is there a preferred method ? I see a lot of examples using stat, but for my purpose, access…
Bamerza
  • 1,335
  • 1
  • 18
  • 34
9
votes
0 answers

In node.js how can I know whether fs.stat() will return usable crtime and/or birthtime fields for a given file/path/volume/fs?

I recently learned that different OSes and even different filesystems under the same OS support different subsets of the timestamps returned by lstat. The Stats object returned gives us four times, each in two different flavours. js Date…
hippietrail
  • 15,848
  • 18
  • 99
  • 158
9
votes
2 answers

stat function for perl6

Is there an alternate way in perl6 to get file attribute details like size, access_time, modified_time.. etc. without having to invoke native call? As per the doc it is "unlikely to be implemented as a built in as its POSIX specific". What…
User9102d82
  • 1,172
  • 9
  • 19
1
2
3
55 56