moving dir subdir and files

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting moving dir subdir and files
# 1  
Old 10-08-2009
moving dir subdir and files

I have created a directory structure and under the directory subdirectories and files are there.I need to move the entire thing
to another path.How can i write a script to do that.

currently the path of files is as below :
/data1/serial/mcycle/archive : under this path differnt sub dir exist

i want to move everything to /data2/mycle
# 2  
Old 10-08-2009
Why write a script? Why not just issue a mv on it/them?

Also please generally use [code] and [/code] tags when posting data, code, logs etc. ty.
# 3  
Old 10-08-2009
Originally Posted by zaxxon
Why write a script? Why not just issue a mv on it/them?

Also please generally use [code] and [/code] tags when posting data, code, logs etc. ty.

can we do this in a single piece of command...i want all the directories...its subdirectories and the files in that to be copied
# 4  
Old 10-08-2009
I don't know your directory structure but you can surely just move directory by directory or use wildcards. Everything based below them will be moved together with them. If you are not familiar with the mv command you should test it out creating example structures with copying something you have already or using mkdir and touch.
# 5  
Old 10-08-2009
This should do what you required, "move all the files and subdirectories under archive to destination mycle".

mv /data1/serial/mcycle/archive /data2/mycle

Or you were expecting some thing else ?
# 6  
Old 10-08-2009
let me explain the exact requirement...

source : /data1/serial/mcycle/archive : under archive there are many directories and sub directories...but unfortunately archive dir is created in one user(say X) and rest are under other user(say Y).

Now we need to change the owner of archive to Y as X id will be removed.So i was thinking of taking a backup and moving files again...

Please suggest ..
# 7  
Old 10-08-2009
Backup is not moving more copying. You can use something like that to create an exact copy:

cd /source
find .| cpio -dumpv /destination

No offense but commands like mv, cp etc. are everyday commands of a Unix admin. I recommend strongly that you get somewhat familiar with those by playing around with them on a test box and reading some manuals.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How do I create a tar file for only dir and its subdir structures??

How do I create a tar file for only dir and its subdir structures?? (4 Replies)
Discussion started by: vx04
4 Replies

2. UNIX for Dummies Questions & Answers

copying the dir/subdir structure from one server to another?

Hi All, I want to copy the dir/subdir structure from SERVER-A to SERVER-B without copying all the files in each dir. Is it possible using SCP / SFTP command? For example, SERVER-A has following two dir/subdirectories and files under each subdir. ... (1 Reply)
Discussion started by: Hangman2
1 Replies

3. Shell Programming and Scripting

Move all files from dir and subdir to Archive with File name as complete path_filename

HI, I need to move all files from a dir & its all subdir to Archive folder which is indise dir only. and moved filename should changed to complete path ( Like Dir_subdir_subdir2_.._filename ). also all files names shoud capture in a file in order to mail I written below code ... (11 Replies)
Discussion started by: minijain7
11 Replies

4. Shell Programming and Scripting

Copy files from subdir

Hey, How can I copy files from subdirectories without copy the subdir and copy it to a higher dir For example: /home/test/subdir/file1 copy file1 to /home or another dir thanx (11 Replies)
Discussion started by: Eclecticaa
11 Replies

5. Shell Programming and Scripting

Problem with moving a file to another dir.

Hi frnds The following is the code #!/bin/ksh ############################################################## # # # Created by eDB Dev - 27-May-2011 # # ... (1 Reply)
Discussion started by: balesh
1 Replies

6. Shell Programming and Scripting

moving files from a dir in one machine to a dir in another machines

Hi, I am a unix newbie.I need to write a shell script to move my oracle READ WRITE datafiles from one serevr to another. I need to move it from /u01/oradata/W1KK/.. to /u01/oradata/W2KK, /u02/oradata/W1KK/.. to /u02/oradata/W2KK. That is, I actaully am moving my datafiles from one database to... (2 Replies)
Discussion started by: mathews
2 Replies

7. Shell Programming and Scripting

Perform action in dir if dir has .git subdir

Hi, I want to run git status for the dir which has subdir ".git" in it with dir path mentioned in output log? If a dir does not have .git subdir then skip that dir. Dir will have 100 main dirs & 500 + subdirs and so on. I appreciate all your help :b: (4 Replies)
Discussion started by: dragon.1431
4 Replies

8. Shell Programming and Scripting

Moving file from one dir to Another with Given Qualifier

Hi, I want to Move files from one dir to another dir on same mount point. The source dir may contain subdir or files within it. Search the files or subfolder which is older then a given datetime . Move the file recursively and after each successful move of file make an entry to log... (2 Replies)
Discussion started by: rkmbcbs
2 Replies

9. Shell Programming and Scripting

replace string in multiple files, dir and subdir

Hello, I have a directory www with multiple directories. Every directory has site name with .htm, .html, .php files or sub directories with .htm, .php, .html file as example - www - sitename 1 - site 1 - sitename 2 - sitename 3 What I'm looking for is a... (7 Replies)
Discussion started by: andyjill
7 Replies

10. Shell Programming and Scripting

Moving file(s) from dir to dir

Hi, I am fairly new to writing scripts. I am trying to write a script that moves either One or All of the files from one directory to another. I know how to make the actual command to do it, but i don't quite know how to add operators to it, ie -i or -a. I want -i to move one file from... (4 Replies)
Discussion started by: SirJoeh
4 Replies
Login or Register to Ask a Question