“But why Command Line Interface (CLI)?“
I asked this question to the computer professor at my university when he was trying to introduce Linux CLI or Command Line Interface to the class. Like most of the students in my class, almost all of the interaction that I have had with computers was using Windows OS. Accustomed to using ‘My Computer’ in Windows, utilizing weird-looking commands to do simple tasks such as listing files felt an overkill to me.
However, it turns out that the precision, power, and resilience of a CLI tool are significantly more than those of a GUI application. A command-line interface (CLI) provides a developer with much-needed speed and control over his or her job. As a result, mastering CLI tools is critical for any prospective coder.
In this article, we will see some of the most commonly used commands which every beginner should know.
The ls
command is one of the most used commands in Linux. This command has a very simple utility and is used to list all files in a directory. Using combinations of options, the granularity and details of the file shown can be controlled. Here are some examples.
When used without any argument, the ls
command lists the files and folders in the current directory.
$ ls
When a path is provided to this command, this commands lists file and folders in the provided directory.
$ ls path/to/my/directory
Users can also use various flags to display hidden files and folders.
Right next in popularity to the ls command is the cd
command. Use this command to change the current directory. Consider it similar to double-clicking on a certain folder in Windows to enter it. The difference is that you can open any arbitrary folder as long as you know the path to that folder or directory.
$ cd /home/desktop/my_folder
When no path is specified, the directory is changed to the path - /home
.
Use the touch
command to create a new file in the current directory. Though simple, this command is very popular among CLI users. Consider it similar to creating a new text document by right-clicking in Windows. But with touch
you can create all sorts of files, not just restricted to text files.
$ touch main.py
While some shells display the current working directory at the start of the cursor, we can use the pwd
command to get the path to the current working directory. With a very simple usage, you will find it very useful when working on several shells at once. Consider this command as looking at the top bar in Window’s file explorer to see the path of the current folder.
$ pwd
One of the greatest Linux commands is man
. This command is also known as the manual command. The man command is only a help system for Linux commands. It enables users to search the reference manuals for authorities and other utilities used in the interface. The man page contains a description of the command, relevant arguments, variables, pictures, and other useful information (brief for handbook page). Use it in the following manner -
$ man pwd
The cat
Linux command is an abbreviation for concatenate. This command's duty is to print the contents of a file to the standard output sequence. It displays file information in the Linux terminal window. This is far more efficient than opening the file in an editor. Enter the following command to read the data from main.py
.
$ cat main.py
To create a new folder in Windows you would right-click and select a new folder. This is followed by giving a name to the new folder. All this process is performed by a single command called mkdir
. Pass in the name of the folder/directory you want to be created and it will be created in the present directory. Here is an example.
$ mkdir New_Folder
One of the simplest yet one of the most used commands. This command clears the content on the terminal screen. The usage of this command is as follows -
$ clear
This concludes with a list of some of the most used commands. Learning these commands lays the foundation for learning advanced and more complex commands.
Hit the like button to let Hackernoon know you are enjoying the blogs. Follow me on Twitter for more on Tech.