How do I add files to a folder until a certain size limit is reached?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I have a folder with 1.5 million files (mail files) of various sizes. I want to create a directory, for example a
, and move (mv
) some of these files (which all start with a numeric timestamp) into folder a
, until folder a
is of up to a specified size. How would I do this?
Avoiding any procedural for
or while
loops would be a plus (i.e. one line) but anything that works is great!
shell-script mv size
add a comment |Â
up vote
2
down vote
favorite
I have a folder with 1.5 million files (mail files) of various sizes. I want to create a directory, for example a
, and move (mv
) some of these files (which all start with a numeric timestamp) into folder a
, until folder a
is of up to a specified size. How would I do this?
Avoiding any procedural for
or while
loops would be a plus (i.e. one line) but anything that works is great!
shell-script mv size
post one of your exemplary filenames with a numeric timestamp
â RomanPerekhrest
Nov 4 '17 at 19:24
I doubt that a simple approach is possible. There is implicit cumulated size measuring with (a) the size of a volume / filesystem, (b) with quota, and (c) with ulimits. But none of those works withmv
i.e. existing files only with newly created (or changed) ones.
â Hauke Laging
Nov 4 '17 at 19:45
Don't reinvent the wheel, use datapacker
â Ipor Sircer
Nov 4 '17 at 19:45
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have a folder with 1.5 million files (mail files) of various sizes. I want to create a directory, for example a
, and move (mv
) some of these files (which all start with a numeric timestamp) into folder a
, until folder a
is of up to a specified size. How would I do this?
Avoiding any procedural for
or while
loops would be a plus (i.e. one line) but anything that works is great!
shell-script mv size
I have a folder with 1.5 million files (mail files) of various sizes. I want to create a directory, for example a
, and move (mv
) some of these files (which all start with a numeric timestamp) into folder a
, until folder a
is of up to a specified size. How would I do this?
Avoiding any procedural for
or while
loops would be a plus (i.e. one line) but anything that works is great!
shell-script mv size
edited Nov 4 '17 at 20:50
Time4Tea
866119
866119
asked Nov 4 '17 at 18:23
Oliver Williams
3841513
3841513
post one of your exemplary filenames with a numeric timestamp
â RomanPerekhrest
Nov 4 '17 at 19:24
I doubt that a simple approach is possible. There is implicit cumulated size measuring with (a) the size of a volume / filesystem, (b) with quota, and (c) with ulimits. But none of those works withmv
i.e. existing files only with newly created (or changed) ones.
â Hauke Laging
Nov 4 '17 at 19:45
Don't reinvent the wheel, use datapacker
â Ipor Sircer
Nov 4 '17 at 19:45
add a comment |Â
post one of your exemplary filenames with a numeric timestamp
â RomanPerekhrest
Nov 4 '17 at 19:24
I doubt that a simple approach is possible. There is implicit cumulated size measuring with (a) the size of a volume / filesystem, (b) with quota, and (c) with ulimits. But none of those works withmv
i.e. existing files only with newly created (or changed) ones.
â Hauke Laging
Nov 4 '17 at 19:45
Don't reinvent the wheel, use datapacker
â Ipor Sircer
Nov 4 '17 at 19:45
post one of your exemplary filenames with a numeric timestamp
â RomanPerekhrest
Nov 4 '17 at 19:24
post one of your exemplary filenames with a numeric timestamp
â RomanPerekhrest
Nov 4 '17 at 19:24
I doubt that a simple approach is possible. There is implicit cumulated size measuring with (a) the size of a volume / filesystem, (b) with quota, and (c) with ulimits. But none of those works with
mv
i.e. existing files only with newly created (or changed) ones.â Hauke Laging
Nov 4 '17 at 19:45
I doubt that a simple approach is possible. There is implicit cumulated size measuring with (a) the size of a volume / filesystem, (b) with quota, and (c) with ulimits. But none of those works with
mv
i.e. existing files only with newly created (or changed) ones.â Hauke Laging
Nov 4 '17 at 19:45
Don't reinvent the wheel, use datapacker
â Ipor Sircer
Nov 4 '17 at 19:45
Don't reinvent the wheel, use datapacker
â Ipor Sircer
Nov 4 '17 at 19:45
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
max_k=1000
sum=0
target_dir_path="/target/dir"
find . -mindepth 1 -maxdepth 1 -type f -printf '%k %p' |
while IFS= read -r -d $'' line; do
size="$line%% *"
path="$line#* "
sum=$((sum+size))
if [ "$sum" -le "$max_k" ]; then
printf "%s" "$path"
else
break
fi
done | xargs -0 echo mv -t "target_dir_path"
add a comment |Â
up vote
-1
down vote
You can create special LV (or partition) of desired size and mount it under your 'a' directory.
If you want to leave some spare space, combine it with quota.
There was similar question:
https://stackoverflow.com/questions/8148715/how-to-set-limit-on-directory-size-in-linux
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
max_k=1000
sum=0
target_dir_path="/target/dir"
find . -mindepth 1 -maxdepth 1 -type f -printf '%k %p' |
while IFS= read -r -d $'' line; do
size="$line%% *"
path="$line#* "
sum=$((sum+size))
if [ "$sum" -le "$max_k" ]; then
printf "%s" "$path"
else
break
fi
done | xargs -0 echo mv -t "target_dir_path"
add a comment |Â
up vote
1
down vote
max_k=1000
sum=0
target_dir_path="/target/dir"
find . -mindepth 1 -maxdepth 1 -type f -printf '%k %p' |
while IFS= read -r -d $'' line; do
size="$line%% *"
path="$line#* "
sum=$((sum+size))
if [ "$sum" -le "$max_k" ]; then
printf "%s" "$path"
else
break
fi
done | xargs -0 echo mv -t "target_dir_path"
add a comment |Â
up vote
1
down vote
up vote
1
down vote
max_k=1000
sum=0
target_dir_path="/target/dir"
find . -mindepth 1 -maxdepth 1 -type f -printf '%k %p' |
while IFS= read -r -d $'' line; do
size="$line%% *"
path="$line#* "
sum=$((sum+size))
if [ "$sum" -le "$max_k" ]; then
printf "%s" "$path"
else
break
fi
done | xargs -0 echo mv -t "target_dir_path"
max_k=1000
sum=0
target_dir_path="/target/dir"
find . -mindepth 1 -maxdepth 1 -type f -printf '%k %p' |
while IFS= read -r -d $'' line; do
size="$line%% *"
path="$line#* "
sum=$((sum+size))
if [ "$sum" -le "$max_k" ]; then
printf "%s" "$path"
else
break
fi
done | xargs -0 echo mv -t "target_dir_path"
answered Nov 4 '17 at 20:18
Hauke Laging
53.6k1282130
53.6k1282130
add a comment |Â
add a comment |Â
up vote
-1
down vote
You can create special LV (or partition) of desired size and mount it under your 'a' directory.
If you want to leave some spare space, combine it with quota.
There was similar question:
https://stackoverflow.com/questions/8148715/how-to-set-limit-on-directory-size-in-linux
add a comment |Â
up vote
-1
down vote
You can create special LV (or partition) of desired size and mount it under your 'a' directory.
If you want to leave some spare space, combine it with quota.
There was similar question:
https://stackoverflow.com/questions/8148715/how-to-set-limit-on-directory-size-in-linux
add a comment |Â
up vote
-1
down vote
up vote
-1
down vote
You can create special LV (or partition) of desired size and mount it under your 'a' directory.
If you want to leave some spare space, combine it with quota.
There was similar question:
https://stackoverflow.com/questions/8148715/how-to-set-limit-on-directory-size-in-linux
You can create special LV (or partition) of desired size and mount it under your 'a' directory.
If you want to leave some spare space, combine it with quota.
There was similar question:
https://stackoverflow.com/questions/8148715/how-to-set-limit-on-directory-size-in-linux
answered Nov 4 '17 at 19:44
Jaroslav Kucera
4,3754621
4,3754621
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f402538%2fhow-do-i-add-files-to-a-folder-until-a-certain-size-limit-is-reached%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
post one of your exemplary filenames with a numeric timestamp
â RomanPerekhrest
Nov 4 '17 at 19:24
I doubt that a simple approach is possible. There is implicit cumulated size measuring with (a) the size of a volume / filesystem, (b) with quota, and (c) with ulimits. But none of those works with
mv
i.e. existing files only with newly created (or changed) ones.â Hauke Laging
Nov 4 '17 at 19:45
Don't reinvent the wheel, use datapacker
â Ipor Sircer
Nov 4 '17 at 19:45