DD NOTRUNC OPTION
####################
When writing a file to another file, you have the option to write 2 ways with dd, with notrunc or without notrunc(default)
Easiest thing to remember is no trunc (no truncation, so it doesnt truncate the stuff at the end, leaving the end of resulting file alone)
So remember “notrunc” is “no truncation”
Also remember to set it with dd, its conv=notrunc (not just notrunc), its a conversion option (or wahtever the convs mean in dd)
EXPLAINED IN MORE DETAIL
###########################
IF ENABLED THE NOTRUNC OPTION, DD OVERWRITES, BUT LEAVES THE SPACE ALONE AFTER
SO WRITING
b to aaaaaaaaaaaaaa
WITH NO TRUNC
WOULD GIVE
baaaaaaaaaaaaa
WITHOUT THE NOTRUNC OPTION (DEFAULT OPTIONS), DD OVERWRITES, BUT DELETES EXTRA SPACE
SO WRITING
b to aaaaaaaaaaaaaa
WITHOUT NOTRUNC (DEFAULT OPTIONS)
WOULD GIVE
b
HERE IS THE EXAMPLE
#####################
FIRST WE WRITE SOME A’S TO 3 TEST FILES, THIS TYPE OF ECHO COMMAND, ENDS EACH STRING WITH A NEWLINE CHARACTER. THE -N OPTION ON THE ECHO WILL MAKE SURE THAT THE B LETTER DOESNT HAVE A NEWLINE CHARACTER AFTER. OR ELSE WHEN WE OVERWRITE WE WOULD GET “B THEN A NEW LINE THEN THE AAAAAAA” BUT WITH THE -N THE END RESULT WILL BE “BAAAAAAA”
# echo "aaaaaaaa" > test1 # echo "aaaaaaaa" > test2 # echo "aaaaaaaa" > test3 # echo -n "b" > test4
COPY OVER THE b TO THE aaaaaaaa WITHOUT NO TRUNC
# dd if=test4 of=test2 0+1 records in 0+1 records out 1 byte (1 B) copied, 2.3e-05 seconds, 43.5 kB/s
COPY OVER THE b TO THE aaaaaaaa WITH NOTRUNC
# dd if=test4 of=test3 conv=notrunc 0+1 records in 0+1 records out 1 byte (1 B) copied, 1.6e-05 seconds, 62 kB/s
SO TEST1 IS UNCHANGED, TEST2 HAD TEST4 WRITTEN TO IT WITHOUT NOTRUNC (DEFAULT OPTIONS), AND TEST3 HAD TEST4 WRITTEN TO IT WITH NOTRUNC (DEFAULT OPTIONS)
RESULTS OF EACH ONE
THE NORMAL aaaaaaaa FILE (THE ORIGINAL)
# cat test1 aaaaaaaa
THE COPY DONE WITHOUT NOTRUNC (note that since there is no newline character when the b prints immediately after it goes the prompt, ready for your next commands press enter if its throwing you off so your on a new clean prompt)
# cat test2 b AcTUAL OUTPUT: b# <- wraps to prompt because no newline char at end (because of echo -n)
THE COPY DONE WITH NOTRUNC
# cat test3 baaaaaaa
THE B FILE WE USED AS THE SOURCE (note that since there is no newline character when the b prints immediately after it goes the prompt, ready for your next commands press enter if its throwing you off so your on a new clean prompt)
# cat test4 b AcTUAL OUTPUT:b# <- wraps to prompt because no newline char at end (because of echo -n) b
NOTE: SAME RESULTS IF WE SET THE BLOCK SIZE TO SOMETHING REALLY HIGH LIKE 1M, BY DEFUALT THE BS IS 512. SO ANY BLOCK SIZE SHOULD PRODUCE SAME RESULTS