LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 12-19-2010, 12:29 PM   #1
dgs012
LQ Newbie
 
Registered: Dec 2010
Posts: 4

Rep: Reputation: 0
Using dd command to write bytes


I'm using
Code:
dd if=/dev/zero bs=5 count=1 of=binfile
Then I run

Code:
hexdump -b binfile
0000000 000 000 000 000 000

How can I use dd to write bytes of 1 or 5 for example?
hexdump -b will return
0000000 001 001 001 001 001
or
0000000 005 005 005 005 005
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 12-19-2010, 02:08 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,503

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Maybe with something like this:
Code:
$ for i in {1..5}; do echo -n $'\x01'; done | dd of=binfile
0+1 records in
0+1 records out
5 bytes (5 B) copied, 7.0541e-05 s, 70.9 kB/s
$ hexdump -b binfile
0000000 001 001 001 001 001                                            
0000005
Another option is to use /dev/zero and change zeros on the fly using sed, e.g.
Code:
$ dd if=/dev/zero bs=5 count=1 | sed 's/\x00/\x01/g' > binfile
1+0 records in
1+0 records out
5 bytes (5 B) copied, 2.4654e-05 s, 203 kB/s
$ hexdump -b binfile
0000000 001 001 001 001 001                                            
0000005
The tr command may serve the same purpose.

Last edited by colucix; 12-19-2010 at 02:23 PM.
 
2 members found this post helpful.
Old 12-19-2010, 03:52 PM   #3
dgs012
LQ Newbie
 
Registered: Dec 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Thank you very much.

I used the second option because I needed to add the bytes at the end of the file.

Worked great!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Write command in QT navderm Programming 1 01-04-2009 08:41 PM
Command to capture page faults and private bytes? ashokkumars Linux - Kernel 2 03-20-2008 01:32 AM
write hex bytes to file pixellany Programming 3 06-25-2007 05:31 PM
TX bytes vs. httpd bytes ovrload Linux - Networking 3 10-12-2005 04:19 PM
Change bytes display on command line Shinobi Linux - General 3 06-04-2003 09:03 AM


All times are GMT -5. The time now is 07:54 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration