LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   bash (ksh, etc) - mkdir problem (https://www.linuxquestions.org/questions/linux-general-1/bash-ksh-etc-mkdir-problem-865455/)

Chipper 02-28-2011 06:11 AM

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

colucix 02-28-2011 06:34 AM

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.

Chipper 02-28-2011 07:00 AM

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/)

devUnix 02-28-2011 11:15 AM

Quote:

Originally Posted by Chipper (Post 4273877)
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.


All times are GMT -5. The time now is 10:12 PM.