Saturday, January 28, 2012

Re: Redhat Linux has crippled Vim

On 01/28/2012 07:07 AM, Christian Brabandt wrote:
> On Sa, 28 Jan 2012, Tony Mechelynck wrote:
>
>> Beware that the order of the arguments of the "ln" command is
>> unintuitive: target first, then link name.
>
> If you think of it as a command, that always needs a target, but does
> not necessarily need a link name, then it is not intuitive.

The ``ln`` command became intuitive to me when I realized that
its syntax is uniform with that of the ``cp`` command:

Copy source file(s) into destination:
$ cp source destination
$ cp source1 source2 source3 destination

Hard link source file(s) into destination:
$ ln source1 source2 source3 destination
$ ln source destination

Symlink source file(s) into destination:
$ ln -s source1 source2 source3 destination
$ ln -s source destination

With only one source, ``destination`` may be a directory or a
filename. With multiple sources, ``destination`` must be a
directory.

In all of the above cases, the last argument on the right
represents where to create the new item(s). Each new item is
either a copy of an existing file, a hard link to an existing
file, or a symlink to an existing file. At some level, all of
the new items "point back" to the original source. A symlink
points back in the most directly visible way, since the ``ls``
command uses an arrow to show the linkage:

$ mkdir ~/tmp/linkdemo
$ cd ~/tmp/linkdemo
$ touch source
$ ln -s source symlink
$ ls -l symlink
lrwxrwxrwx 1 mike mike 6 2012-01-28 08:06 symlink -> source

In my opinion, this arrow notation is what makes the
command-line syntax seem counter-intuitive, since ``symlink`` is
displayed on the left and ``source`` is on the right. It helps
me to recall that ``symlink`` was created as a (linked) copy of
``source``, so it's pointing back to the original.

Hard links work similarly:

$ ln source hardlink
$ ls -li
13239823 -rw-rw-r-- 2 mike mike 0 2012-01-28 08:06 hardlink
13239823 -rw-rw-r-- 2 mike mike 0 2012-01-28 08:06 source
13239824 lrwxrwxrwx 1 mike mike 6 2012-01-28 08:06 symlink -> source

The ``-i`` flag shows the "inode" number in the first column.
``hardlink`` and ``source`` now share the same inode number,
which means both filenames link to the same underlying stream of
bytes, so they are linked together. For example:

$ echo "Some new text" > source
$ cat hardlink
Some new text
$ diff -s source hardlink
Files source and hardlink are identical

This syntax has the nice feature that you can do wildcard copies
or links in the same way:

Copy multiple pictures to a backup directory:
$ cp ~/pictures/*.jpg /path/to/backup/directory/

Symlink pictures of Snowmen into a separate directory:
$ mkdir ~/tmp/snowmen
$ ln -s ~/pictures/snowman*.jpg ~/tmp/snowmen

Michael Henry

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment