Link multiple files from different subfolder to a new subfolder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Link multiple files from different subfolder to a new subfolder
# 1  
Old 07-15-2011
How to link multiple files from different subfolder to a new subfolder

Hi,

I have the following subfolder with files:
Code:
/data/a/1/xxx.txt
/data/b/2/yyy.txt
/data/c/3/zzz.txt

And i have a set of new folders which have exactly the same structure as above but different disk without the files:
Code:
/data_02/a/1/
/data_02/b/2/
/data_02/c/3/

Now i would like to have a command that i can do a soft link (ln -s) for all files to the respective directory like below:

Code:
/data_02/a/1/xxx.txt -> /data/a/1/xxx.txt
/data_02/b/2/yyy.txt ->/data/b/2/yyy.txt
/data_02/c/3/zzz.txt ->/data/c/3/zzz.txt

Please advice.

Last edited by Franklin52; 07-15-2011 at 03:32 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 07-15-2011
Code:
for i in `find /data/ -type f -name "*.txt"`
do
  #remove parent directory
  subDirPath=nawk -F"/" '{for(i=1;i<=NF;i++)printf("%s/",$i)}'
  echo $subDirPath
  #check the command before create link
  echo "ln -s $i /data_02/$subDirPath"
  #ln -s $i /data_02/$subDirPath
done

# 3  
Old 07-15-2011
Code:
[mute@geek ~/links]$ find . -type f | { while read F; do echo ln -s /data/${F#./} /data_02/${F#./}; done }
ln -s /data/b/2/yyy.txt /data_02/b/2/yyy.txt
ln -s /data/a/1/xxx.txt /data_02/a/1/xxx.txt
ln -s /data/c/3/zzz.txt /data_02/c/3/zzz.txt

# 4  
Old 07-15-2011
I try to use your command but i got error.
Code:
[j0345619@x-kul-012 PROFILS]$ find . -type f | { while read F; do echo ln -s /data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/${F#./} /data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS/${F#./}; done }
Missing }.
[j0345619@x-kul-012 PROFILS]$

Please advice

---------- Post updated at 12:04 PM ---------- Previous update was at 11:57 AM ----------


Hi Raj,

Thanks for your reply. But i got the error when running your script.
Code:
ln -s /data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-252/SEISMIC/CE93                                                                                                -252.Mig_4ms.xt /data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS/
./link_files: line 4: -F/: No such file or directory

Code:
ln -s /data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-248/SEISMIC/CE93                                                                                                -248.Mig_4ms.xt /data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS/
./link_files: line 4: -F/: No such file or directory

ln -s /data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-248/SEISMIC/CE93                                                                                                -248.Mig_2ms.xt /data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS/
./link_files: line 4: -F/: No such file or directory

ln -s /data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-266/SEISMIC/CE93                                                                                                -266.Mig_4ms.xt /data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS/
./link_files: line 4: -F/: No such file or directory

ln -s /data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-263/SEISMIC/CE93                                                                                                -263.Mig_4ms.xt /data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS/
./link_files: line 4: -F/: No such file or directory

ln -s /data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-263/SEISMIC/CE93                                                                                                -263.Mig_2ms.xt /data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS/


The real directory structure is like below:
Code:
/data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-240/SEISMIC/CE93-240.Mig_4ms.xt

/data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-243/SEISMIC/CE93-243.Mig_2ms.xt

I want to link all the .xt files to :
Code:
/data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS/CE93-240/SEISMIC

/data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS/CE93-243/SEISMIC

Please advice

Last edited by Franklin52; 07-15-2011 at 03:34 AM.. Reason: Please use code tags for code and data samples, thank you
# 5  
Old 07-15-2011
ok, just execute the below command and show some result.

Code:
 
find /data_drobo/ -type f -name "*.txt"

---------- Post updated at 02:53 PM ---------- Previous update was at 02:47 PM ----------

execute this.. and let me know.. not tested
Code:
 
for i in `find /data_drobo/ -type f -name "*.txt"`
do
  #remove parent directory
  subDirPath=`echo $i | nawk -F"\/" '{for(i=1;i<=NF;i++)printf("%s/",$i)}'`
  echo $subDirPath
  #check the command before create link
  echo "ln -s $i /data/archive_data02/$subDirPath"
  #ln -s $i /data_02/$subDirPath
done

# 6  
Old 07-17-2011
How to link multiple files from different subfolder to a new subfolder

Hi Kamaraj,

I have edited a bit of your script base on the directory. Firstly i got the message "nawk: command not found", so i change teh script to awk.But i still run without success.

Below is the script that i run:

Code:
for i in `find /data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/ -type f -name "*.txt"`
do
  #remove parent directory
  subDirPath=`echo $i | awk -F"\/" '{for(i=1;i<=NF;i++)printf("%s/",$i)}'`
  echo $subDirPath
  #check the command before create link
  echo "ln -s $i /data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS/$subDirPath"
  #ln -s $i /data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS/$subDirPath
done

And below is the error that i got when running the script above:

Code:
awk: warning: escape sequence `\/' treated as plain `/'
/data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-246A/SEISMIC/CE93-246A.Mig_2ms.xt/
ln -s /data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-246A/SEISMIC/CE93-246A.Mig_2ms.xt /data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS//data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-246A/SEISMIC/CE93-246A.Mig_2ms.xt/
awk: warning: escape sequence `\/' treated as plain `/'
/data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-246A/SEISMIC/CE93-246A.Mig_4ms.xt/
ln -s /data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-246A/SEISMIC/CE93-246A.Mig_4ms.xt /data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS//data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-246A/SEISMIC/CE93-246A.Mig_4ms.xt/
awk: warning: escape sequence `\/' treated as plain `/'
/data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-260/SEISMIC/CE93-260.Mig_4ms.xt/
ln -s /data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-260/SEISMIC/CE93-260.Mig_4ms.xt /data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS//data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-260/SEISMIC/CE93-260.Mig_4ms.xt/
awk: warning: escape sequence `\/' treated as plain `/'
/data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-250/SEISMIC/CE93-250.Mig_4ms.xt/
ln -s /data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-250/SEISMIC/CE93-250.Mig_4ms.xt /data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS//data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-250/SEISMIC/CE93-250.Mig_4ms.xt/
awk: warning: escape sequence `\/' treated as plain `/'
/data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-250/SEISMIC/CE93-250.Mig_2ms.xt/
ln -s /data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-250/SEISMIC/CE93-250.Mig_2ms.xt /data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS//data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-250/SEISMIC/CE93-250.Mig_2ms.xt/
awk: warning: escape sequence `\/' treated as plain `/'
/data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-262/SEISMIC/CE93-262.Mig_4ms.xt/
ln -s /data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-262/SEISMIC/CE93-262.Mig_4ms.xt /data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS//data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-262/SEISMIC/CE93-262.Mig_4ms.xt/
awk: warning: escape sequence `\/' treated as plain `/'
/data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-262/SEISMIC/CE93-262.Mig_2ms.xt/
ln -s /data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-262/SEISMIC/CE93-262.Mig_2ms.xt /data/archive_data02/MALAY_BASIN_INTERP/DATA/2D/CE93/PROFILS//data_drobo/MY_MALAY_BASIN_2011/DATA/2D/CE93/PROFILS/CE93-262/SEISMIC/CE93-262.Mig_2ms.xt/
awk: warning: escape sequence `\/' treated as plain `/'

Please advice.

Last edited by total_ysf; 07-17-2011 at 09:48 PM..
# 7  
Old 07-19-2011
Kamaraj,

Could you please help me on this problem....

Please advice.

Thanks,
Siew Fong
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to copy subfolder and files to matching directory

The bash executes but returns no results and the set -xv showed while the $run variable in blue, was extracted correctly, the $match value in green, was not, rather both values in home/cmccabe/Desktop/f1 were extracted not just the matching. There will always be an exact match from the $run to... (7 Replies)
Discussion started by: cmccabe
7 Replies

2. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

3. Shell Programming and Scripting

Bash - Find files excluding file patterns and subfolder patterns

Hello. For a given folder, I want to select any files find $PATH1 -f \( -name "*" but omit any files like pattern name ! -iname "*.jpg" ! -iname "*.xsession*" ..... \) and also omit any subfolder like pattern name -type d \( -name "/etc/gconf/gconf.*" -o -name "*cache*" -o -name "*Cache*" -o... (2 Replies)
Discussion started by: jcdole
2 Replies

4. Shell Programming and Scripting

List of files in a folder inclusive subfolder

Hi, I need to list the names of existing files in a specific folder. I have written a script for that, but the problem is, it is also picking up name of a subfolder that is there in that folder. I need only the list of files and not that subfolder. How to go about that ? Can anyone plz help... (2 Replies)
Discussion started by: Subhasis
2 Replies

5. UNIX for Dummies Questions & Answers

removing files in a given subfolder

Hello, im new to this forum and directly start with a problem... :) I have a folder structure like : /folder/01/1/oldfiles /folder/01/2/oldfiles /folder/02/1/oldfiles /folder/0x/y/oldfiles Every Month a new folder adds automaticly from the system. Now i need an idea how to search... (6 Replies)
Discussion started by: Hugi
6 Replies

6. Shell Programming and Scripting

Create subfolder within folder in one command

suppose if i am checking folder g as shown below path a/b/c/d/e/f/g ,and some directory c,d,e,f,g not present then is there anyway to create directory in one command or i need to use mkdir for everyfolder (3 Replies)
Discussion started by: lalitpct
3 Replies

7. UNIX for Dummies Questions & Answers

Unzip subfolder to some path.

I have a zip file (somezipfile.zip) with the following contents in it: dir1/subdir1/somefile1.txt dir1/subdir2/somefile2.txt dir1/subdir2/somefile3.txt dir1/somefile3.txt dir1/somefile4.txt dir2/somefile5.txt dir2/somefile6.txt Lets say I unzip this to my home directory so now I have: ... (0 Replies)
Discussion started by: mrwatkin
0 Replies

8. UNIX for Dummies Questions & Answers

How to Get the count fo files in each subfolder

Hi is there a command to get the count of files inside each sub directory in a directory. example: in a directory like this /opt/:> ls subdir1 subdir2 subdir3 I need to see the count of files in sub directories like this: /opt/subdir1: 3 files /opt/subdir2: 5 files /opt/subdir3: 10... (1 Reply)
Discussion started by: sanjangr
1 Replies

9. UNIX and Linux Applications

Samba read only subfolder.

Hi, I need to make a folder read only under a fileshare that has full permissions granted to it. The fileshare with full permissions is /u02/prodfileshare. The folder I need to make read only for everyone except the owner of the folder is called /u02/prodfileshare/EFT/purchases. ... (0 Replies)
Discussion started by: sparcman
0 Replies

10. Solaris

Samba: share subfolder as read only.

Hi, Currently I have a Samba shared configured as follows: comment = Public fileshare path = /u02/pub guest ok = Yes writeable = Yes There is a subfolder under /u02/pub called /u02/pub/expenses/hardware that I need to make read only. How do I do this? I am new to using Samba. ... (2 Replies)
Discussion started by: sparcman
2 Replies
Login or Register to Ask a Question