Performing basic file operations
Most commonly used files are regular files and directories. In the following subsection, we will see the basic file operations.
Creating files
We can create both regular files and directories in shell using different shell commands.
Directory file
A directory is a special type of file that contains a list of filenames and a corresponding inode number. It acts as a container or folder to hold files and directories.
To create a new directory through shell, we can use the mkdir
command:
$ mkdir dir1
We can also provide multiple directories' name as arguments to the mkdir
command as follows:
$ mkdir dir2 dir3 dir4 # Creates multiple directories
We can create a parent directory if the specified pathname to mkdir
is not present. This is done using the -p
option in mkdir
:
$ mkdir -p /tmp/dir1/dir2/dir3
Here, if dir1
and dir2
are the parent directories for dir3
and don't exist already, the -p
option will create the dir1
directory first and then dir2
subdirectory inside...