Fri. Aug 14th, 2020

[Linux basic] Creating and deleting Linux directories

2 min read

mkdir command

The mkdir used to create one or more directories

Example:

Create directory:

mkdir ddos

The above command will create the directory ‘ddos’.

Create a directory and set access permissions:

mkdir -m 777 ddos

The above command will create the directory ‘ddos’ and set read and write permissions.

rmdir command

The rmdir command is used to delete/remove a directory and its subdirectories.

Example:

Delete / remove directory. 

rmdir tmp

If the tmp directory is empty, the rmdir command will remove/delete the tmp directory.

Delete the directory tree:

rm -ir tmp

This command recursively deletes the contents of all subdirectories under the tmp directory. You will be prompted for the deletion of each file, and then the tmp directory itself is deleted. 

To deletes the contents of all subdirectories under the tmp directory without prompt, you can use the command:

rm -rf tmp

cd command

The cd command is used to change directories.

Example

cd /etc/: This command changes from its parent directory to the /etc/ directory.

cd ..: This will change from the current working directory/subdirectory to the parent directory.

cd ~:  This command will change to the user’s home directory “/home/username”

pwd command

The pwd command displays the working directory. The pwd command displays the absolute pathname of the current working directory.

ls command

The ls command files and directories in the current working directory.

Example:

Display the contents of the root directory:

ls /

List the contents of the root directory.

Show hidden files and directories: 

ls -a

Lists all items, including hidden files and directories.

Display information: 

ls -i