How to pad a file to a desired size?'seek' argument in command ddreasons for a dd image of an almost-empty...
Placement of positioning lights on A320 winglets
Was self-modifying code possible using BASIC?
Professor Roman loves to teach unorthodox Chemistry
Why did Robert pick unworthy men for the White Cloaks?
Why does there seem to be an extreme lack of public trashcans in Taiwan?
Suppose leased car is totalled: what are financial implications?
Swapping High voltage breakers; change 50amp to 40amp
Should I explain the reasons for gaslighting?
DateTime.addMonths skips a month (from feb to mar)
Why did the World Bank set the global poverty line at $1.90?
How do I type a hyphen in iOS 12?
What plausible reason could I give for my FTL drive only working in space
What is this Amiga 2000 mod?
Can I use 220 V outlets on a 15 ampere breaker and wire it up as 110 V?
In The Incredibles 2, why does Screenslaver's name use a pun on something that doesn't exist in the 1950s pastiche?
That's not my X, its Y is too Z
How can I list the different hex characters between two files?
My mom's return ticket is 3 days after I-94 expires
Are the guests in Westworld forbidden to tell the hosts that they are robots?
How to represent jealousy in a cute way?
Why do I seem to lose data using this bash pipe construction?
What do I need to do, tax-wise, for a sudden windfall?
Do SFDX commands count toward limits?
Quasar Redshifts
How to pad a file to a desired size?
'seek' argument in command ddreasons for a dd image of an almost-empty drive not be small after gzipHow to use DD to clone a partition off a disk image?Write the same file multiple times to one file using ddHow to create a new partitioning table on SD card from the command line ?Size difference between an iso file burnt to a cd and the file retrieved with ddHow can I zero the unused blocks on my filesystem in order to minimize the compressed disk image size?Accidentally ejected sd card physically while ddSSHD cloning - something special to keep in mind, compared to HDD?why does does windows run checkdisk after I clone into a vm disk it using dd?dd command writing to /dev/sdc changed size of disk
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I have a file that I want to pad until it reaches 16 MiB (16777216 bytes). Currently it is 16515072 bytes. The difference is 262144 bytes.
How do I pad it?
This doesn't seem to be working:
cp smallfile.img largerfile.img
dd if=/dev/zero of=largerfile.img bs=1 count=262144
dd
add a comment |
I have a file that I want to pad until it reaches 16 MiB (16777216 bytes). Currently it is 16515072 bytes. The difference is 262144 bytes.
How do I pad it?
This doesn't seem to be working:
cp smallfile.img largerfile.img
dd if=/dev/zero of=largerfile.img bs=1 count=262144
dd
1
@terabyte; do you want physical padding or logical padding? In other words; should the file only show a size of 16777216 (and may contain holes) or shall it also occupy that amount of storage on the disk? - BTW, choosing abs=1
indd
is in my experience very runtime expensive.
– Janis
Apr 16 '15 at 22:50
4
truncate -s 16M thefile
– frostschutz
Apr 17 '15 at 9:28
4
@frostschutz that'd be a good answer, were you to post it as an answer.
– derobert
Apr 17 '15 at 9:40
@derobert, What's with StackExchange site users posting legit, simple answers as comments?
– user1717828
Apr 20 '15 at 5:29
@user1717828 not sure, probably a good question for meta.
– derobert
Apr 20 '15 at 7:27
add a comment |
I have a file that I want to pad until it reaches 16 MiB (16777216 bytes). Currently it is 16515072 bytes. The difference is 262144 bytes.
How do I pad it?
This doesn't seem to be working:
cp smallfile.img largerfile.img
dd if=/dev/zero of=largerfile.img bs=1 count=262144
dd
I have a file that I want to pad until it reaches 16 MiB (16777216 bytes). Currently it is 16515072 bytes. The difference is 262144 bytes.
How do I pad it?
This doesn't seem to be working:
cp smallfile.img largerfile.img
dd if=/dev/zero of=largerfile.img bs=1 count=262144
dd
dd
edited Apr 17 '15 at 11:59
Peter Mortensen
93069
93069
asked Apr 16 '15 at 22:04
tarabytetarabyte
1,11951935
1,11951935
1
@terabyte; do you want physical padding or logical padding? In other words; should the file only show a size of 16777216 (and may contain holes) or shall it also occupy that amount of storage on the disk? - BTW, choosing abs=1
indd
is in my experience very runtime expensive.
– Janis
Apr 16 '15 at 22:50
4
truncate -s 16M thefile
– frostschutz
Apr 17 '15 at 9:28
4
@frostschutz that'd be a good answer, were you to post it as an answer.
– derobert
Apr 17 '15 at 9:40
@derobert, What's with StackExchange site users posting legit, simple answers as comments?
– user1717828
Apr 20 '15 at 5:29
@user1717828 not sure, probably a good question for meta.
– derobert
Apr 20 '15 at 7:27
add a comment |
1
@terabyte; do you want physical padding or logical padding? In other words; should the file only show a size of 16777216 (and may contain holes) or shall it also occupy that amount of storage on the disk? - BTW, choosing abs=1
indd
is in my experience very runtime expensive.
– Janis
Apr 16 '15 at 22:50
4
truncate -s 16M thefile
– frostschutz
Apr 17 '15 at 9:28
4
@frostschutz that'd be a good answer, were you to post it as an answer.
– derobert
Apr 17 '15 at 9:40
@derobert, What's with StackExchange site users posting legit, simple answers as comments?
– user1717828
Apr 20 '15 at 5:29
@user1717828 not sure, probably a good question for meta.
– derobert
Apr 20 '15 at 7:27
1
1
@terabyte; do you want physical padding or logical padding? In other words; should the file only show a size of 16777216 (and may contain holes) or shall it also occupy that amount of storage on the disk? - BTW, choosing a
bs=1
in dd
is in my experience very runtime expensive.– Janis
Apr 16 '15 at 22:50
@terabyte; do you want physical padding or logical padding? In other words; should the file only show a size of 16777216 (and may contain holes) or shall it also occupy that amount of storage on the disk? - BTW, choosing a
bs=1
in dd
is in my experience very runtime expensive.– Janis
Apr 16 '15 at 22:50
4
4
truncate -s 16M thefile
– frostschutz
Apr 17 '15 at 9:28
truncate -s 16M thefile
– frostschutz
Apr 17 '15 at 9:28
4
4
@frostschutz that'd be a good answer, were you to post it as an answer.
– derobert
Apr 17 '15 at 9:40
@frostschutz that'd be a good answer, were you to post it as an answer.
– derobert
Apr 17 '15 at 9:40
@derobert, What's with StackExchange site users posting legit, simple answers as comments?
– user1717828
Apr 20 '15 at 5:29
@derobert, What's with StackExchange site users posting legit, simple answers as comments?
– user1717828
Apr 20 '15 at 5:29
@user1717828 not sure, probably a good question for meta.
– derobert
Apr 20 '15 at 7:27
@user1717828 not sure, probably a good question for meta.
– derobert
Apr 20 '15 at 7:27
add a comment |
5 Answers
5
active
oldest
votes
Drop the of=largerfile.txt
and append stdout to the file:
dd if=/dev/zero bs=1 count=262144 >> largerfile.txt
1
seek
is a right option here.
– 0andriy
Oct 29 '16 at 17:44
add a comment |
Besides the answers to get a physical padding you may also leave most of the padding space in the file just empty ("holes"), by seek
ing to the new end-position of the file and writing a single character:
dd if=/dev/zero of=largerfile.txt bs=1 count=1 seek=16777215
(which has the advantage to be much more performant, specifically with bs=1
, and does not occupy large amounts of additional disk space).
That method seems to work even without adding any character, by using if=/dev/null
and the final desired file size:
dd if=/dev/null of=largerfile.txt bs=1 count=1 seek=16777216
A performant variant of a physical padding solution that uses larger block-sizes is:
padding=262144 bs=32768 nblocks=$((padding/bs)) rest=$((padding%bs))
{
dd if=/dev/zero bs=$bs count=$nblocks
dd if=/dev/zero bs=$rest count=1
} 2>/dev/null >>largerfile.txt
2
Correct. In this casetruncate -s +262144 largerfile.txt
would also be fast.
– don_crissti
Apr 16 '15 at 23:08
add a comment |
The best anwser here is Janis's (above) because it lets you forget about the current file size and pad directly to the desired size with no calculation.
It also takes advantage of sparse files, which appending /dev/zero doesn't.
The answer could be tidier though, because 'count' is allowed to be 0 and you still get the padding:
dd if=/dev/null of=largerfile.txt bs=1 count=0 seek=16777216
(Edit: this is correct for GNU dd, but the behaviour of count=0
is platform-specific, see comments)
You are mistaken:count=0
is unspecified, but typically is the same as when nocount
parameter was specified. More problems:dd
truncates the file to 16777216 bytes, but if you are in hope that this creates a hole at the end, you are mistaken since you would first need to write data after the hole and later truncate it to a size that contains no data.
– schily
Jul 4 '18 at 14:58
count=0 is nothing like specifying no count parameter. Are you saying thatdd if=/dev/zero of=somefile
is the same asdd if=/dev/zero of=somefile count=0
? Try it.
– PeteC
Jul 6 '18 at 10:32
Of course!count=0
is the same as if you did not specify a count parameter at all. This is true at least for all implementations that have been derived from the original sources. Try it, it seems that you did never work with the originaldd
command.
– schily
Jul 6 '18 at 10:39
I can't find any documentation that specifies 0 as a unique value forcount
meaning 'ignore this parameter'. Can you find any? Without such documentation,count=0
means 'write zero blocks' and any deviation from this is a bug... (original sources or no).
– PeteC
Jul 6 '18 at 11:14
1
This was the POSIX documentation from before May 2015 when the underspecified text was corrected.
– schily
Jul 6 '18 at 12:43
|
show 2 more comments
Do you have to use dd
? If you want a file to have a particular (logical) length, just write a zero to the position you want. The bytes between the previous end and the written byte will be displayed as having null bytes. Here's an example using perl.
$ echo Hello > file
$ ls -l file
-rw-r--r-- 1 user group 6 Apr 16 22:59 file
$ perl -le 'open(my $f,"+<","file"); seek($f, 16777216 - 2, 0); print $f ""'
$ ls -ln file
-rw-r--r-- 1 user group 16777216 Apr 16 22:59 file
Why the "- 2" in the line? The script will write a byte, so we subtract 1 to seek to the position before that byte. We take off the other because the seek position is zero-indexed.
add a comment |
yes!
it works for dd if=/dev/zero bs=1 count=262144 >> largerfile.txt
make this transaction empty with that size.
restart database
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f196715%2fhow-to-pad-a-file-to-a-desired-size%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Drop the of=largerfile.txt
and append stdout to the file:
dd if=/dev/zero bs=1 count=262144 >> largerfile.txt
1
seek
is a right option here.
– 0andriy
Oct 29 '16 at 17:44
add a comment |
Drop the of=largerfile.txt
and append stdout to the file:
dd if=/dev/zero bs=1 count=262144 >> largerfile.txt
1
seek
is a right option here.
– 0andriy
Oct 29 '16 at 17:44
add a comment |
Drop the of=largerfile.txt
and append stdout to the file:
dd if=/dev/zero bs=1 count=262144 >> largerfile.txt
Drop the of=largerfile.txt
and append stdout to the file:
dd if=/dev/zero bs=1 count=262144 >> largerfile.txt
answered Apr 16 '15 at 22:13
OuturnateOuturnate
984617
984617
1
seek
is a right option here.
– 0andriy
Oct 29 '16 at 17:44
add a comment |
1
seek
is a right option here.
– 0andriy
Oct 29 '16 at 17:44
1
1
seek
is a right option here.– 0andriy
Oct 29 '16 at 17:44
seek
is a right option here.– 0andriy
Oct 29 '16 at 17:44
add a comment |
Besides the answers to get a physical padding you may also leave most of the padding space in the file just empty ("holes"), by seek
ing to the new end-position of the file and writing a single character:
dd if=/dev/zero of=largerfile.txt bs=1 count=1 seek=16777215
(which has the advantage to be much more performant, specifically with bs=1
, and does not occupy large amounts of additional disk space).
That method seems to work even without adding any character, by using if=/dev/null
and the final desired file size:
dd if=/dev/null of=largerfile.txt bs=1 count=1 seek=16777216
A performant variant of a physical padding solution that uses larger block-sizes is:
padding=262144 bs=32768 nblocks=$((padding/bs)) rest=$((padding%bs))
{
dd if=/dev/zero bs=$bs count=$nblocks
dd if=/dev/zero bs=$rest count=1
} 2>/dev/null >>largerfile.txt
2
Correct. In this casetruncate -s +262144 largerfile.txt
would also be fast.
– don_crissti
Apr 16 '15 at 23:08
add a comment |
Besides the answers to get a physical padding you may also leave most of the padding space in the file just empty ("holes"), by seek
ing to the new end-position of the file and writing a single character:
dd if=/dev/zero of=largerfile.txt bs=1 count=1 seek=16777215
(which has the advantage to be much more performant, specifically with bs=1
, and does not occupy large amounts of additional disk space).
That method seems to work even without adding any character, by using if=/dev/null
and the final desired file size:
dd if=/dev/null of=largerfile.txt bs=1 count=1 seek=16777216
A performant variant of a physical padding solution that uses larger block-sizes is:
padding=262144 bs=32768 nblocks=$((padding/bs)) rest=$((padding%bs))
{
dd if=/dev/zero bs=$bs count=$nblocks
dd if=/dev/zero bs=$rest count=1
} 2>/dev/null >>largerfile.txt
2
Correct. In this casetruncate -s +262144 largerfile.txt
would also be fast.
– don_crissti
Apr 16 '15 at 23:08
add a comment |
Besides the answers to get a physical padding you may also leave most of the padding space in the file just empty ("holes"), by seek
ing to the new end-position of the file and writing a single character:
dd if=/dev/zero of=largerfile.txt bs=1 count=1 seek=16777215
(which has the advantage to be much more performant, specifically with bs=1
, and does not occupy large amounts of additional disk space).
That method seems to work even without adding any character, by using if=/dev/null
and the final desired file size:
dd if=/dev/null of=largerfile.txt bs=1 count=1 seek=16777216
A performant variant of a physical padding solution that uses larger block-sizes is:
padding=262144 bs=32768 nblocks=$((padding/bs)) rest=$((padding%bs))
{
dd if=/dev/zero bs=$bs count=$nblocks
dd if=/dev/zero bs=$rest count=1
} 2>/dev/null >>largerfile.txt
Besides the answers to get a physical padding you may also leave most of the padding space in the file just empty ("holes"), by seek
ing to the new end-position of the file and writing a single character:
dd if=/dev/zero of=largerfile.txt bs=1 count=1 seek=16777215
(which has the advantage to be much more performant, specifically with bs=1
, and does not occupy large amounts of additional disk space).
That method seems to work even without adding any character, by using if=/dev/null
and the final desired file size:
dd if=/dev/null of=largerfile.txt bs=1 count=1 seek=16777216
A performant variant of a physical padding solution that uses larger block-sizes is:
padding=262144 bs=32768 nblocks=$((padding/bs)) rest=$((padding%bs))
{
dd if=/dev/zero bs=$bs count=$nblocks
dd if=/dev/zero bs=$rest count=1
} 2>/dev/null >>largerfile.txt
edited Apr 16 '15 at 23:51
answered Apr 16 '15 at 22:59
JanisJanis
10.5k21738
10.5k21738
2
Correct. In this casetruncate -s +262144 largerfile.txt
would also be fast.
– don_crissti
Apr 16 '15 at 23:08
add a comment |
2
Correct. In this casetruncate -s +262144 largerfile.txt
would also be fast.
– don_crissti
Apr 16 '15 at 23:08
2
2
Correct. In this case
truncate -s +262144 largerfile.txt
would also be fast.– don_crissti
Apr 16 '15 at 23:08
Correct. In this case
truncate -s +262144 largerfile.txt
would also be fast.– don_crissti
Apr 16 '15 at 23:08
add a comment |
The best anwser here is Janis's (above) because it lets you forget about the current file size and pad directly to the desired size with no calculation.
It also takes advantage of sparse files, which appending /dev/zero doesn't.
The answer could be tidier though, because 'count' is allowed to be 0 and you still get the padding:
dd if=/dev/null of=largerfile.txt bs=1 count=0 seek=16777216
(Edit: this is correct for GNU dd, but the behaviour of count=0
is platform-specific, see comments)
You are mistaken:count=0
is unspecified, but typically is the same as when nocount
parameter was specified. More problems:dd
truncates the file to 16777216 bytes, but if you are in hope that this creates a hole at the end, you are mistaken since you would first need to write data after the hole and later truncate it to a size that contains no data.
– schily
Jul 4 '18 at 14:58
count=0 is nothing like specifying no count parameter. Are you saying thatdd if=/dev/zero of=somefile
is the same asdd if=/dev/zero of=somefile count=0
? Try it.
– PeteC
Jul 6 '18 at 10:32
Of course!count=0
is the same as if you did not specify a count parameter at all. This is true at least for all implementations that have been derived from the original sources. Try it, it seems that you did never work with the originaldd
command.
– schily
Jul 6 '18 at 10:39
I can't find any documentation that specifies 0 as a unique value forcount
meaning 'ignore this parameter'. Can you find any? Without such documentation,count=0
means 'write zero blocks' and any deviation from this is a bug... (original sources or no).
– PeteC
Jul 6 '18 at 11:14
1
This was the POSIX documentation from before May 2015 when the underspecified text was corrected.
– schily
Jul 6 '18 at 12:43
|
show 2 more comments
The best anwser here is Janis's (above) because it lets you forget about the current file size and pad directly to the desired size with no calculation.
It also takes advantage of sparse files, which appending /dev/zero doesn't.
The answer could be tidier though, because 'count' is allowed to be 0 and you still get the padding:
dd if=/dev/null of=largerfile.txt bs=1 count=0 seek=16777216
(Edit: this is correct for GNU dd, but the behaviour of count=0
is platform-specific, see comments)
You are mistaken:count=0
is unspecified, but typically is the same as when nocount
parameter was specified. More problems:dd
truncates the file to 16777216 bytes, but if you are in hope that this creates a hole at the end, you are mistaken since you would first need to write data after the hole and later truncate it to a size that contains no data.
– schily
Jul 4 '18 at 14:58
count=0 is nothing like specifying no count parameter. Are you saying thatdd if=/dev/zero of=somefile
is the same asdd if=/dev/zero of=somefile count=0
? Try it.
– PeteC
Jul 6 '18 at 10:32
Of course!count=0
is the same as if you did not specify a count parameter at all. This is true at least for all implementations that have been derived from the original sources. Try it, it seems that you did never work with the originaldd
command.
– schily
Jul 6 '18 at 10:39
I can't find any documentation that specifies 0 as a unique value forcount
meaning 'ignore this parameter'. Can you find any? Without such documentation,count=0
means 'write zero blocks' and any deviation from this is a bug... (original sources or no).
– PeteC
Jul 6 '18 at 11:14
1
This was the POSIX documentation from before May 2015 when the underspecified text was corrected.
– schily
Jul 6 '18 at 12:43
|
show 2 more comments
The best anwser here is Janis's (above) because it lets you forget about the current file size and pad directly to the desired size with no calculation.
It also takes advantage of sparse files, which appending /dev/zero doesn't.
The answer could be tidier though, because 'count' is allowed to be 0 and you still get the padding:
dd if=/dev/null of=largerfile.txt bs=1 count=0 seek=16777216
(Edit: this is correct for GNU dd, but the behaviour of count=0
is platform-specific, see comments)
The best anwser here is Janis's (above) because it lets you forget about the current file size and pad directly to the desired size with no calculation.
It also takes advantage of sparse files, which appending /dev/zero doesn't.
The answer could be tidier though, because 'count' is allowed to be 0 and you still get the padding:
dd if=/dev/null of=largerfile.txt bs=1 count=0 seek=16777216
(Edit: this is correct for GNU dd, but the behaviour of count=0
is platform-specific, see comments)
edited Jul 6 '18 at 11:45
answered Apr 17 '15 at 9:21
PeteCPeteC
1663
1663
You are mistaken:count=0
is unspecified, but typically is the same as when nocount
parameter was specified. More problems:dd
truncates the file to 16777216 bytes, but if you are in hope that this creates a hole at the end, you are mistaken since you would first need to write data after the hole and later truncate it to a size that contains no data.
– schily
Jul 4 '18 at 14:58
count=0 is nothing like specifying no count parameter. Are you saying thatdd if=/dev/zero of=somefile
is the same asdd if=/dev/zero of=somefile count=0
? Try it.
– PeteC
Jul 6 '18 at 10:32
Of course!count=0
is the same as if you did not specify a count parameter at all. This is true at least for all implementations that have been derived from the original sources. Try it, it seems that you did never work with the originaldd
command.
– schily
Jul 6 '18 at 10:39
I can't find any documentation that specifies 0 as a unique value forcount
meaning 'ignore this parameter'. Can you find any? Without such documentation,count=0
means 'write zero blocks' and any deviation from this is a bug... (original sources or no).
– PeteC
Jul 6 '18 at 11:14
1
This was the POSIX documentation from before May 2015 when the underspecified text was corrected.
– schily
Jul 6 '18 at 12:43
|
show 2 more comments
You are mistaken:count=0
is unspecified, but typically is the same as when nocount
parameter was specified. More problems:dd
truncates the file to 16777216 bytes, but if you are in hope that this creates a hole at the end, you are mistaken since you would first need to write data after the hole and later truncate it to a size that contains no data.
– schily
Jul 4 '18 at 14:58
count=0 is nothing like specifying no count parameter. Are you saying thatdd if=/dev/zero of=somefile
is the same asdd if=/dev/zero of=somefile count=0
? Try it.
– PeteC
Jul 6 '18 at 10:32
Of course!count=0
is the same as if you did not specify a count parameter at all. This is true at least for all implementations that have been derived from the original sources. Try it, it seems that you did never work with the originaldd
command.
– schily
Jul 6 '18 at 10:39
I can't find any documentation that specifies 0 as a unique value forcount
meaning 'ignore this parameter'. Can you find any? Without such documentation,count=0
means 'write zero blocks' and any deviation from this is a bug... (original sources or no).
– PeteC
Jul 6 '18 at 11:14
1
This was the POSIX documentation from before May 2015 when the underspecified text was corrected.
– schily
Jul 6 '18 at 12:43
You are mistaken:
count=0
is unspecified, but typically is the same as when no count
parameter was specified. More problems: dd
truncates the file to 16777216 bytes, but if you are in hope that this creates a hole at the end, you are mistaken since you would first need to write data after the hole and later truncate it to a size that contains no data.– schily
Jul 4 '18 at 14:58
You are mistaken:
count=0
is unspecified, but typically is the same as when no count
parameter was specified. More problems: dd
truncates the file to 16777216 bytes, but if you are in hope that this creates a hole at the end, you are mistaken since you would first need to write data after the hole and later truncate it to a size that contains no data.– schily
Jul 4 '18 at 14:58
count=0 is nothing like specifying no count parameter. Are you saying that
dd if=/dev/zero of=somefile
is the same as dd if=/dev/zero of=somefile count=0
? Try it.– PeteC
Jul 6 '18 at 10:32
count=0 is nothing like specifying no count parameter. Are you saying that
dd if=/dev/zero of=somefile
is the same as dd if=/dev/zero of=somefile count=0
? Try it.– PeteC
Jul 6 '18 at 10:32
Of course!
count=0
is the same as if you did not specify a count parameter at all. This is true at least for all implementations that have been derived from the original sources. Try it, it seems that you did never work with the original dd
command.– schily
Jul 6 '18 at 10:39
Of course!
count=0
is the same as if you did not specify a count parameter at all. This is true at least for all implementations that have been derived from the original sources. Try it, it seems that you did never work with the original dd
command.– schily
Jul 6 '18 at 10:39
I can't find any documentation that specifies 0 as a unique value for
count
meaning 'ignore this parameter'. Can you find any? Without such documentation, count=0
means 'write zero blocks' and any deviation from this is a bug... (original sources or no).– PeteC
Jul 6 '18 at 11:14
I can't find any documentation that specifies 0 as a unique value for
count
meaning 'ignore this parameter'. Can you find any? Without such documentation, count=0
means 'write zero blocks' and any deviation from this is a bug... (original sources or no).– PeteC
Jul 6 '18 at 11:14
1
1
This was the POSIX documentation from before May 2015 when the underspecified text was corrected.
– schily
Jul 6 '18 at 12:43
This was the POSIX documentation from before May 2015 when the underspecified text was corrected.
– schily
Jul 6 '18 at 12:43
|
show 2 more comments
Do you have to use dd
? If you want a file to have a particular (logical) length, just write a zero to the position you want. The bytes between the previous end and the written byte will be displayed as having null bytes. Here's an example using perl.
$ echo Hello > file
$ ls -l file
-rw-r--r-- 1 user group 6 Apr 16 22:59 file
$ perl -le 'open(my $f,"+<","file"); seek($f, 16777216 - 2, 0); print $f ""'
$ ls -ln file
-rw-r--r-- 1 user group 16777216 Apr 16 22:59 file
Why the "- 2" in the line? The script will write a byte, so we subtract 1 to seek to the position before that byte. We take off the other because the seek position is zero-indexed.
add a comment |
Do you have to use dd
? If you want a file to have a particular (logical) length, just write a zero to the position you want. The bytes between the previous end and the written byte will be displayed as having null bytes. Here's an example using perl.
$ echo Hello > file
$ ls -l file
-rw-r--r-- 1 user group 6 Apr 16 22:59 file
$ perl -le 'open(my $f,"+<","file"); seek($f, 16777216 - 2, 0); print $f ""'
$ ls -ln file
-rw-r--r-- 1 user group 16777216 Apr 16 22:59 file
Why the "- 2" in the line? The script will write a byte, so we subtract 1 to seek to the position before that byte. We take off the other because the seek position is zero-indexed.
add a comment |
Do you have to use dd
? If you want a file to have a particular (logical) length, just write a zero to the position you want. The bytes between the previous end and the written byte will be displayed as having null bytes. Here's an example using perl.
$ echo Hello > file
$ ls -l file
-rw-r--r-- 1 user group 6 Apr 16 22:59 file
$ perl -le 'open(my $f,"+<","file"); seek($f, 16777216 - 2, 0); print $f ""'
$ ls -ln file
-rw-r--r-- 1 user group 16777216 Apr 16 22:59 file
Why the "- 2" in the line? The script will write a byte, so we subtract 1 to seek to the position before that byte. We take off the other because the seek position is zero-indexed.
Do you have to use dd
? If you want a file to have a particular (logical) length, just write a zero to the position you want. The bytes between the previous end and the written byte will be displayed as having null bytes. Here's an example using perl.
$ echo Hello > file
$ ls -l file
-rw-r--r-- 1 user group 6 Apr 16 22:59 file
$ perl -le 'open(my $f,"+<","file"); seek($f, 16777216 - 2, 0); print $f ""'
$ ls -ln file
-rw-r--r-- 1 user group 16777216 Apr 16 22:59 file
Why the "- 2" in the line? The script will write a byte, so we subtract 1 to seek to the position before that byte. We take off the other because the seek position is zero-indexed.
answered Apr 17 '15 at 6:06
BowlOfRedBowlOfRed
2,705717
2,705717
add a comment |
add a comment |
yes!
it works for dd if=/dev/zero bs=1 count=262144 >> largerfile.txt
make this transaction empty with that size.
restart database
New contributor
add a comment |
yes!
it works for dd if=/dev/zero bs=1 count=262144 >> largerfile.txt
make this transaction empty with that size.
restart database
New contributor
add a comment |
yes!
it works for dd if=/dev/zero bs=1 count=262144 >> largerfile.txt
make this transaction empty with that size.
restart database
New contributor
yes!
it works for dd if=/dev/zero bs=1 count=262144 >> largerfile.txt
make this transaction empty with that size.
restart database
New contributor
New contributor
answered 1 min ago
EricEric
1
1
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f196715%2fhow-to-pad-a-file-to-a-desired-size%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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 as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
@terabyte; do you want physical padding or logical padding? In other words; should the file only show a size of 16777216 (and may contain holes) or shall it also occupy that amount of storage on the disk? - BTW, choosing a
bs=1
indd
is in my experience very runtime expensive.– Janis
Apr 16 '15 at 22:50
4
truncate -s 16M thefile
– frostschutz
Apr 17 '15 at 9:28
4
@frostschutz that'd be a good answer, were you to post it as an answer.
– derobert
Apr 17 '15 at 9:40
@derobert, What's with StackExchange site users posting legit, simple answers as comments?
– user1717828
Apr 20 '15 at 5:29
@user1717828 not sure, probably a good question for meta.
– derobert
Apr 20 '15 at 7:27