I'm trying to recursively create directories through ssh.
The directory /home/user/staging exists. But the user has no permission to read /home. mkdir doesn't know if /home/user exists and tries to create it.
mkdir -p /home/user/staging/first/second/third/fourth/
mkdir: cannot create directory ‘/home/user’: Permission denied
How to skip this directory and go on creating where user has permission?
I'm trying to do it with my own script,
rec()
{
dir=$1
if [[ ! -e $dir ]]; then
echo "creating $dir"
newdir=$(echo $dir | sed 's:/[^/]*$::')
rec $newdir
mkdir $dir
fi
}
Fore some reason this check fails if [[ ! -e $dir ]] and loop goes down past existing dirs and eventually doesn't create anything.
id
;ls -ld /home
user
doesn't have execute permission on/home
, then this is the expected behaviour. This answer about directory permissions might help you.