Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

watch file size on linux

I want to watch the growing size of a single file, so i use this command:

texai@maelstrom ~$ ls -lh club_prod.sql | awk '{print $5}' 116M 

Now I want to watch that result each 5 seconds so:

texai@maelstrom ~$ watch -n 5 ls -lh club_prod.sql | awk '{print $5}' 

but this command doesn't return any result

like image 241
texai Avatar asked May 11 '12 16:05

texai


People also ask

How do I check the size of a file in UNIX?

don't worry we have a got a UNIX command to do that for you and command is "df" which displays the size of the file system in UNIX. You can run "df" UNIX command with the current directory or any specified directory.

How do I see file size in bash?

Another method we can use to grab the size of a file in a bash script is the wc command. The wc command returns the number of words, size, and the size of a file in bytes.

Does Linux Show file size in bytes?

ls -lh command shows all file size information as K for Kibibyte (KiB), M for Mebibyte (MiB) and so on.. Instead of bits they show information in bytes. ls -lh shows unit (size) information using single character instead of two characters. If no unit information is there, then that is bytes.

How do I see file size in Ubuntu?

Use ls The -l option tells ls to show various metadata about the file, including file size. Without this option, ls only shows filenames. The -h option tells ls to show human-friendly units such as M for megabytes, G for gigabytes, etc.

How to display the size of a file in Linux?

You can force ls command to display file size in MB with the --block-size flag. The problem with this approach is that all the files with size less than 1 MB will also be displayed with file size 1 MB. The ls command also has -s option to display size. You should combine with -h to show the file size in human readable form.

How to find files that are more than 2 GB in Linux?

Let’s find files that are more than 2 GB in file size. The -size option tells find to search for files of a certain size. The + is “greater than” and 2 GB is specified as 2G in the syntax. Example 4. We can also use find to search for files under a certain size.

How do I watch a file for changes in Linux?

This watches a given file (or files) for changes and runs the command whenever (the instant) it changes. So you could do it like: echo /etc/my.cnf | \ entr sh -c 'cat /etc/my.cnf | mail -E -s "file changed" [email protected]' (PS. Credit to Denis 's answer for the mail command)

What is the Watch Command in Linux?

The watch command is a built-in Linux utility used for running user-defined commands at regular intervals. It temporarily clears all the terminal content and displays the output of the attached command, along with the current system date and time.


2 Answers

You're piping the output of watch into awk. If you simplify your command line, what you have is:

 watch <some arguments> | awk '{print $5}' 

That's not what you want. Try:

watch -n 5 "ls -lh club_prod.sql | awk '{print \$5}'" 
like image 169
larsks Avatar answered Sep 22 '22 10:09

larsks


watch -n 5 "du -h club_prod.sql" 
like image 37
tamasgal Avatar answered Sep 22 '22 10:09

tamasgal