Hot answers tagged

33

You cannot do this because for such a conversion, you need to know the meaning of the binary content. If e.g. there is a string inside a binary file it must not be converted and a 4 byte integer may need different treatment than a two byte integer. In other words, for a byte order conversion, you need a data type description.


32

You can byteswap with dd. Is that sufficent? If not, please update your question to give an example of an input file and the expected outfile. echo hello >infile dd conv=swab <infile >outfile hex infile 0000 68 65 6c 6c 6f 0a hello. hex outfile 0000 65 68 6c 6c 0a 6f ehll.o


18

This uses od to show one hex value per line, then sorts and counts: od -t x1 -w1 -v -An mybinaryfile | sort | uniq -c (-w1 is an extension, it’s not mandated by POSIX.)


13

Yes, there are such cases. In case of symlinks on Linux system with GNU ls, the ls -l will put out the size of the link, while wc -c will resolve the actual file and read number of bytes there. Below you can see that ls -l reports 29 bytes , while wc reports 172 bytes in the actual file. $ ls -l /etc/resolv.conf ...


12

You can combine GNU tail and head: tail -c +26 file | head -c -2 will output the contents of file starting at byte 26, and stopping two bytes (minus two -2) before the end. (-c operates on bytes, not characters.)


11

ls -l will return the size of the file reported by the filesystem. wc -c will attempt to read the file to determine the 'actual' size. From my observations it appears to first try seeking to the end, and if this doesn't work, it will read out the entire file, counting the size as it goes. This is a simple description as to what the two tools do, but it ...


6

For a normal file, ls and wc call stat. However, for a file of /proc or /sys, ls returns 0, but wc returns a different number: $ ls -l /proc/modules -r--r--r-- 1 root root 0 Jan 16 14:56 modules ^ this one $ wc -c /proc/modules 7621 modules This is probably some way of finding out if something is a special file.


5

There's no fully reliable way to put an invisible mark in a text file. A text file has no room for anything that isn't plain text, after all. Comments (text that doesn't belong in the main text) are a form of markup. Null bytes are a bad idea not only because they may be rendered as ^@ or ␀ or � or other ways, but also because many text processing tools ...


5

Using Perl to unpack the slurped file to a byte array and then use a hash to count unique bytes: printf '\xA0\x01\x00\xFF\x77\x01\x77\x01\xA0' | perl -0777 -nE ' @bytes = unpack("C*",$_) }{ $counts{$_}++ for @bytes; for $k (sort { $a <=> $b } keys %counts) { printf "%02X: %d\n", $k, $counts{$k} } ' 00: 1 01: 3 77: 2 A0:...


4

dd will do both for you in a single command. Set the block size to 1 byte, skip the 25 first bytes, count to the size of file minus skip and end bytes. 100 byte file file.img dd if=./file.img of=./trimed_file.img bs=1 skip=25 count=73 Double check numbers cause it might count from 0.


4

You're running od on a little-endian machine. >>> 0x1f1b 7963


3

This is a rather new addition to wget (1.13.4 doesn't have it) and there is no other value for that option, the manual is quite clear: ‘--report-speed=type’ Output bandwidth as type. The only accepted value is ‘bits’.


3

Is this 4097 bits (or bytes?) of entropy? Neither. Entropy is a property of how the random data was generated (see, e.g., this Crypto.SE post), not how much of it was generated. If openssl rand could generate data with x bits of entropy, that would still be x bits of entropy irrespective of whether you told it to output 1 bit or 1 TB. A detailed discussion ...


2

With ksh93: { head -c "$n"; } < file <#((n = EOF - 25 - 2 , 25)) Or to do it in-place: { head -c "$n"; } < file <#((n = EOF - 25 - 2 , 25)) 1<>; file If you have /opt/ast/bin ahead of your $PATH, you'll get the head builtin. <#((...)) is a lseek() operator. ... is interpreted as an arithmetic expression where EOF is the length of ...


2

You can grep for null or other special characters using the -P flag and the hex code: echo -e "a\0b\nhello" | grep -a -P '\x0' You could also hide text by putting backspace characters after them, for example: $ echo -e "the matrix\0\0\0\0\n\bh\ba\bs\b \by\bo\bu\b\0\0:-)" the matrix :-) $ echo -e "the matrix\0\0\0\0\n\bh\ba\bs\b \by\bo\bu\b\0\0:-)" | ...


1

Actually wget reports speed by default, and it would be in kilobytes/megabytes: 2017-07-08 23:33:45 (362 KB/s) - ‘openwrt-ar71xx-mikrotik-vmlinux-lzma.elf.4’ saved [1230693/1230693] In case you would set an option '--report-speed=bits' it would report speed in megabits/kilobits, like 2017-07-08 23:33:21 (2.74 Mb/s) - ‘openwrt-ar71xx-mikrotik-vmlinux-lzma....


1

It is really unclear, what you are asking. Yes, you can count LOC in the Linux kernel, but you cannot in any commercial UNIX. Therefore it is not really possible to compare those. What do you mean with "storage size"? You can download the Linux kernel from kernel.org. You can look at the compressed size, you can unpack it and look at the size of the ...


Only top voted, non community-wiki answers of a minimum length are eligible