Script for creating symbolic links to my photos (*.JPG)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for creating symbolic links to my photos (*.JPG)
# 1  
Old 03-17-2014
Script for creating symbolic links to my photos (*.JPG)

Hi,


I have all my pictures as *.JPG and *.CR2 in the following folder structure:
/media/a_2TB/pictures/year/year-month-day-hour/picture*.*

But sometimes I added a subdirectory -->
/media/a_2TB/pictures/year/year-month-day-hour/suba/picture*.*
/media/a_2TB/pictures/year/year-month-day-hour/subb/picture*.*


I would like to create symbolic links to all pictures of a whole year.

The following command is working fine except of additional sub-directories.

Code:
find 2006/. \( -name "*.CR2" -o -name "*.JPG" \) -execdir sh -c 'ln -s "$PWD"/$(basename {}) ../../2006_Links/Link_$(basename {})' {} \;

What do I have to change to make it flexible to subfolders?

I tried changing the command but it then it won't work anyhow :-(

Code:
f=$(pwd);
find 2006/. \( -name "*.CR2" -o -name "*.JPG" \) -execdir sh -c 'ln -s "$PWD"/$(basename {}) "$f"/2006_Links/Link_$(basename {})' {} \;

Altough the same command without the path variable does work:
Code:
find 2006/. \( -name "*.CR2" -o -name "*.JPG" \) -execdir sh -c 'ln -s "$PWD"/$(basename {}) /media/a_2TB/pictures/2006_Links/Link_$(basename {})' {} \;

Best regards,
Arthur

Last edited by 8200; 03-17-2014 at 07:26 PM..
# 2  
Old 03-17-2014
try:

Code:
f=$(pwd);
export f
find 2006/. \( -name "*.CR2" -o -name "*.JPG" \) -execdir sh -c 'ln -s "$PWD"/$(basename {}) "$f"/2006_Links/Link_$(basename {})' {} \;

# 3  
Old 03-18-2014
Thank you, Chubler_XL!!!

It works :-)

Quote:
Originally Posted by Chubler_XL
try:

Code:
f=$(pwd);
export f
find 2006/. \( -name "*.CR2" -o -name "*.JPG" \) -execdir sh -c 'ln -s "$PWD"/$(basename {}) "$f"/2006_Links/Link_$(basename {})' {} \;

# 4  
Old 03-18-2014
f is a variable with scope limited to the current process. export f changes the scope to include all descendants of the current process.

The variable is visible to the "grandson": find ... -exec [child of a child]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Symbolic links

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

2. 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

3. Shell Programming and Scripting

How to change symbolic links via script

Hello, the install routine puts automatically the servername "SERVER" in the symlink like: hello.txt --> /SERVER/usr/lpp/hello.txt world.txt --> /SERVER/usr/lpp/world.txt ... but i need to change this symlinks (without servername) to: hello.txt --> /usr/lpp/hello.txt world.txt -->... (3 Replies)
Discussion started by: smitty11
3 Replies

4. UNIX for Dummies Questions & Answers

Permissioning for symbolic links

I've just started using UNIX in a Linux vmplayer. I'm trying to run the command: ln -s `pwd`/$1 `python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"`/$1 in a script from an online tutorial, but I keep getting an error message: ln: creating symbolic link... (1 Reply)
Discussion started by: ChipT
1 Replies

5. 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

6. Solaris

Will creating symbolic links affect users

Hi, I have a quick question with regards to creating symbolic links. Would creating a symbolic link from one directory to a file in another cause any issues for users that are currently logged into the box. I don't believe it will unless they are using the file in question, but I would like... (2 Replies)
Discussion started by: Chains
2 Replies

7. Shell Programming and Scripting

Symbolic Links - BASH Script

Hi all, This is my first message in this forum. I'd like to know if there is a nice way to get the complete path from a symbolic link. Example: When I do a ls -ltr I see this output. lrwxr-xr-x 1 mmmm users 66 Sep 4 09:58 LINK_SEND ->... (4 Replies)
Discussion started by: rodrimuino
4 Replies

8. Shell Programming and Scripting

ksh Script to Generate Symbolic Links

I'm writing a ksh script which will reference a text file I have to create symbolic links for my application: --file contents-- Link Directory Link Source Link Name /users/05/dwisconbug bin link2bin Now, this should create the following... (1 Reply)
Discussion started by: dwisconbug
1 Replies

9. 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

10. UNIX for Dummies Questions & Answers

Finding symbolic links

How can I find all symbolic links across the network to a directory (2 Replies)
Discussion started by: mehtad
2 Replies
Login or Register to Ask a Question