can I create symbolic links for multiple files simultaneously


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers can I create symbolic links for multiple files simultaneously
# 1  
Old 02-24-2011
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!
# 2  
Old 02-24-2011
please give more clue about the Source and target directory as well as the filenames

Let's say you have a /target directory containing
Code:
pic1.jpg
pic2.jpg
pic3.jpg
pic4.jpg
...

and you want to create some links in /linksource
Code:
lnkpic1 pointing to pic1.jpg
lnkpic2 pointing to pic2.jpg
lnkpic3 pointing to pic3.jpg
lnkpic4 pointing to pic4.jpg
...

to create those lnkpic* link you can for example :
just

Code:
cd /linksource
for i in /target/pic*.jpg
do
t=${i##*/}
ln -s "$i" lnk"${t%.*}"
done

If what you want is something else for example, you want /linksource to be a link to /target so that if someone do cd /linksource, he goes to /target and can see the pic*.jpg,
then
Code:
ln -s /target /linksource


Last edited by ctsgnb; 02-24-2011 at 03:00 PM..
# 3  
Old 02-24-2011
e.g.
I have 50 files in the directory jpg1

file1.jpg
file2.jpg
..
file50.jpg

I want to make symbolic links for all them to my current directory /jpg2

I tried in directory jpg2

$ln -s ~/jpg1/*.jpg *.jpg
# 4  
Old 02-24-2011
Are you sure you don't prefer your jpg2 be a link to jpg1 ? if so :
Code:
ln -s /jpg1 /jpg2

Else, if you want a link for each an every file... then :

Code:
cd /jpg2
for i in /jpg1/*.jpg
do
ln -s "$i" "${i##*/}"
done

# 5  
Old 02-24-2011
This doesn't seem to be working for me.
I get the message that ln: target `pic1.jpg' is not a directory
Any clues?
# 6  
Old 02-24-2011
What is your OS ?
check the syntax of ln command
Code:
man ln

if on solaris try using /usr/xpg4/bin/ln

Last edited by ctsgnb; 02-24-2011 at 03:21 PM..
# 7  
Old 03-18-2011
the trick here is to go into the target directory before issuing the ls command:

cd /jpeg2
ln -s /jpeg1/* -t .
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

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... (4 Replies)
Discussion started by: Gussifinknottle
4 Replies

2. Solaris

Symbolic links

Soft link,Hard link brief explanation (1 Reply)
Discussion started by: RAJU KAVATI
1 Replies

3. UNIX for Dummies Questions & Answers

Symbolic links in UNIX

Hi, I have a file with more than 1 layers of soft links for it. For ex. ls -la .profile .profile@ -> /home/act/.profile_abc ls -la /home/act/.profile_abc@ -> .profile_final I want to get the name of the last file (i.e. .profile_final) when I refer to .profile using shell script. I... (2 Replies)
Discussion started by: deo_kaustubh
2 Replies

4. UNIX for Dummies Questions & Answers

Symbolic Links

Hi all, I have scoured the entire forum for this but to no avail unfortunately. Basically, I would like to remove my symbolic link from my folder name i.e. foldername -> /a/b/c/d/f where f is indeed a folder. I have tried rmdir but this does not work and in actual fact deletes the... (4 Replies)
Discussion started by: cyberfrog
4 Replies

5. Shell Programming and Scripting

renaming multiple files simultaneously

Hi , I have a large no of files which all end in .asp.htm extension . But for proper navigation between the pages I need to rename all those files as .asp only . How can it be done ? (4 Replies)
Discussion started by: nshailesh
4 Replies

6. UNIX for Dummies Questions & Answers

Symbolic links between directories

Hi all, lets consider 2 directories test1 and test2. I want to link test2 to point to test1, how do u do this? (4 Replies)
Discussion started by: Mr. Zer0
4 Replies

7. Shell Programming and Scripting

simultaneously create three empty files?

I can't get touch to simultaneously create three empty files file1, file2, file3. I tried:$ touch filebut all I got was one file:$ fileWhat did I do wrong? (4 Replies)
Discussion started by: na5m
4 Replies

8. AIX

Symbolic Links

I am linking a directory as follows: ln -sf /home/xxx/userid/real_files/* /home/xxx/userid/linked_files This gives me symbolic links for all the files in the real_files directory in the linked_files directory. My question is, if I go and remove a file in the real_files directory and then go... (1 Reply)
Discussion started by: rcarnesiii
1 Replies

9. UNIX for Dummies Questions & Answers

deleting files by type (symbolic links)

How do I delete just the symbolic links in a directory? I have files that I wish to keep that have similar names, length and date/time. Can I use file size? Thanks kyle (4 Replies)
Discussion started by: kryan_toolboy
4 Replies

10. Solaris

cp a dty without symbolic links?

Hi, - we have copy (cp command) to do to save all the contents of a dty BUT we dont want to copy the files corresponding to symbolic links contained whithin this dty - the box is a sun solaris one - and the cp commande do not say avything about that? thanks for help Jakez (7 Replies)
Discussion started by: JAKEZ
7 Replies
Login or Register to Ask a Question