Wednesday 5 October 2011

Make directories

% mkdir <directory name>:  used to create a new directory.
Example:
jp@ubuntu:~/demo$ mkdir dir1
jp@ubuntu:~/demo$ ls
dir1

% mkdir -p <dir name>: Creates all directories leading up to the given directory that do not exist previously.  No error if existing.
Example:
jp@ubuntu:~/demo$ pwd
/home/jp/demo
jp@ubuntu:~/demo$ ls
dir1
jp@ubuntu:~/demo$ mkdir -p dir2/sub1/sub2/
jp@ubuntu:~/demo$ ls
dir1  dir2
jp@ubuntu:~/demo$ ls -R
.:
dir1  dir2
./dir1:
./dir2:
sub1
./dir2/sub1:
sub2
./dir2/sub1/sub2:

% mkdir -v <dir name>:  Creates  directory and prints message for each created directory.
Example:
jp@ubuntu:~/demo$ ls
dir1  dir2
jp@ubuntu:~/demo$ mkdir -v dir3
mkdir: created directory `dir3'
jp@ubuntu:~/demo$ ls
dir1  dir2  dir3

% mkdir -m <dir name>: Creates directory and sets file mode(as in chmod).
Example:
jp@ubuntu:~/demo$ ls -l
total 12
drwxr-xr-x 2 jp jp 4096 2011-10-05 23:14 dir1
drwxr-xr-x 3 jp jp 4096 2011-10-05 23:21 dir2
drwxr-xr-x 2 jp jp 4096 2011-10-05 23:26 dir3
jp@ubuntu:~/demo$ mkdir -m 0007 dir4
jp@ubuntu:~/demo$ ls
dir1  dir2  dir3  dir4
jp@ubuntu:~/demo$ ls -l
total 16
drwxr-xr-x 2 jp jp 4096 2011-10-05 23:14 dir1
drwxr-xr-x 3 jp jp 4096 2011-10-05 23:21 dir2
drwxr-xr-x 2 jp jp 4096 2011-10-05 23:26 dir3
d------rwx 2 jp jp 4096 2011-10-05 23:29 dir4
jp@ubuntu:~/demo$ ls dir4
ls: cannot open directory dir4: Permission denied
Only others (has read, write and execute permission) can access the directory "dir4".  Owner and user cannot access it, since the chmod for them is set to zero.


No comments:

Post a Comment