Sponsored Content
Homework and Emergencies Homework & Coursework Questions Creating directories within a directory? Post 302462140 by vbe on Wednesday 13th of October 2010 11:09:40 AM
Old 10-13-2010
From man pages:
Quote:
mkdir(1) mkdir(1)

NAME
mkdir - make a directory

SYNOPSIS
mkdir [-p] [-m mode] dirname ...

DESCRIPTION
mkdir creates specified directories in mode 0777 (possibly altered by
umask unless specified otherwise by a -m mode option (see umask(1)).
Standard entries, . (for the directory itself) and .. (for its parent)
are created automatically. If dirname already exists, mkdir exits
with a diagnostic message, and the directory is not changed.

Options
mkdir recognizes the following command-line options:

-m mode After creating the directory as specified, the file
permissions are set to mode, which is a symbolic mode
string as defined for chmod (see chmod(1)). The
umask(1) has precedence over -m.

-p Intermediate directories are created as necessary.
Otherwise, the full path prefix of dirname must
already exist. mkdir requires write permission in
the parent directory.

For each directory name in the pathname prefix of the
dirname argument that is not the name of an existing
directory, the specified directory is created using
the current umask setting, except that the equivalent
of chmod u+wx is done on each component to ensure
that mkdir can create lower directories regardless of
the setting of umask. Each directory name in the
pathname prefix of the dirname argument that matches
an existing directory is ignored without error. If
an intermediate path component exists, but has
permissions set to prevent writing or searching,
mkdir fails with an error message.

If the -m option is used, the directory specified by
dirname (excluding directories in the pathname
prefix) is created with the permissions specified by
mode.
etc...
To be able in ONE command, mkdir that is you will have no other choice but to give the 2 directories in argument and using -p option:
Code:
mkdir -p test/test1 test/test2

which will create you:
/test # the directory
/test/test1 # the 2 subdirectories...
/test/test2
demo:
Code:
ezra:/tmp/vbe $ mkdir -p test/test1 test/test2; ll -ld test/*
drwxrwxr-x   2 vbe        bin             96 Oct 13 17:05 test/test1
drwxrwxr-x   2 vbe        bin             96 Oct 13 17:05 test/test2
ezra:/tmp/vbe $ ll
total 0
drwxrwxr-x   4 vbe        bin             96 Oct 13 17:05 test

Good exercice: Read the man pages...
start by typing man man
This User Gave Thanks to vbe For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

creating directories

how do i create directories using command in my unix system, i could do with knowing how to do it with absolute pathnames and relative pathnames please (3 Replies)
Discussion started by: carlvernon
3 Replies

2. HP-UX

creating directories on the same box

I have two login accounts 'fup04a' and 'fup04c' on the same unix box after log in using 'fup04a' and if I try creating a directory 'new' drwxrwxr-x 2 fup04a fup04a 4096 Nov 14 14:06 new but if i try the same with fup04c drw-rw-r-x 2 fup04c fup04c 4096 Nov 14... (3 Replies)
Discussion started by: vivek_damodaran
3 Replies

3. Shell Programming and Scripting

Creating date directory and moving files into that directory

I have list of files named file_username_051208_025233.log. Here 051208 is the date and 025233 is the time.I have to run thousands of files daily.I want to put all the files depending on the date of running into a date directory.Suppose if we run files today they should put into 05:Dec:08... (3 Replies)
Discussion started by: ravi030
3 Replies

4. Shell Programming and Scripting

help needed with creating challenging bash script with creating directories

Hi, Can someone help me with creating a bash shell script. I need to create a script that gets a positive number n as an argument. The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
Discussion started by: I-1
7 Replies

5. Shell Programming and Scripting

Creating Directories

I have many pdf files with similar naming conventions as this one: AC41_AC85_86_AC128_129_MC171_173_SF_207_FMV.pdf. It is a pdf file containing evaluations for these locations: AC41, AC85, AC86, AC128, AC129, MC171, and MC173. I want to create a directory for every location and put the... (3 Replies)
Discussion started by: ndnkyd
3 Replies

6. UNIX for Dummies Questions & Answers

creating separate directories according to file extension and keeping file in different directory as

unix program to which a directory name will be passed as parameter. This directory will contain files with various extensions. This script will create directories with the names of the extention of the files and then put the files in the corresponding folder. All files which do not have any... (2 Replies)
Discussion started by: Deekay.p
2 Replies

7. Shell Programming and Scripting

need help with creating directories and variables

i'm trying to write a script that has 2 variables, and uses the 1st variable as a number and the 2nd a name to create directories. so if you typed in ./myscript 5 week, it would create 5 directories named week1 - week5. whenever i run this, i get an error message saying week5 already exists, so i... (3 Replies)
Discussion started by: layne2kim
3 Replies

8. Shell Programming and Scripting

How to list all the files, directories and sub-directories in the current path except one directory?

Can anyone come up with a unix command that lists all the files, directories and sub-directories in the current directory except a folder called log.? Thank you in advance. (7 Replies)
Discussion started by: Manjunath B
7 Replies

9. Shell Programming and Scripting

Archiving and moving files into directories, creating directories, etc.

how can i move "dataName".sql.gz into a folder called 'database' and then move "$fileName".tar.gz * .htaccess into a folder called 'www' with the entire gzipped file being "$fileName".tar.gz? Is this doable or overly complex. so mydemo--2015-03-23-1500.tar.gz > database -... (5 Replies)
Discussion started by: wyclef
5 Replies

10. Shell Programming and Scripting

Creating new directories

I want to create a new system of directory structure for example mkdir -p ./iv.sac/resu/hhz.d However, I think that `mkdir -p` overwrites the directories. I want to avoid that and am doing something as follows in my bash script echo -e "\nCreating directories:" ... (6 Replies)
Discussion started by: kristinu
6 Replies
All times are GMT -4. The time now is 03:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy