LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-28-2011, 06:11 AM   #1
Chipper
LQ Newbie
 
Registered: Feb 2011
Posts: 11

Rep: Reputation: 0
Question bash (ksh, etc) - mkdir problem


hi, this is my first post on this forum.

I have a problem with creating folders with parametr -p.
I have script like: mkdir -p /dir1/dir2/dir3/dir4, but if for example /dir1/dir2 is a file, then mkdir is stoped. Do you have any idea, how to rewrite file dir2 to directory?

Thank you
 
Old 02-28-2011, 06:34 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Hi and welcome to LinuxQuestions!

Not sure about the problem, but if /dir1/dir2 is a file, the mkdir command should have aborted and the file should be still there. At this point you can simply rename it, since there is no way to have a file and a directory with the same name in the same place. Otherwise, please clarify your issue.
 
Old 02-28-2011, 07:00 AM   #3
Chipper
LQ Newbie
 
Registered: Feb 2011
Posts: 11

Original Poster
Rep: Reputation: 0
hi, thank you for your response,
my script extracts 2 archives, to 2 separate directories. Then I have function which use diff to compare all files in both directories and then, if there is a difference, save the patch file to third folder. for example:

1. archive has dir structure:
main.c
main.h
folder/hello.c
folder/etc.c
README

2. archive has dir structure
main.c
main.h
folder/hello.c
folder/etc.c
README/README
README/License

lets say, main.c file is different in both archives. The created 3rd archiv will look like:

main.c.patch
README/README.patch
README/Licence.patch

But my script first see, thah in second archive is not file README, so script create README.patch, but then script see, in first archive is not folder README so script is trying to create dir, but there is a file. Im creating dir by mkdir -p because, I can create more dirs at 1 time. (example: README/DIR/FOO/)

Last edited by Chipper; 02-28-2011 at 07:01 AM. Reason: missing word
 
Old 02-28-2011, 11:15 AM   #4
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Rep: Reputation: 59
Quote:
Originally Posted by Chipper View Post
hi, thank you for your response,
my script extracts 2 archives, to 2 separate directories. Then I have function which use diff to compare all files in both directories and then, if there is a difference, save the patch file to third folder. for example:

1. archive has dir structure:
main.c
main.h
folder/hello.c
folder/etc.c
README

2. archive has dir structure
main.c
main.h
folder/hello.c
folder/etc.c
README/README
README/License

Well, README in the first archive is a file whereas in the second archive there is a directory with the same name and it contains one or more files and directories.

The problem is that at the top level README can only be either a file or a directory when you get the 3rd archive.

Your mkdir -p formula is fine. But it failes because it conflicts when it finds a file already present with the same name as that of your directory, i.e. README. If README were a directory and not a file, then mkdir -p would not create it again and will not fail as well.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mkdir in bash script - command substitution casperdaghost Linux - Newbie 3 06-26-2010 05:10 AM
Bash vs ksh Nickbrandson Linux - Newbie 7 04-23-2008 06:40 PM
How to switch from BASH to KSH? tejpatil Linux - Software 13 06-14-2007 02:03 PM
bash or ksh noir911 *BSD 5 05-10-2007 11:08 AM
bash more bloated than ksh? noir911 Linux - General 4 10-10-2006 04:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration