How to make a folder in Linux or Unix

I am a new Linux user. How do I make a folder in Linux or Unix system using the CLI?

You need to use the mkdir command to create new directories or folders in Linux or Unix-like operating systems. This page shows how to create a folder (also known as “directory”) in Linux or Unix systems.

How to make a folder in Linux

The procedure is as follows:

  1. Open the terminal application in Linux
  2. The mkdir command is is used to create new directories or folders.
  3. Say you need to create a folder name dir1 in Linux, type: mkdir dir1

Let us see examples and other usage in details. The syntax is:

mkdir folder
mkdir [option] folderName
mkdir directory

Now you know the syntax. Let us explore how to create new folders and directories on Linux or Unix-like system using the command line option.

How to create a new folder named foo in Unix

Open the Terminal app and type the following command:
mkdir foo
To see directory listing use the ls command:
ls -l

You can simultaneously create any number of folders/directories:
mkdir dir1 dir2 dir3 dir_4
Verify it:
ls -l

Fig.01: How to create Folders/Directories In Linux/Unix with the mkdir command

Let us try to understand the following line:
drwxr-xr-x 2 vivek vivek  4096 Aug  7 20:57 dir_4
  1. drwxr-xr-x – The file mode (see below for file mode).
  2. 2 – Number of links
  3. vivek – The owner name
  4. vivek – The group name
  5. 4096 – The number of bytes in the file
  6. Aug 7 20:57 – The date when the file was last modified
  7. dir_4 – File/dir name path

More on file mode

The entry type character describes (the first character drwxr-xr-x) the type of file, as follows:

  1. - : Regular file.
  2. b : Block special file.
  3. c : Character special file.
  4. d : Directory.
  5. l : Symbolic link.
  6. p : FIFO.
  7. s : Socket.
  8. w : Whiteout.

So basically d character in above entry tell us that it is a directory/folder. The next three fields are three characters ach: owner permissions, group permissions, and other permissions. Each field has three character positions:

	   1.	If r, the file is readable; if -, it is	not readable.
	   2.	If w, the file is writable; if -, it is	not writable.
	   3.	The first of the following that	applies:
		      S	    If in the owner permissions, the file is not exe-
			    cutable and	set-user-ID mode is set.  If in	the
			    group permissions, the file	is not executable and
			    set-group-ID mode is set.
		      s	    If in the owner permissions, the file is exe-
			    cutable and	set-user-ID mode is set.  If in	the
			    group permissions, the file	is executable and set-
			    group-ID mode is set.
		      x	    The	file is	executable or the directory is search-
		      -	    The	file is	neither	readable, writable, exe-
			    cutable, nor set-user-ID nor set-group-ID mode,
			    nor	sticky.	 (See below.)
		These next two apply only to the third character in the	last
		group (other permissions).
		      T	    The	sticky bit is set (mode	1000), but not execute
			    or search permission.  (See	chmod(1) or
		      t	    The	sticky bit is set (mode	1000), and is search-
			    able or executable.	 (See chmod(1) or sticky(7).)

How to create a new directory named bar

Open the Terminal app and type the following command but pass the -v option to get visual confirmation about your folder/directory name:
mkdir -v foo
Sample outputs:

mkdir: created directory 'foo'

How to make parent folder if needed

The syntax is:
mkdir -p dir1/dir2
mkdir -p parent/child
mkdir -p pictures/vacations
ls -l
ls -l pictures

How to make a folder/directory and set permissions on it

New directories are by default created with the read, write and execute permissions. Pass the -m option to directory to set the the permissions of new directories:
mkdir -m {permissions} {dirName}
mkdir -m 777 delta
ls -l

To create a directory named delta for which all three types of permissions were enabled for all users, the sequence 777 would be added after the -m as above. More information about mkdir can be obtained from the mkdir man page:
man mkdir
mkdir --help
Sample outputs:

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

To delete the directory, use the rmdir command/rm command. For example, delete a folder named dir1:
rmdir dir1
rm -rf dir2


This page explained how to make a folder in Linux. Please mkdir man page online here or type the following command:
man mkdir

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

Comments on this entry are closed.

Comments are closed. Still have questions? Post it on our forum