Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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:
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.