Create Sym Links for a series of files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Create Sym Links for a series of files
# 1  
Old 04-13-2015
Question Create Sym Links for a series of files

Hello,

I would like to create symbolic links for a series of files in my cwd (after confirming that the links don't already exist). The above files all have a similar prefix, but different extensions.

I created a shell script like shown below and I get an error message "No such file or directory"

Code:
#!/bin/sh

for x in `ls -1 /myRandomDir/myFiles.*`
do
    if [ ! -f $x ]
    then
        ln -s $x
    fi
done

What should I do differently.

Thanks!
~Guss
# 2  
Old 04-13-2015
ln -s needs two parameters (man ln):
Quote:
ln [OPTION]... [-T] TARGET LINK_NAME (1st form)
And, you don't need the command substitution in the for statement: for x in /myRandomDir/myFiles.* should suffice.
# 3  
Old 04-13-2015
Hello Rudi,

Well, I want to use the 2nd form without an alias; the manual tells me that I need to do the following:

Code:
 ln -s TARGET

Following this logic, I wan to create symlinks in my cwd for files that exist in another directory.

I have used the code in my previous thread, sans the check for existence, number of times. This time around, I wanted to add code to check the symlinks don't exist before I create them.

Thanks for your input!
~Guss

Last edited by Gussifinknottle; 04-14-2015 at 06:24 AM..
# 4  
Old 04-13-2015
$x is the target, where the link points to.
The target should exist. The link is implicitly generated by the ln; you must explicitly generate it for a test.
Code:
if [ -f "$x" ] && [ ! -f `basename "$x"` ]
then

# 5  
Old 04-13-2015
Sorry, that wasn't clear from your post. Where and when does the error msg occur? Please provide the two directory listings, too.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Find cmd and sym links

Hi. Can somebody tell me if there's a way of creating a symbolic link from a directory on one filesystem to that on another that will allow a find command that doesn't use the -L param to locate a particular file under that new 'linked' dir. With a normal sym link the find command on that... (6 Replies)
Discussion started by: user052009
6 Replies

2. Shell Programming and Scripting

Running a script over a series of files

Hi, I want to run a script over a series of files with the names : Sample_1.sorted.bam Sample_2.sorted.bam Sample_3.sorted.bam How can I specify it in my script. Thanks a lot in advance. (3 Replies)
Discussion started by: Homa
3 Replies

3. Shell Programming and Scripting

Create tar file excluding all hard links

I have a problem with tar. Taring a folder with a lot of contents, causes the tar to contain hard links to some files, seen with the same name but 0 in size. The hard links don't exist in the first place. How can I prevent that from happening? I am using the -T option with either -n or... (2 Replies)
Discussion started by: Tribe
2 Replies

4. Solaris

Hard Links and Soft or Sym links

When loooking at files in a directory using ls, how can I tell if I have a hard link or soft link? (11 Replies)
Discussion started by: Harleyrci
11 Replies

5. Solaris

Create sym-link into /dev (zone)

Hi i need to install a software into a zone, and this kind of software needs to have a file who is linked into /dev. But it is not possible to create a link into /dev nor create a file into it. -bash-3.00# ln -s /tmp/testfile /dev/ ln: cannot create /dev//testfile: Permission denied... (2 Replies)
Discussion started by: beta17
2 Replies

6. UNIX for Dummies Questions & Answers

can I create symbolic links for multiple files simultaneously

Does anybody know how to make symbolic links for multiple files simultaneously? Often times I need make symbolic links for multiple files with some common pattern (just like "*.jpg"). Is there a way to avoid making symbolic link for each of them one by one... Thank you! (6 Replies)
Discussion started by: danieladna
6 Replies

7. AIX

How to create a sym link pointing a changing name.

Hello A new file is created every day with the date appended to the end of a name. We are using Autosys to run jobs which watches for the file and runs jobs. But Autosys does not have the capability to figure out the current date. I tried creating a symlink like this ln -s... (1 Reply)
Discussion started by: vra5107
1 Replies

8. UNIX for Dummies Questions & Answers

rsync with --link-dest doesn't create hard links

I have been experimenting with rsync as a scriptable backup option, reading various example and tips pages, including Time Machine for every Unix out there - IMHO That page seems to describe the exact behavior I want: The ability to make a "full backup" snapshot regularly, but with rsync... (0 Replies)
Discussion started by: fitzwilliam
0 Replies

9. UNIX for Dummies Questions & Answers

How do I organize a series of files in date order?

I'd like to ls a group of files in date order but I'm not sure what the commands would be. Can anyone help with this? (1 Reply)
Discussion started by: hedgehog001
1 Replies

10. UNIX for Dummies Questions & Answers

find and sym links

Would I be correct in assuming that find doesn't bother recursivley searching down sim links. (It doesn't seem to so I guess it doesn't!!!) Is there anyway to make it do so? (3 Replies)
Discussion started by: peter.herlihy
3 Replies
Login or Register to Ask a Question