Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3453
  • Last Modified:

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
0
xewoox
Asked:
xewoox
  • 3
  • 3
  • 2
  • +8
15 Solutions
 
ozoCommented:
is /tmp protected?
does /tmp/abc exist
0
 
Heem14Commented:
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
 
Heem14Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
michofreihaCommented:
mkdir -p /tmp/abc/def should create abc and def directories into /tmp if both directories does not exist
0
 
omarfaridCommented:
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
 
Xyptilon2Commented:
-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
 
woolmilkporcCommented:
Just to make the picture complete - does
mkdir /tmp/abc
work?
0
 
TintinCommented:
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
 
SaranyakkaliCommented:
    -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
 
dfkeCommented:
My guess is that /tmp/abc is an existing file, therefore a directory cannot be made by mkdir -p.
0
 
Xyptilon2Commented:
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
 
TintinCommented:
AIX does not use ext2 filesystems.
0
 
colinvannCommented:
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
 
TintinCommented:
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
 
Xyptilon2Commented:
Well....we are all ignoring the most likely explanation

The version of "mkdir" that is being used does not support the -p parameter.
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 3
  • 3
  • 2
  • +8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now