linux overwrite directory


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users linux overwrite directory
# 1  
Old 01-22-2012
linux overwrite directory

How do you overwrite a directory with another directory? I know you can delete your directory then copy your directory over, but I would think there would be a way to do this in one step.
# 2  
Old 01-22-2012
Here is a way to do it in one step:
Code:
mount --bind olddir newdir

Note that the old content isn't lost, just hidden by the overlay mount.
# 3  
Old 01-23-2012
I think, that You're looking for:
Code:
mv -T /path/to/dir1 /path/to/dir2

with -T target directory is treated as file - so it will be overwritten.
# 4  
Old 01-23-2012
Code:
mv -T

will only work if dir2 is not empty.
# 5  
Old 01-23-2012
Actually it will work only if dir2 IS empty Smilie
But when there are some files in it, it simply won't work...
So for now, I don't have any solution better than:
Code:
rm -rf /path/to/dir2 && mv /path/to/dir1 /path/to/dir2

I think, that filesystem won't allow to do such thing with simple 'mv'.
Smilie
# 6  
Old 01-23-2012
Quote:
I think, that filesystem won't allow to do such thing with simple 'mv'.
True.
When source and destination are both directory names, the destination for "mv" is relative to the target directory. If the target directory does not exist "mv" will create it, otherwise "mv" will create the new directory under the target directory.
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Better to Delete or Overwrite

Hello All, I had just a question about my Bash Script I'm currently writing. The script I have writes some text to a output file. After I write to the output file I send the file to another server to do some stuff with it. After the file sends in the script, I don't need the output/txt... (4 Replies)
Discussion started by: mrm5102
4 Replies

2. UNIX for Dummies Questions & Answers

overwrite problem

my script is: awk '...mycode...' file1.txt > file2.txt and i want to overwrite file2.txt eachtime I run this script. but it says:File exists! :( I have tried awk '...mycode...' file1.txt >| file2.txt but it again says:Missing name for redirect! :confused::confused: what is this? (2 Replies)
Discussion started by: gc_sw
2 Replies

3. Shell Programming and Scripting

Files overwrite in awk

Hi guys, I checked the knowledge base before posting this question. is there any way by which you can ALWAYS ALLOW file overwrite in AWK?. i.e. an option similar to noclobber in Korn shell. I don't to check for files existence and remove them. (1 Reply)
Discussion started by: Moon Noon
1 Replies

4. UNIX for Dummies Questions & Answers

overwrite problem

Hi im using the following to copy a file to a directory, the user being prompted to overwrite if the file already exists in that directory, cp -i myfile /home/brief/bin2 but this reveals the path of the directory when being prompted to overwrite (below) cp: overwrite... (2 Replies)
Discussion started by: ali999
2 Replies

5. UNIX for Dummies Questions & Answers

Overwrite

if i want to pipe output to a file, say, cat abc.dat > abc.txt, how do i make it replace the existing file? (9 Replies)
Discussion started by: Duckman
9 Replies
Login or Register to Ask a Question