Home Linux Commandline Tips How to Watch a Growing Size of a File in Linux

How to Watch a Growing Size of a File in Linux

Linux operating system distributions are masters at solving computing riddles. These operating system distributions do not entertain computing myths. Therefore, its open-source attribute makes all Linux OS activities transparent to its users.

This article guide will try to uncover the possibility of monitoring the growing size of a file in a Linux operating system environment.

Why Monitor Growing File Size in Linux?

There are a number of reasons why you might need to monitor growing files’ sizes in Linux. One of them is perfectly explained by the following scenario. Imagine being assigned a Linux-powered machine or your current Linux machine is running out of disk space.

This scenario requires Linux-based expertise in monitoring or watching growing file sizes to identify and solve the issue leading to low disk space. In order to monitor such a file, we have to find it first.

Finding Growing Files in Linux

We will use the touch command to create a file called newest_file.txt from the Linux command line.

$ touch newest_file.txt

Since this is the newest file we have created on our system, we can now comparatively reference it while using the Linux find command to display files modified after the creation of the above file (newest_file.txt).

Our reference point for searching growing files’ sizes should be the root (/) folder if we want to explore the whole computer.

$ find / -newer newest_file.txt -not -path "/proc/*" -exec ls -lh {} \;

The above command searches for newly modified files on the root (/) directory whose modification took place after the creation of the newest_file.txt file. The find command ignores its search on /proc/ since it majorly deals with system processes information.

Finally, ls -lh prints the path to the discovered files on the terminal.

Find Modified Files on Linux
Find Modified Files on Linux

We can modify the above command and specify that the find command looks for modified files with a particular size range. For instance, for files that are at least 50 MB in size, we will execute the following command.

You might also need to execute this command as a sudoer/root Linux user of the system you are using.

$ sudo find / -newer newest_file.txt -size +50M -not -path "/proc/*" -exec ls -lh {} \;
Find Files with 50MB Size
Find Files with 50MB Size

Watching Growing File Sizes in Linux

At this point of the article, we can make an assumption that you have identified the specific file whose size growth you wish to monitor. Alternatively, maybe you wish to monitor the size growth of a newly created file from scratch.

We have added some data to the file newest-file.txt as per the following screenshot.

Add Text to File in Linux
Add Text to File in Linux

Suppose other users with access are feeding this file with data and we want to watch the file size change after every 4 seconds? We will make use of the watch command.

The watch command will periodically execute while displaying the needed output (ls -lh newest_file.txt) after every 4 seconds. The -n command option specifies the watch duration the system user is comfortable using.

$ watch -n 4 "ls -lh newest_file.txt"
Monitor Linux File Size
Monitor Linux File Size

The current file size is 483 bytes, let us try to add some data to the file and save it to see if any changes occur.

Watch Linux File Size
Watch Linux File Size

As you can see, the file size has changed to 1.6 kilobytes.

We can now comfortably find and watch/monitor the growing size of any file on a Linux operating system.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.