create directoryCreate Directory on Linux

By: - Last Updated:

Directory on linux based operating system basically can be created, renamed, moved, modified, grown, shrunk, and deleted. In most cases, software programs that are executed on the computer handle these operations, but the user of a computer can also manipulate folder if necessary.

For instance, A new directory or folder are normally created and modified by the Microsoft program in response to user commands, but the user can also move, rename, or delete these folders directly by using a file manager program such as Windows Explorer (on Windows computers) while on linux by command lines (CLI) via terminal.

How To Create Directory on Linux?

You can easily create directory on linux with the following methods New Directory, Multiple Directories, Set Directory Permissions, and More Information via terminal on your system with the command line.

Directory

To create a new directory on linux:

  1. Open “Terminal” on linux system
  2. Keep on the current working directory or go to the specific directory (use “cd” to change directory) that you want to create a new directory inside it
  3. Use “mkdir” command and specify output-directory-name
  4. The syntax for using the “mkdir” command as shown below
    mkdir [option] [directory-name]
    • Create a “new directory” in the current directory.
      mkdir docs
    • verify created directory listing using the “ls” command.
      ls -l
      drwxrwxr-x 2 username username 4096 May  3 22:16 docs
  5. Done, now you have a new directory

Multiple Directories

To create multiple directories on linux:

  1. Open “Terminal” on linux system
  2. Keep on the current working directory or go to the specific directory (use “cd” to change directory) that you want to create a new directory inside it
  3. Use “mkdir” command and specify output-directory-name
  4. The syntax for using the “mkdir” command as shown below
    mkdir [option] [dir1-name] [dir2-name] [dir3-name]
    • create “multiple directories”. You need to specify all directories names separated by space.
      mkdir docs1 docs2 docs3
    • verify created directories listing using the “ls” command.
      ls -l
      drwxrwxr-x 2 username username 4096 May  3 22:26 docs1
      drwxrwxr-x 2 username username 4096 May  3 22:26 docs2
      drwxrwxr-x 2 username username 4096 May  3 22:26 docs3
  5. Done, now you have new multiple directories

Set Directory Permissions

To create a new directory and set the permissions on linux:

  1. Open “Terminal” on linux system
  2. The newly directory by default created with the read, write and execute permissions
  3. Use “mkdir” command with -m (-mode) option and directory-name
  4. The syntax command as shown below
    mkdir -m [permissions] [directory-name]
    • set directory permissions on a specific directory.
      mkdir -m 777 docs
    • verify created directories listing the contents using the “ls” command.
      ls -l
      drwxrwxrwx 2 username username 4096 May  3 22:51 doc
  5. Done

Variables:

  • drwxrwxr-x is The file mode
  • 2 is Number of links
  • username is The owner name (first)
  • username is The group name (next)
  • 4096 is The number of bytes in the file
  • May 3 22:51 is The date when the file was last modified
  • doc is the directory name

More Information

“mkdir” command can be obtained from the “mkdir man page”.

mkdir --help

Usage: mkdir [OPTION]… DIRECTORY…
Create the DIRECTORY(ies), if they do not already exist.

Mandatory arguments to long options are mandatory for short options too.
-m, –mode=MODE set file mode (as in chmod), not a=rwx – umask
-p, –parents no error if existing, make parent directories as needed
-v, –verbose print a message for each created directory
-Z set SELinux security context of each created directory
to the default type
–context[=CTX] like -Z, or if CTX is specified then set the SELinux
or SMACK security context to CTX
–help display this help and exit
–version output version information and exit

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation at: <https://www.gnu.org/software/coreutils/mkdir>
or available locally via: info ‘(coreutils) mkdir invocation’

create directory
image: create directory on linux

In general, a directory can contain either a list of files or a list of links to files. Within this definition, it is of paramount importance that the term “file” includes “directories”. This permits the existence of directory hierarchies, i.e., directories containing sub-directories.

A name that refers to a file within a directory must be typically unique. In other words, there must be no identical names within a directory. However, in some operating systems, a name may include a specification of type that means a directory can contain an identical name for more than one type of object such as a directory and a file.

Leave a Reply

Your email address will not be published. Required fields are marked *