Work with Directories in Shell Script - BunksAllowed

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

Community

Work with Directories in Shell Script

Share This

Check Present Working Directory

To check the present working directory, pwd command is used.

Create Directories

To create a directory or a set of directories, mkdir command is used as shown below. In the first case, one directory is created and in the second case, two directories are created. Remember that space cannot be used in the name of a directory. If you use space, directories will be created by the name of each word.

Change Present Directory

To change the present working directory cd command is used. Using this command, we can change the current directory to any other directory.

Let us consider a child directory code and a sub-directory code as a shell. We want to move to the shell directory from the current location. To do so, there are different ways as shown below.

$cd dir1/dir2/dir3
$cd /var/www/html
$cd ../../dir1/dir2

Copying Files and Directories

Moving Directories

Removing Directories

An empty directory can be removed using rmdir command. But, if the directory contains one or more files or directories, the directory needs to be removed in a recursive way.



Happy Exploring!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.