Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What might be confusing you: <code>[</code> is actually a Unix shell command. You can find it in <code>/bin</code> and when you look more closely, it's a hard link to the <code>test</code> command which means you could also write:</p> <pre><code>test -f /etc/bashrc &amp;&amp; source /etc/bashrc </code></pre> <p>(<code>.</code> is a shortcut for <code>source</code>).</p> <p>Historic note for your amusement: When Unix was invented, there were no screens but "teletypes" which is a kind of typewriter. You sent a command to the Unix host and the teletype would print the result. The rumor goes like this: Since the early Unix developers were tired of all the racket the teletypes created, they tried to shorten all the commands to two letters and all options to a single letter.</p> <p>If you're green, then the rumor is: To save paper and ink ribbon, they tried to shorten all the commands to two letters and all options to a single letter.</p> <p>And if you look into <code>/dev</code>, you'll see all those <code>tty</code> files which is the only thing that's left from the original teletypes.</p> <p>[EDIT] How to figure out that that <code>[</code> and <code>test</code> are the same thing:</p> <p>This is a two-step process. <code>ls -il [ test echo</code> gives:</p> <pre><code>356954 -r-xr-xr-x 2 root wheel 46K May 31 2008 [ 356954 -r-xr-xr-x 2 root wheel 46K May 31 2008 test 67392 -rwxr-xr-x 1 root wheel 18K Sep 22 2007 echo </code></pre> <p>First, you notice the "2" before "root". This means that there are two directory entries (a.k.a file names) which point to the same data (Unix lingo: inode, i-node or "index node"). Every inode on the disk has a unique number which is the first number in the example above (356954). You can see that <code>[</code> and <code>test</code> share the same inode but <code>echo</code> doesn't.</p> <p>Note that there is no fast way to get all directory entries which point to the same inode. You have to search the whole filesystem for an entry with the same inode (using <code>find /path -inode 356954</code>)</p> <p>[EDIT2] As for the tty "files": These are in fact device nodes. The first letter of the permissions is "c" as in "character device". You can find "-" for files, "d" for directories and "b" for block devices (like hard disks, floppies, etc). This is not a file but it's a really a program. You can talk to it by sending data to it ("writing" something in the "file") or read data from it. The concept seemed so close to real files that the Unix inventors used a the file API plus something called "IO control" (or ioctl) to send special commands (like querying a terminal for its size).</p> <p>If you switch to console mode ("Ctrl-Alt-F1"), you'll see something like:</p> <pre><code>Welcome to .... - Kernel .... (tty1) </code></pre> <p>Switch to another console (with Alt-F2...Alt-F6) and you'll see they are connected to <code>tty2</code> to <code>tty6</code>. Login on one of them and try</p> <p>echo test > /dev/tty1</p> <p>And the string will appear on the console connected to <code>tty1</code>. Reading from a tty is a not so easy since there is already a program reading from it (either <code>mingetty</code> as long as you're not logged in and <code>login</code> or <code>bash</code> after log in). If you try <code>read line &lt; /dev/tty1</code>, that would conflict with the program which is already running on that console but in principle, it would work.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload