Usually, most users have seen the Windows command prompt at least once while using their computer systems. Be it for seeing any system errors or just for the sake of exploration. The Windows command prompt is a text-based interface used for interaction with the computer's operating software. This is an example of a command line interface or CLI.
CLI is a text-based interface to interact with an operating system or software by entering commands as text lines. The user usually types CLI-specific commands, followed by arguments or options, and then presses the "Enter" key to execute the command. The operating system or software then processes the command and provides the desired output or performs the requested action.
In this Answer, we will look at the examples of command line interfaces and the commonly used commands.
In this text-based interface, we have several commands which are used to interact with it. These commands are generally used across the majority of text-based interfaces. Let's see some of the commands.
cd
commandcd
is used for navigating through the different directories in a system. The implementation is shown below:
cd Courses/dataStructures
Moreover, if we want to go back to a directory we use:
cd ..
While the command that takes the user back to the home directory is by using just cd
.
ls
commandls
is used to list all the files and folders in a directory. This helps to visualize whatever the directory stores.
cd Coursesls
In this command, we have some other options which can change the output.
-l
: Long format listing (detailed information about files and directories)
-a
: All files (including hidden files and directories)
-h
: Human-readable sizes (file sizes in KB, MB, or GB)
-r
: Reverse order (listing in reverse alphabetical order)
-t
: Sort by modification time (most recently modified first)
-R
: Recursive listing (contents of subdirectories included)
--color
: Enable colorized output (highlight files and directories with different colors)
mkdir
commandThe mkdir
command stands for "make directory," and it creates new directories or folders within the file system. Its implementation is shown below:
mkdir dir1mkdir Courses/new_dir2
If you want to create nested directories (directories within directories), you can use the -p option:
mkdir -p path/to/nested/directory
del
commandThe del
command is used to delete any file or folder in the computer system. The rm
command is used in Unix systems such as Linux or macOS. This is implemented as shown below:
del file1.txt file2.txt file3.txt
Moreover, we can use /s
and /p
to change the output.
/s
: Deletes specified files from all subdirectories as well
/p
: Suppresses the confirmation prompt before deleting each file
del /s /q directory_name
cp
commandThe cp
command is used for copying information from a source file to a destination file. This is implemented below to clarify any issues.
cp source_file destination
We use the -r
or -R
option to copy a directory and its contents.
cp -r /path/to/source_directory/ /path/to/destination/
mv
commandThe mv
command is used to move or rename files and directories in the command-line interface. Implementation of moving a file from one place to another:
mv source destination
While if we want to use this to rename a file, then the command would be:
mv current_name new_name
touch
commandThe touch
command in CLI is used to create new, empty files in the computer system. This command comes in help for various tasks. Its implementation can be seen below:
touch filename.txttouch /path/to/directory/filename.txt
There are various examples of CLI which are used by various users. Let's discuss the most commonly used one, the Windows command prompt.
The other example we can see is the Ubuntu command line interface.
Just like these, we can find similar CLIs in most computer operating systems, such as the macOS.
Let's take a small quiz about the basic commands we discussed above.
Assessment
Which command is used to create new files?
ls
mv
touch
mkdir
Free Resources