how to know size of file in linux code example
Example 1: linux file size
cd dir ; du -hsx * | sort -rh | head -20
Example 2: find the size of file in linux
ls -l filename
ls -l *
ls -al *
ls -al dir/
Example 3: how to check the size of a file in linux c
If you have the file stream (FILE * f):
fseek(f, 0, SEEK_END); // seek to end of file
size = ftell(f); // get current file pointer
fseek(f, 0, SEEK_SET); // seek back to beginning of file
// proceed with allocating memory and reading the file
Or,
fd = fileno(f);
struct stat buf;
fstat(fd, &buf);
int size = buf.st_size;
Or, use stat, if you know the filename:
struct stat st;
stat(filename, &st);
size = st.st_size;