Using mkdir to create a directory where its immediate subdirectories are not exist

Hi,

In my shell script, i use mkdir to create a subdirectory but it keeps failing saying the immediate subdirectory does not exist.

I use

mkdir -p  /tmp/abc/def
I got:
mkdir: 0653-357 Cannot access directory /tmp/abc.
/tmp/abc: A parameter must be a directory

I tried -p -m 755 /tmp/abc/def
I got the same error

What did I do wrong?

Thank you
xewooxAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
is /tmp protected?
does /tmp/abc exist
0
 
Heem14Connect With a Mentor Commented:
typically that means you don't have permissions. /tmp/abc does not have to exist as the -p option is set. check make sure you have permissions to write in this tree
0
 
Heem14Connect With a Mentor Commented:
OR - if you are operating in tmp - another process is deleting your directory before you have the chance to create the subdirectory.

if possible try operating outside of /tmp

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
xewooxAuthor Commented:
No, /tmp/abc does not exist.

I run the mkdir inside /tmp

If I do

mkdir -p /tmp/abc/def
failed

mkdir abc
success

mkdir -p /tmp/abc/def
success

but I want to be able to create /tmp/abc/def without first creating the subdir abc
0
 
michofreihaConnect With a Mentor Commented:
mkdir -p /tmp/abc/def should create abc and def directories into /tmp if both directories does not exist
0
 
omarfaridConnect With a Mentor Commented:
If you run the same command from command line (mkdir -p /tmp/abc/def) without having /tmp/abc being created earlier, do you get the same error? did you try to do the same under a different dir other that /tmp?
0
 
Xyptilon2Connect With a Mentor Commented:
-p is short for --parents, does the long option work?

mkdir --parents /tmp/abc/def

Is /tmp a seperate partition or mounted as read-only? perhaps a symlink?
0
 
woolmilkporcConnect With a Mentor Commented:
Just to make the picture complete - does
mkdir /tmp/abc
work?
0
 
TintinConnect With a Mentor Commented:
Assuming you have AIX 5.1 or higher, you should have truss.  There is something, very, very strange happening on your system.

What is the output of

truss mkdir -p /tmp/abc/def
0
 
SaranyakkaliConnect With a Mentor Commented:
    -p              With  this  option,  mkdir  creates  dir  by
                     creating  all the non-existing parent direc-
                     tories first. The mode given to intermediate
                     directories  will  be the difference between
                     777 and the bits set in the file mode  crea-
                     tion  mask. The difference, however, must be
                     at least 300 (write and  execute  permission
                     for the user).

0
 
dfkeConnect With a Mentor Commented:
My guess is that /tmp/abc is an existing file, therefore a directory cannot be made by mkdir -p.
0
 
Xyptilon2Connect With a Mentor Commented:
Either that or it is a more exotic problem, such as extended ext2 file attributes that are set in a parent directory preventing access that won't be visible during a normal "ls" command, or perhaps file system corruption.

Do you have this problem also outside the /tmp folder ? does mkdir -p /home/a/b/c/d/e/f work ?

This will rule out a problem with the mkdir command itself
0
 
TintinConnect With a Mentor Commented:
AIX does not use ext2 filesystems.
0
 
colinvannConnect With a Mentor Commented:
Ok, lets rule out a few things...

SELinux: please run "setenforce 0"
are there any acl's on the /tmp: "getfacl /tmp"
you might want to check if the filesystem is mounted with acl support: "mount |grep acl"

please display this output here for further comment.
Colin
0
 
TintinConnect With a Mentor Commented:
Can posters please note that this issue is on an AIX system and *NOT* a Linux system, so all the Linux suggestions are not going to be valid.
0
 
Xyptilon2Connect With a Mentor Commented:
Well....we are all ignoring the most likely explanation

The version of "mkdir" that is being used does not support the -p parameter.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.