Tag Info

Hot answers tagged

22

When you pipe the output, ls acts differently. This fact is hidden away in the info documentation: If standard output is a terminal, the output is in columns (sorted vertically) and control characters are output as question marks; otherwise, the output is listed one per line and control characters are output as-is. To prove it, try running ls and ...


7

For hysterical historical reasons, od prints two-byte words¹ by default. The number 020061 (octal) corresponds to the two-byte sequence 1␣ (␣ is a space character). Why? It's clearer if you use hexadecimal: 0o20061 = 0x2031, and ␣ is 0x20 (32) in ASCII and 1 is 0x31 (49). Notice that the lower-order bits (0x31) correspond to the first character and the ...


6

hd is a synonym for hexdump -C on FreeBSD and on some Linux distributions. hexdump is from the BSD days; od is from the dawn of time. Only od is standardized by POSIX. The Single UNIX rationale discusses why od was chosen in preference to hd or xd. These commands do very similar things: display a textual representation of a binary file, using octal, decimal ...


5

Linux doesn't let you do a plain read(dir_name, buffer, sizeof(buffer) - it always returns -1 and puts EISDIR in errno. This is probably rational, as not all filesystems have directories as files. The commonly-used reiserfs does not, for example. You can use the open() system call from a C program to get a file descriptor of a directory, but things like ...


3

One of the first things I had to memorise for computer science was Data + Interpretation = Useful Information. A corollary of this is that if you're missing Data or Interpretation, you have nothing. The data itself can't tell you how to interpret it. (you can have metadata which tells you this, but then you need to know how to interpret the metadata too) ...


2

"Named characters" means the output will print the name of a character rather than its numerical ASCII value. For printable characters, the name used is the actual character and for non-printable the names are things like nl for newlines and sp for spaces. The high-order bit is the bit with the highest value. For single-byte ASCII characters, this bit ...


2

Interesting question. After browsing the man page, I found that -o prints octal output (od == octal dump), the c you appended only prints the associated characters as well. You get the same numbers with -o alone. Looking at the output it appears that od is reading data two bytes at a time. Take the first two characters for instance: CHAR - OCTAL - BINARY 1 ...


2

There are lots of ways of storing numbers - ascii (which can have locale specific variants, such as using ',' to seperate fractional part OR as a thousands grouping), binary integer (variable number of bits)/float/double (all of which may vary depending on endian architecture and whether software producing the file formalises the representation), BCD ...


1

Your discovery highlights the primary reason why parsing the output of ls is always a bad idea. See Greg's wiki for a full explanation. Think of your problem in reverse. You noticed that ls sometimes does and sometimes doesn't print newlines between it's output. For use in scripts or when forced by the -1 flag, it does. One newline at the end of each file. ...


1

A od-less solution, just bash, and just lowercase, so far. z is the character searched for, here s as search. i=97 because ascii(a)=97. The rest is obvious. z=s i=97 for c in {a..z} do [ "$c" = "$z" ] && echo $i && break || ((i+=1)) done You may put it into a single line of course. Here are some semmicolons: ;;;;; (should be enough)



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