Linux Commands
mkdir(make/create directory) command
To create a new directory, we use “mkdir DIRECTORY_NAME”. In this example, i am using dir1 as directory name. You can use directory name according to your choice.
mkdir -p
is a command in Linux and Unix-like operating systems that creates a new directory. The -p
option stands for "parent" and it allows you to create a directory hierarchy (a tree of directories) in one step, without getting an error if the parent directories already exist.
Here’s an example:
mkdir dir1 --> Create a directory
mkdir -p dir1 --> Create a directory if it is already exists
mkdir dir1 dir2 dir3 --> Create 3 directories at a time
mkdir Tester{0..5} --> Create 6 dir at time
This will create the directory dir1
if it doesn't already exist. The -p
option ensures that the whole hierarchy of directories is created in one step, without any errors.
Create a file with the touch command
If we have to create any file, we can use the touch command. Type “touch FILE_NAME.EXTENSION” then press enter.
In this example, I am creating a sample.txt file. You can create any other files like .docx, .html, .py, .csv, etc… according to your choice.
touch file1 --> Create a file with name file1
touch file1 file2 file3--> Create 3 directories at a time
touch file{0..5} --> Create 6 files at time