linux create file of specified size

1. Generate files with the same size as the actual size

dd if=/dev/zero of=50M.file bs=1M count=50

dd if=/dev/zero of=20G.file bs=1G count=20

bs=1M means read and write 1M data each time, count=50 means read and write 50 times, so the size of the generated file is specified as 50M. The bs parameter can be further subdivided into ibs and obs, which specify different Buffer sizes for read operations and write operations.

 

2. The size of the generated file is fixed, but it does not actually occupy the space command

dd if=/dev/zero of=1G.img bs=1M seek=1000 count=0

A new command seek is used here, which means that 1000 blocks are skipped and not written (here, the block is 1M according to the definition of bs), and count=0 means that 0 blocks are written. Use the ls (view file size) command to see the newly generated file, and the size can be seen to be 1000M. But then use du (check the space occupied by files) to see that the actual hard disk size is only 0M.

 

3. Detailed command

dd command usage:

dd [options]
if = input file (or device name).
of = output file (or device name).
ibs = bytes reads bytes bytes at a time, that is, the number of bytes read into the buffer.
skip = blocks skips the ibs*blocks blocks at the beginning of the read buffer.
obs = bytes writes bytes bytes at a time, the number of bytes written to the buffer.
bs = bytes also sets the number of bytes in the read/write buffer (equivalent to setting ibs and obs).
cbs = byte converts bytes bytes at a time.
count=blocks copies only the input blocks.
conv = ASCII Convert EBCDIC code to ASCII code.
conv = ebcdic Convert ASCII code to EBCDIC code.
conv = ibm converts ASCII code to alternate EBCDIC code.
conv = block converts variable bits to fixed characters.
conv = ublock converts fixed bits to variable bits.
conv = ucase converts letters from lowercase to uppercase.
conv = lcase converts letters from uppercase to lowercase.
conv = notrunc does not truncate output files.
conv = swab swaps each pair of input bytes.
conv = noerror Do not stop processing on errors.
conv = sync resize each input record to the size of ibs (filled with NUL).

 

iconv command usage:

iconv [options...] [file...]
input/output format specification:
-f, --from-code=raw text encoding
-t, --to-code=output text encoding
information:
-l, -- list List all known charset
output controls:
-c ignore invalid characters from output
-o, --output=FILE output file
-s, --silent turn off warnings
--verbose print progress information
-?, --help give a list of help for this system
--usage give brief usage information
-V, --version print program version number

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324734410&siteId=291194637