Sponsored Content
Operating Systems Linux how to get the correct reading of diskspace Post 302234640 by Annihilannic on Wednesday 10th of September 2008 03:21:45 AM
Old 09-10-2008
Quote:
Originally Posted by jonathan184
So while the process is still running i cleared the log using cat /dev/null > script1.sh then ran rm -rf script1.sh
I presume you meant script1.log, not script1.sh.

Sometimes the cat /dev/null > script1.log (or just >script1.log on its own) is enough. When the next output is written to the file you can end up with a sparse file, where the file size is reported as quite large, but the file only occupies a small space on disk.

The big problem was that you removed the log file with rm, which meant that you could no longer truncate the log.

Here is an example where I create a "log" file, and part way through writing to it, I "flatten" the file. You can see that the file size continues to increase, but the disk usage reported by du drops:

Code:
# while sleep 1 ; do dd if=/dev/zero bs=1048576 count=1 2>/dev/null ; done > /tmp/logfile &
[1]     20489
# ls -l /tmp/logfile
-rw-r--r--   1 root       sys        2097152 Sep 10 07:15 /tmp/logfile
# ls -l /tmp/logfile ; du -ks /tmp/logfile
-rw-r--r--   1 root       sys        8388608 Sep 10 07:15 /tmp/logfile
11264   /tmp/logfile
# ls -l /tmp/logfile ; du -ks /tmp/logfile
-rw-r--r--   1 root       sys        9437184 Sep 10 07:15 /tmp/logfile
11264   /tmp/logfile
# ls -l /tmp/logfile ; du -ks /tmp/logfile
-rw-r--r--   1 root       sys        15728640 Sep 10 07:15 /tmp/logfile
27648   /tmp/logfile
# ls -l /tmp/logfile ; du -k /tmp/logfile
-rw-r--r--   1 root       sys        23068672 Sep 10 07:15 /tmp/logfile
27648   /tmp/logfile
# > /tmp/logfile
# ls -l /tmp/logfile ; du -k /tmp/logfile
-rw-r--r--   1 root       sys        33554432 Sep 10 07:15 /tmp/logfile
3072    /tmp/logfile
# ls -l /tmp/logfile ; du -k /tmp/logfile
-rw-r--r--   1 root       sys        35651584 Sep 10 07:15 /tmp/logfile
11264   /tmp/logfile
# ls -l /tmp/logfile ; du -k /tmp/logfile
-rw-r--r--   1 root       sys        36700160 Sep 10 07:15 /tmp/logfile
11264   /tmp/logfile
# kill %1
#
[1] + Terminated               while sleep 1 ; do dd if=/dev/zero bs=1048576 count=1 2>/dev/null ; done > /tmp/logfile &
#

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

diskspace usage info

Anybody can help me? I need to know a specified folder diskspace usage, that's how much bytes that folder and its files/folders below spend on my storage. Thanks (2 Replies)
Discussion started by: nusajunus
2 Replies

2. UNIX for Dummies Questions & Answers

Linux diskspace usage

when /var directory of my machine gets filled up (85%) i removed some old logs. but after cleaning df -k command still shows that /var is still 85% full. It can detect the actual disk space only after I restart the machine. Is there a way to force df to reflect actual free space without... (1 Reply)
Discussion started by: necro
1 Replies

3. UNIX for Dummies Questions & Answers

Diskspace

Hi there, pls help me, i have a problem, how i can find out the disk amount of each harddisk per command (not the on label on the Harddisk) i need it on HP UX and Sun. can anybody helb me???? pls thanks Scotty (1 Reply)
Discussion started by: scotty
1 Replies

4. AIX

Help ... Java not reading correct AIX system time.

I have Java 1.4.2 (IBM AIX build ca142-20050929a SR3) installed on AIX 5.3. My system time is set correctly and both date and smitty confirm the correct date, time, and timezone: #date Thu Sep 21 15:12:42 EDT 2006 However, when I check the sytem time in Java... (2 Replies)
Discussion started by: dave521
2 Replies

5. Shell Programming and Scripting

to compute diskspace

Guys, have any idea for the script like this? also to compute w/ decimal. thanks a=10 b=20 c=30 d=40 if a < b then ( a -b)*1024 = free space b + (c -d) = total space if a > b then (b / d)*1024 = cpu (3 Replies)
Discussion started by: kenshinhimura
3 Replies

6. Shell Programming and Scripting

ASM Diskspace

Hi I want to check Oracle ASM disk status through a PERL script. Script flow would be like this ... 1. Its taking diskgroup name in the command line... 2. Connect to Oracle database 3. If connection error send a critical message. Plz replyyyyyyy...... (1 Reply)
Discussion started by: Harikrishna
1 Replies

7. Solaris

graphical diskspace analyzer

Hi all, recently I took over the admin task for a solaris 5.10 machine. Being a little bit familiar with debian systems Solaris is up to now a complete mystery to me. The first thing I would like to have is a graphical diskspace analyzer. I mean something like BaoBab under gnome. I there a... (2 Replies)
Discussion started by: sly_dunbar
2 Replies

8. Shell Programming and Scripting

[ask]elimination with diskspace

dear all, i want elimination file with disk space for example: $ df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 62G 19G 41G 31% / /dev/sda1 99M 13M 82M 13% /boot tmpfs 1014M 0... (2 Replies)
Discussion started by: zvtral
2 Replies

9. Shell Programming and Scripting

DiskSpace Error

Hi, While am preparing the script for diskspace for different partitions different threshhold limit. am getting below error: ./test.sh: syntax error at line 5: `space=$' unexpected Script ==== #!/bin/sh df -h |grep -v '/oradata2'|grep -v '/orabkp' |grep -v '/oradata5' | awk '{ print $5... (7 Replies)
Discussion started by: Pavan83
7 Replies

10. Red Hat

Check free diskspace

Hi all, I would like to know what was the free disk space available in my system for last two days back. I know how to check free disk space by command below. df -h But i want to know the same outcome for last two days back. Please help me. Reg, Mastan (5 Replies)
Discussion started by: mastansaheb
5 Replies
RENAME(1)							   User Commands							 RENAME(1)

NAME
rename - rename files SYNOPSIS
rename [options] expression replacement file... DESCRIPTION
rename will rename the specified files by replacing the first occurrence of expression in their name by replacement. OPTIONS
-v, --verbose Give visual feedback which files where renamed, if any. -V, --version Display version information and exit. -s, --symlink Peform rename on symlink target -h, --help Display help text and exit. EXAMPLES
Given the files foo1, ..., foo9, foo10, ..., foo278, the commands rename foo foo0 foo? rename foo foo0 foo?? will turn them into foo001, ..., foo009, foo010, ..., foo278. And rename .htm .html *.htm will fix the extension of your html files. WARNING
The renaming has no safeguards. If the user has permission to rewrite file names, the command will perform the action without any ques- tions. For example, the result can be quite drastic when the command is run as root in the /lib directory. Always make a backup before running the command, unless you truly know what you are doing. SEE ALSO
mmv(1), mv(1) AVAILABILITY
The rename command is part of the util-linux package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/. util-linux June 2011 RENAME(1)
All times are GMT -4. The time now is 05:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy