Fill the directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fill the directory
# 1  
Old 03-18-2011
Fill the directory

HI all
When i do df -h,it displays the amount of free space.
Tell me a command or a script to fill the total space
to a certain percent (say 99%)

Thanks in advance
# 2  
Old 03-18-2011
Your question is not clear. Are you looking for disk usage command..?
Code:
du -h

# 3  
Old 03-18-2011
Just a little shot.
No doubt it can be done in more elegant way.

Warning, use this script carfully and with harmless command at first.
Check that the stop condition in the while loop works fine on your plateform before setting up something in the loop

This create a "dummy" file and make it growth until the FS reach the chosen "threshold" level

Code:
ksh
FStofill=/tmp
threshold=99
while [ "$(df -k ${FStofill} | awk '{x=$(NF-1);sub(/.$/,"",x)}END{print x}')" -lt "$threshold" ]
do
cat /usr/bin/tar >> ${FStofill}/dummy
done

This User Gave Thanks to ctsgnb For This Post:
# 4  
Old 03-19-2011
And is it possible in one liner code to fill the remaining space just by creating a huge file equal to free space..
# 5  
Old 03-19-2011
I didn't try it but maybe something like (feel free to test/adapt/fix) but use it carefully

Code:
#!/usr/bin/ksh
# choose a threshold level to which you want to fill your FS
threshold=80
FStoFill=/tmp

while :
do

set -- $(df -k $FStoFill | tail -1)
# Now:
# $1 = FS
# $2 = total size in 1k-block
# $3 = Used size in k block
# $4 = available size
# $5 = %used    ${5%?} will remove the char "%"
# $6 = mount point

# if current %used has reached of exceed threshold, then break
[[ ${5%?} -ge $threshold ]] && break

# setup the remaining number of 1k block to fill
nb=$((($threshold*$2/100)-$3))

# if the remaining number of 1k block to fill represent more than 4Gb,
# setup the remaining number of 1k block to fill a 4Gb file
[[ $nb -gt $((4*1024*1024)) ]] && nb=$((4*1024*1024))

# create a file of the remaining $nb number of 1k block to fill
dd if=/dev/zero of=$FStoFill/zerofile.$$ bs=1k count=$nb

done

This method should fill the space with 4Gb files until the remaining space to fill to the wanted threshold is lower , then fill the remaining space with a last file so the threshold is reached


If you want to fill all the remaining space to the wanted threshold in one shot you can try

Code:
threshold=80
FStoFill=/tmp
set -- $(df -k $FStoFill | tail -1)
dd if=/dev/zero of=$FStoFill/zerofile.$$ bs=1k count=$((($threshold*$2/100)-$3))

As previously mentionned i didn't test it so you can give a shot in test environment, but use it carefully.

---------- Post updated at 10:13 PM ---------- Previous update was at 10:05 PM ----------

note that if the remaining space is bigger than 2^32 you may have to ensure that you run a 64bit version of the dd command

---------- Post updated at 10:13 PM ---------- Previous update was at 10:13 PM ----------

(i meant the remaining space to fill up until you reach the chosen threshold)
This User Gave Thanks to ctsgnb For This Post:
# 6  
Old 03-20-2011
Thanks ,i will try this when my system is back up..

Can you please tell a way to create a file whose size is equal to remaining free size in a partition(df -h gives so and so megabytes free remaining for each partition)
# 7  
Old 03-21-2011
hey please explain the two lines
Code:
set -- $(df -k $FStoFill | tail -1)
dd if=/dev/zero of=$FStoFill/zerofile.$$ bs=1k count=$((($threshold*$2/100)-$3))


Last edited by Franklin52; 03-21-2011 at 11:25 AM.. Reason: Please use code tags, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fill in missing values

Hi, I have a data sample as shown below. I want to fill in the left column so that the line will be continuous. For example, between 1 and 5 should be 2,3,4. And corresponding values in the right column will be 0. Thus the expected data should look like that: 1 1 1 10 1 2 1 3 1 5 1 6 2 0... (6 Replies)
Discussion started by: theanh0508
6 Replies

2. Shell Programming and Scripting

Fill missing values with 2

Hi All, I have 100 .txt files which look like this: 3 4 5 6 7 Now, some files have some numbers missing in them and they look like this: 4 5 6 (6 Replies)
Discussion started by: shoaibjameel123
6 Replies

3. UNIX for Dummies Questions & Answers

combine and fill series

hi all! i have a script with an output like this abc 123 1246 abc 1386 abc 2589 abc 7383 what can i do if i want to fill the 2nd column with the 2nd string '123' abc 123 1246 abc 123 1386 abc 123 2589 abc 123 7383 thanks! (3 Replies)
Discussion started by: engr.jay
3 Replies

4. Shell Programming and Scripting

Zero fill a string

How do I zero fill a string. E.g pad a string to two digits m=`date "+%m"` pm=`expr $m - 1` echo $pm the above code echoes 1. I want it to echo 01. Any ideas? (3 Replies)
Discussion started by: timgolding
3 Replies

5. Programming

Zero Fill 10 position field

Hi everyone, I am using shell scripting on a Unix SCO box. It calls a C program named zerofill. I do not know anything about C. I am having an issue with a hash total that should only be zero filled 10 positions but the record has 11 positions. DEBUG RESULTS + nice -n -5 bc -l /tmp/fhash8395... (0 Replies)
Discussion started by: ski
0 Replies

6. UNIX for Dummies Questions & Answers

Fill in columns

Hi, I've got a file with several columns where some entries are missing. Example: a b c d f g h j k l p y r I need to replace the empty spaces with zero, so the new file would be: a b c d f 0 g h j k 0 l p y 0 r The original file is tab delimited. Many thansk for... (3 Replies)
Discussion started by: zajtat
3 Replies

7. UNIX for Dummies Questions & Answers

Read directory and fill a file with this information

Hello All, Got a question to make a script what reads a directory and put the file names from that directory in a file with some extra text. ls /tempdir output is: file1.gfh file2.txt file4.zzz these file names (always with an extention) must be placed in a line and written to... (2 Replies)
Discussion started by: ToXiQ
2 Replies

8. Shell Programming and Scripting

fill in missing columns

It can't be that hard, but I just can't figure it out: I have file like: File Sub-brick M_1 S_1 M_2 S_2 M_4 S_4 ... xxx 1 214 731 228 621 132 578 ... and would like to get 0 0 where M_3 S_3 is missing xxx 1 214 731 228 621 0 0 132 578 ... I wrote following script, but can't figure out... (3 Replies)
Discussion started by: avvk
3 Replies

9. Shell Programming and Scripting

Fill the Key fields : Please help us

Hi .... we are having the below file .Column 1, Column 2 ,column 3 are key fields... In the below ...for 2 nd , 3 rd row the repeated key column is missing .... i want the new file to be populated with all missing key columns. ... (11 Replies)
Discussion started by: charandevu
11 Replies

10. Shell Programming and Scripting

Fixed length (Fill out)

hello, I have a file that has lines with different lengts. I want this file to be filled up with a zero so that al the lines have the same length. Please advice? File 1: ----------- 2310 2009 830 1345 Result File 2: ---------- 2310 2009 0830 (3 Replies)
Discussion started by: peterk
3 Replies
Login or Register to Ask a Question