Directory Related Commands in Linux - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Random Posts

Directory Related Commands in Linux

Share This

In this tutorial we will discuss different directory related commands.

pwd command

The pwd, a built-in command, stands for print working directory. It displays the current working location or directory of the user. It displays the whole working path starting with / as shown in the below.

mkdir command

You have to use mkdir command to create a directory. This command can be used to create multiple directories. The use of this command is shown below.

Remember that file name and directory name can not contain any space. Hence if you use space in directory name, multiple directories will be created. For an example, mkdir my dir1 will create two directories namely, my and dir1.

rmdir command

The rmdir command is used to remove a directory. This command is also used to remove multiple directories.

But this command can be used only if the directories are empty. If programs directory contains some files and directories, using rmdir command you cann't delete the directory. You have to use rm command with -r option to recursively delete all the files and directories it contains along with this directory.

ls command

The ls command is used to show the list of directories and files. It will list out all the files and directories in the directed folder.

If you execute ls command without specifying any directory, it shows list of files and directories in the present working directory as shown below.

To get list of files and directories in a different directory, you have to specify the path as shown below.

To get details of the files and directories, you can run ls command with -l option. It shows file type, access rights, creation time, ownership details etc. in long list format as shown below.

The ls command with -a option shows all the files along with hidden files that start with . (dot) symbol and are not visible in the regular directory.

The command ls -lh will show you the file sizes in human readable format. This command shouws file size in terms of Mb, Gb, Tb, etc.

cd command

The cd command stands for change directory. It is used to change to the directory you want to work from the present directory.

To move to home directory from any location you can use ~ symbol as shown below.

To move to the previous directory from any location you can use - symbol as shown below.

To move to the parent directory you can use .. (double consecutive dots).

The cd / command will help you to move to the root directory.

If you want to move to any directory, you can use relative path from your present working directory, or you can use actual path from the root directory. Look at the following example.


Happy Exploring!

No comments:

Post a Comment