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”

 

COPY OVER THE b TO THE aaaaaaaa WITHOUT NO TRUNC

 

COPY OVER THE b TO THE aaaaaaaa WITH NOTRUNC

 

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)

 

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)

 

THE COPY DONE WITH NOTRUNC

 

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)

 

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

Leave a Reply

Your email address will not be published. Required fields are marked *