coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[coreutils] Use of backup and suffix options with ln command


From: Surfin Ten
Subject: [coreutils] Use of backup and suffix options with ln command
Date: Wed, 30 Jun 2010 17:24:53 -0600

I have a small script I have written, incorporating zenity, which
searches for files and creates symbolic links to them. Here's an
example of what it does:

find "/home/mine" -iname myfile.txt -exec sh -c 'filename="${0##*/}";
ln -s "$0" "$1"' {} "myfile.txt" \;

In the real script, some of the above is passed to it through
variables, but I want to keep the sample short so I specified the path
and filename just as an example to help explain what I am trying to
do.

As the drive is scanned, there are times when the script will find
files with the same name in different locations depending on what the
user specified to search for. Since the script creates all the
symbolic links in the same directory, this means the first symbolic
link created is overwritten if an identically named symbolic link is
created later on.

To work around this, I modified the portion of the command
implementing "ln" to use the --backup option.

Example: ln --backup=numbered -s "$0" "$1"' {} "myfile.tx" \;

This works well in a command line environment. For instance, if a
symbolic link is created called myfile.txt and another with the same
name is created later on, the second symbolic link is named
myfile.txt~1~.

The problem is that Gnome/Nautilus treats the symbolic link with the
tildes (i.e., ~) in it as a hidden file. This means having to enable
the viewing of hidden files which is not really ideal for my intended
purpose (the users don't like it).

So, I thought I would incorporate the --suffix option to eliminate the
tildes in the name of the symbolic links. Here's the modified ln
command portion:

Example: ln -b --suffix=. -s "$0" "$1"' {} "myfile.tx" \;

If a duplicate symbolic link is created called myfile.txt, I expected
the above to create a sybmolic link for the duplicate called
myfile.txt.1. However, it instead created a link called myfile.txt.
(the period on the end is part of the name of the duplicate link, not
to mark the end of the sentence). Then, if additional files are found
that result in more duplicate links, the first duplicate is
continually overwritten.

I've downloaded the GNU coreutils documentation and read the sections
regarding the ln command and backup options. In Section 2.2 "Backup
options", it says "-b" does not accept any argument and that using it
is equivalent to using "--backup=existing". So, I tested this and did
get the same results as before, except that the suffix is back to
using tildes.

My confusion stems from the wording in the documentation which
describes "--backup=existing" as "Make numbered backups of files that
already have them, simple backups of others." To me, then, it seems
like this is saying that duplicated links should be numbered when
using "-b" or "--backup=existing", but instead my results just end
with the suffix and the first duplicate keeps getting overwritten by
later duplicates.

So, is there a way to make duplicate links numbered as with
"--backup=numbered" while still being able to change the suffix to
something other than a tilde?

Modifying the environment variable as discussed in the documentation
is not really an option for my users.

Thanks.

Sam



reply via email to

[Prev in Thread] Current Thread [Next in Thread]