How to Create New Directory in Linux

directory

In Linux, dir is a command used to list the contents of a directory. However, it’s not as commonly used as ls, which is the more prevalent command to list directory contents.

In the context of a Linux hosting company or web hosting environment, dir refers to the command used within the command-line interface (CLI) or terminal to list the contents of directories. It serves the same purpose as in a standard Linux system, allowing users to view files and folders within a directory on the hosting server.

The dir command is similar to ls, but its output might vary slightly depending on the system configuration or any specific options used with it. By default, dir provides a more concise listing compared to ls, showing basic information about files and directories within a specified directory.

For instance, if you want to list the contents of the current directory using dir, you’d simply type dir in the terminal and press Enter.

It will display a list of files and directories in a more compact format compared to the more detailed output of ls.

However, it’s worth noting that ls is more widely used and offers more flexibility and customization options through various command-line switches and options.

To see the contents of a directory in a more detailed and comprehensive manner, you can use ls with different options to suit your needs. For instance:

  • ls -l provides a long listing format with detailed information.
  • ls -a shows all files, including hidden files (those starting with a dot .).
  • ls -lh provides a long listing with file sizes displayed in human-readable format.

These are just a few examples of how ls can be used with different options to get detailed information about the contents of directories in Linux.

The general syntax of the dir command is as follows.

dir

dir Command Usage with Examples

The most common usage of the dir command is to display the contents of a directory in ascending order alphabetically.

If you run the dir command without any options or location of the directory it will display all files and directories in your current working directory.

dir

Files and Directories listing in a Particular Path

If you want to list all the files and directories of a particular path, then append the path of your directory as shown. Here, we will list files and directories under the /etc directory.

dir /etc

To list one file per line use -1 option as follows.

dir -1 /etc

Hidden Files and Directories listing

To list all files in a directory including . (hidden) files, use the -a option. You can include the -l option to format output as a list (detailed information).

dir -a
dir -al

Directory Entries listing

When you need to list only directory entries instead of directory content, you can use the -d option. In the output below, the option -d lists entries for the /etc directory.

When you use -dl, it shows a long listing of the directory including the owner, group owner, and permissions.

dir -d /etc
dir -dl /etc

Index Number of Files listing

In case you want to view the index number of each file, use the option -i. From the output below, you can see that the first column shows numbers. These numbers are called inodes which are sometimes referred to as index nodes or index numbers.

An inode in Linux systems is a data storage on a filesystem that stores information about a file except for the filename and its actual data.

dir -il

Listing Files According to size & time

The output below shows a sorted list of files according to their sizes by using the -S option.

dir -ashlS /home/chennaihosting

You can also sort files by modification time, with the file that has recently been modified appearing first on the list. This can be done using the -t option.

dir -ashlt /home/chennaihosting

To find help in using the dir command use –help flag and to view version details of dir use –version

dir --help
dir --version

Remember that in Linux, you might need appropriate permissions to create directories in certain locations (especially system directories). Using sudo before the command might be necessary in some cases to execute commands with elevated privileges.

Always be cautious while working with system directories or when using commands with elevated permissions (sudo), as they can affect the system’s stability and security.