The command to create directory in Ubuntu is mkdir. Here are the mkdir command information and synopsis.
mkdir - make directories.
Synopsis:
mkdir [OPTION] DIRECTORY...
Example of mkdir command used with some important options:
Example 1 - Ubuntu create directory using mkdir with no option.
luzar@ubuntu:~$ ls
file.txt
luzar@ubuntu:~$ mkdir folder
luzar@ubuntu:~$ ls
file.txt folder
luzar@ubuntu:~$
The mkdir command with no option creates a directory.
Example 2 - Ubuntu create multiple directories using mkdir with no option.
luzar@ubuntu:~$ mkdir new_folder myfolder mycats myjeans
luzar@ubuntu:~$ ls
file.txt folder mycats myfolder myjeans new_folder
luzar@ubuntu:~$
Use mkdir to creates multiple directory at once. Use mkdir command with no option and multiple directory's names separated by a space.
Example 3 - Ubuntu create directory in other directory using mkdir.
luzar@ubuntu:~$ mkdir folder/mydir
luzar@ubuntu:~$ ls -R
.:
file.txt folder mycats myfolder myjeans new_folder
./folder:
mydir
./folder/mydir:
./mycats:
./myfolder:
./myjeans:
./new_folder:
luzar@ubuntu:~$
To create a directory in another directory, you don't have to change into that directory. Just provide the path like in the example above.
Example 4 - Ubuntu create directory in other directory using mkdir - m option.
luzar@ubuntu:~$ ls
file.txt folder mycats myfolder myjeans new_folder
luzar@ubuntu:~$ mkdir -m 0022 myfolder/umaskdir
luzar@ubuntu:~$ ls -l myfolder/umaskdir/
ls: cannot open directory myfolder/umaskdir/: Permission denied
luzar@ubuntu:~$ ls -l myfolder/
total 4
d----w--w- 2 luzar luzar 4096 2008-10-22 05:02 umaskdir
luzar@ubuntu:~$
In this example, I created a new directory named umaskdir in myfolder directory. This time I added -m option to mkdir and a umask permission to apply to the new directory. Then, I tried to view umaskdir content with ls -l myfolder/umaskdir command. I got a permission denied warning. That means I don't have access permission to the directory I created myself. So I viewed myfolder directory content to see details about umaskdir directory permission. That's what -m option do, apply permission to the new directory using umask.
No comments:
Post a Comment
Please keep comment relevant and strictly no spam will be tolerated. Thank you.