Copy a file by creating folder structure in destination as in Souce


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy a file by creating folder structure in destination as in Souce
# 1  
Old 03-31-2010
Copy a file by creating folder structure in destination as in Souce

Hello,

i am having a source directory which consist of multiple sub directories and my destination folder is a empty directory.

if try to copy a file source->test->1.txt from source to destination test2 using the commaind.
cp source/test/1.txt desti/

It will copy the 1.txt under desti directory.

but i need tocreating directory test folder under desti folder then copy the file to desti/test/ folder.

Please advice me how to do this.

thanks in advance.

~Saravana
# 2  
Old 03-31-2010
Is that the real scenario? or do you want to create the complete directory structure?


Code:
s_dir=/some/path/source/test
s_file=1.txt
t_dir=/some/path/dest/$(basename $s_dir)

mkdir -p $t_dir
cp $s_dir/$s_file $t_dir/

for the complete directory structure:

change:
Code:
t_dir=/some/path/dest/$(basename $s_dir)

to:
Code:
t_dir=/some/path/dest/dest/$s_dir

please test first.

Last edited by clx; 03-31-2010 at 10:25 AM..
This User Gave Thanks to clx For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sftp cannot see folder in destination server

I'm using sftp to connect from a Windows server (User ID is ssh1) to AIX server (User ID ftpeapsg) to access /sftp/ftphrssg/HRSSG/EAPSG in AIX server. User ftpeapsg is created on AIX server. Able to connect to AIX server fine without the need for password however not able to see the folder... (4 Replies)
Discussion started by: userguy
4 Replies

2. Shell Programming and Scripting

How to copy all structure folder create last day?

HI All, please help , i got same case . i want copy folder and directory create yesterday. for sample below : drwxr-xr-x 4 apps apps 33 Nov 23 04:00 xxxxxx@gmai.com drwxr-xr-x 4 apps apps 33 Nov 23 04:00 yyyyyyy@gmail.com drwxr-xr-x 4 apps apps 33 Nov 24 04:00... (2 Replies)
Discussion started by: fajar_3t3
2 Replies

3. Shell Programming and Scripting

Creating a ksh script to copy a folder

Hi Folks, I need help in creating a ksh script to copy a folder from one server to multiple other servers using ssh and sftp. The thing is the folder name changes daily. So is there a way we could specify the folder name during the execution of script.? I would appreciate a quicker help.... (3 Replies)
Discussion started by: lena07
3 Replies

4. UNIX for Dummies Questions & Answers

copy files grabbing destination folder from file name

Hi all... Below is what I am trying to do: 1. Having the following folder with the files... /source_folder/dodiddone.tar.gz /source_folder/gowentgone.tar.gz /source_folder/gowentgone.log 2. I need to copy and chown files with extension .tar.gz to another folder copy... (1 Reply)
Discussion started by: pedroz
1 Replies

5. UNIX for Dummies Questions & Answers

Copy the latest (last file) in given folder

#!/bin/bash for i in {1..1536..1} do #find /home/test/Desktop/up111/workplace/Malware/$i/logs for a in /home/test/Desktop/up111/workplace/Malware/$i/logs/* do #max=a for b in /home/test/Desktop/up111/workplace/Malware/$i/logs/* do ... (4 Replies)
Discussion started by: upvan111
4 Replies

6. Red Hat

Copy certain file types recursively while maintaining file structure on destination?

Hi guys, I have just been bothered by a fairly small issue for some time now. I am trying to search (using find -name) for some .jpg files recursively. This is a Redhat environment with bash. I get this job done though I need to copy ALL of them and put them in a separate folder BUT I also... (1 Reply)
Discussion started by: rockf1bull
1 Replies

7. Shell Programming and Scripting

Copy files from input file with dir structure

hi, I want to copy files from source directory based on input file (or output of previous command) and i want to have the SAME DIRECTORY STRUCTURE. Note that i will have other files and directories which i dont want to copy to destination. For example, dir source has following content:... (22 Replies)
Discussion started by: dragon.1431
22 Replies

8. Shell Programming and Scripting

Creating Report file with 'vlookup' kind of structure in shell

Hi, I have some files in the following structure. File_a.txt Field_1 Pass Field_2 Pass Field_3 Pass File_b.txt Field_1 Pass Field_2 Fail Field_3 Pass File_c.txt Field_1 Fail Field_2 Pass Field_3 Pass (2 Replies)
Discussion started by: vikaskm
2 Replies

9. Shell Programming and Scripting

Copy only folder structure ?

Hello, I am not sure how feasible is it, but trying to copy/create the folders from one box to another. I dont want to copy the content of folder otherwise it'd be too much of data.. The folder structure is quite complex (in deep hierarchy) and its a big effort manually .. Please... (5 Replies)
Discussion started by: navsha
5 Replies

10. Shell Programming and Scripting

File Management: How do I move all JPGS in a folder structure to a single folder?

This is the file structure: DESKTOP/Root of Photo Folders/Folder1qweqwasdfsd/*jpg DESKTOP/Root of Photo Folders/Folder2asdasdasd/*jpg DESKTOP/Root of Photo Folders/Folder3asdadfhgasdf/*jpg DESKTOP/Root of Photo Folders/Folder4qwetwdfsdfg/*jpg DESKTOP/Root of Photo... (4 Replies)
Discussion started by: guptaxpn
4 Replies
Login or Register to Ask a Question