How to get the file length in C on Linux Posted on Mar 24, 2018 by Eric Ma In QA How to get the file length in C on Linux given the address of the file (e.g. “/tmp/a.txt”)? This function returns the length of the file: #include <sys/stat.h> long file_length(char *f) { struct stat st; stat(f, &st); return st.st_size; } Read more: How to get a FILE pointer from a file descriptor and how to get a file descriptor from a FILE pointer in C on Linux? Maximum allowed file path length for C programming on Linux? How to redirect anything written on a file to another file in linux? How to test whether a file exists and is a block special file in Python on Linux? How to convert a ps file to a pdf file How to sort lines by length in Linux? How to get a 10-byte length random string in bash The length of timeslices for processes under CFS process scheduling algorithm in Linux Kernel