check size of file linux code example
Example 1: list file size as mb
ls -l --block-size=M
Example 2: linux file size
cd dir ; du -hsx * | sort -rh | head -20
Example 3: linux command for file size
du -bsh *
Example 4: ls human readable size
du -sh directory_name
du -bsh *
Example 5: find the size of file in linux
ls -l filename
ls -l *
ls -al *
ls -al dir/
Example 6: 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;