moving files and creating a link to it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting moving files and creating a link to it
# 1  
Old 10-23-2009
moving files and creating a link to it

Hi All,

I am in a tricky situation where I have to move my files to a different mount point and create a link in place of the file which will point to the moved location.

to explain you in details:-

say I have two mount points

/dir/mount1/
/dir/mount2/

I have my application files in /dir/mount1/application/

in /dir/mount1/application/ i have directories like

/dir/mount1/application/month
/dir/mount1/application/month/day
/dir/mount1/application/month/day/hour
/dir/mount1/application/month/day/hour/min1/a.txt
/dir/mount1/application/month/day/hour/min1/b.txt
/dir/mount1/application/month/day/hour/min1/c.txt

and

/dir/mount1/application/month/day/hour/min2/d.txt
/dir/mount1/application/month/day/hour/min2/e.txt

like wise....these files will be created in day-hour-min format directories...
now I need to move these .txt files to
/dir/mount2/application/ directory which will have exact directory structure which mount point 1 has.

and in place of original files in mount1 I will create softlinks which will be linked to the shifted files respectively....


any idea will be appreciated.... Smilie

---------- Post updated 10-24-09 at 12:39 AM ---------- Previous update was 10-23-09 at 11:18 PM ----------

any luck with any one?
# 2  
Old 10-23-2009
Hi.

As a starting point:

Code:
cd /dir/mount1
tar cf - application | (cd ../mount2; tar xf -)
find application -type f | while read FILE; do
   rm "$FILE"
   ln -s ../mount2/"$FILE" "$FILE"
done

# 3  
Old 10-24-2009
Thanks Scott for suggestion...I had to discard the tar methos as if I do tar for the first time I will get all the files in my back up location but.....as on my files gets loaded in primary directory I have to move those files also...then how do I move the differential tar to back up location and create link?
# 4  
Old 10-24-2009
Try this...


Code:
mount1="/dir/mount1"
mount2="/dir/mount2"

cd $mount1

f_list=`find application -type f`

tar cf - $f_list | (cd $mount2; tar xf -)

for i in $f_list ; do
  rm $i
  ln -s $mount2/$i $i
done

# 5  
Old 10-24-2009
thanks for suggestion but req is diff here...I have to move the files daily through a cron script.....your suggestion will work if I do once....

but If i do daily then I have to copy the files(and not the links which are created already)...so If I do tar and move the files in my new location I will get error as directory already exist....Smilie

I am working on a shell script whcih will create the exact directory structire in the new location, move the files and create a link to it....


by the time any new suggestions are appreciated....Smilie
# 6  
Old 10-24-2009
The script will only move files that are not links already. The tar pipe is a convenient way to move the files without having to create logic to make paths and directories that may not exits. What the script does:
  1. Create variables for directories
  2. create a list of regular files. Note sym links will not be in the list.
  3. Use a tar pipe to transfer the files and directory structure to the destination directory. Only files that have not already been processed are moved.
  4. remove the source files and create sym links in the source directory to the target directory

For the first run, every file will be moved and linked. For any subsequent runs, only files that are not sym links (i.e. new additions) will be moved.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Moving the target of a symbolic link

Hello all, On a Solaris box, I am trying to move the target of a symbolic link. Let's say the symbolic link looks like the following: /dir1/dir2/link -> /some/dir/target I would like to know of a simple way to move the target of the symbolic link and not the link itself. I'd like to move... (4 Replies)
Discussion started by: ejianu
4 Replies

2. Shell Programming and Scripting

Archiving and moving files into directories, creating directories, etc.

how can i move "dataName".sql.gz into a folder called 'database' and then move "$fileName".tar.gz * .htaccess into a folder called 'www' with the entire gzipped file being "$fileName".tar.gz? Is this doable or overly complex. so mydemo--2015-03-23-1500.tar.gz > database -... (5 Replies)
Discussion started by: wyclef
5 Replies

3. Shell Programming and Scripting

Creating hard link with name

How can I create a hard link to a file, then rename the hard link to a different name? (2 Replies)
Discussion started by: fhill2
2 Replies

4. UNIX for Dummies Questions & Answers

Odd while Creating Symbolic Link

Hi, # mkdir usr3 # ls -l /h/uxossolbld10/0/teamcity/agent total 8 drwxrwxr-x 14 test1 rdl 512 Nov 30 02:54 conf drwxrwxr-x 3 test1 rdl 512 Jun 24 14:21 scripts drwxrwxr-x 10 test1 rdl 512 Jun 3 2011 teamcity drwxrwxr-x 4 test1 ... (1 Reply)
Discussion started by: Divakar
1 Replies

5. Solaris

creating link for a file of remote server

Hi, I use to access a file on remote server. Can I create a link for this file present on remote server on my local server, if yes then please let me know. Thanx in advance. (7 Replies)
Discussion started by: sanjay1979
7 Replies

6. Shell Programming and Scripting

Creating date directory and moving files into that directory

I have list of files named file_username_051208_025233.log. Here 051208 is the date and 025233 is the time.I have to run thousands of files daily.I want to put all the files depending on the date of running into a date directory.Suppose if we run files today they should put into 05:Dec:08... (3 Replies)
Discussion started by: ravi030
3 Replies

7. Shell Programming and Scripting

Bash and Awk for creating directories and moving files

I have a security system that FTPs the camera files to my machine, however I want to sort the pictures (taken every 30s) into directories by hour. Every picture uses the following file format. yymmddhhmmsstt.jpg (where tt is the milliseconds) I am thinking the for loop is best for file... (11 Replies)
Discussion started by: Kiint
11 Replies

8. UNIX for Dummies Questions & Answers

creating link to new vim

Hi, I have installed vim 7 but I'm unsure how to point the 'vim' command to the new vim version rather than version 6. Thanks in advance. Michael (2 Replies)
Discussion started by: c19h28O2
2 Replies

9. Shell Programming and Scripting

Creating symbolic link

Any idea how to create a symbolic link...for example i want to create a symbolink link for a specific user in his profile to use the df command...? Thanks in advance (9 Replies)
Discussion started by: charbel
9 Replies

10. UNIX for Dummies Questions & Answers

Creating a link

Hi All, Suppose i have a directory called /home/rooh and I have an executable that writes to this directory. the size of /home/rooh/logs is quite small and thus blows out of space. I don't want to modify the executable but I want to create a link so that all the logs are moved there . ... (1 Reply)
Discussion started by: rooh
1 Replies
Login or Register to Ask a Question