Полезная информация

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 35.5 Remove Mail/News Headers with behead Chapter 35
You Can't Quite Call This Editing
Next: 35.7 offset: Indent Text

35.6 Low-Level File Butchery with dd

Want to strip off some arbitrary number of characters from the front of a file?

dd provides an unexpectedly easy answer. Let's say you wanted to delete the first 100 characters in a file. Here's the command that will do the trick (assuming of course that you give dd a filename with the if= option or data from a pipe):

% dd bs=100 skip=1

Or you could try:

% dd bs=1 skip=100

dd normally reads and writes data in 512-byte blocks; the input block size can be changed with the ibs= option, and the output block size with obs=. Use bs= to set both. skip= sets the number of blocks to skip at the start of the file.

Why would you want to do this? Article 22.17 gives an interesting example when encrypting files. Article 20.6 explains using dd over a network with a tape drive. To convert files between ASCII and EBCDIC, see article 35.12. Article 35.13 shows even more uses for dd.


Previous: 35.5 Remove Mail/News Headers with behead UNIX Power ToolsNext: 35.7 offset: Indent Text
35.5 Remove Mail/News Headers with behead Book Index35.7 offset: Indent Text

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System