05 - Intro to Command Line Interface
05 - Intro to Command Line Interface
1. CLI Introduction
2. GUI vs CLI
3. Basic File Management Commands in Linux
4. Essential list of Commands
CLI Introduction
CLI stands for the command-line interface. It is a program that allows users to type text commands instructing the computer to do specific tasks.
Back then, people had only a keyboard as an input device and the computer screen could only display text information. Operating
systems like MS-DOS used the CLI as the standard user interface.
Note that interface has a much broader definition these days. For this session, however, we're only interested in the display and input of text an
commands via the command line.
CLI Display
The command line can be the default interface for a computer, but most personal computers use a program (like Terminal) within the desktop graphic
interface to provide the command line interface. Let's dissect the CLI's language for a moment.
Below is an example of the prompt on an Ubuntu Linux server:
ubuntu@chopin:~$
[user]@[hostname]:[current_directory]$
Examples - Microsoft Windows, macOS, Chrome OS, Linux variants like Ubuntu
CLI vs GUI
Open the command-line interface
To start some experiments we need to open our command-line interface first.
Opening: Windows
Depending on your version of Windows and your keyboard, one of the following should open a command window (you may have to experiment a bit, b
you don't have to try all of these suggestions):
Go to the Start menu or screen, and enter "Command Prompt" in the search field.
Go to Start menu → Windows System → Command Prompt.
Opening: OS X
Prompt
You now should see a white or black window that is waiting for your commands.
Prompt: OS X and Linux
If you're on Mac or Linux, you probably see a $ , like this:
command-line
Prompt: Windows
>
Each command will be prepended by a $ or > and one space, but you should not type it. Your computer will do it for you.
Just a small note: in your case, there may be something like C:\Users\alma> or alma-MacBook-Air:~ alma$ before the prompt sign, and this is 100% OK
The part up to and including the $ or the > is called the command line prompt, or prompt for short. It prompts you to input something there.
$ whoami
> whoami
command-line
$ whoami
almabetter-student
Basics
Each operating system has a slightly different set of commands for the command line, so make sure to follow instructions for your operating system. Let
try this, shall we?
Current directory
It'd be nice to know where are we now, right? Let's see. Type this command and hit enter :
Current directory: OS X and Linux
command-line
$ pwd
/Users/almabetter-student
> cd
Users\alambetter
C:\Users\alambetter-student
Note: 'cd' stands for 'change directory'. With PowerShell, you can use pwd just like on Linux or Mac OS X.
You'll probably see something similar on your machine. Once you open the command line you usually start at your user's home directory.
$ ls
Applications
Desktop
Downloads
Music
...
> dir
Directory of C:\Users
Users\almabetter
\almabetter-student
05/08/2020 07:28 PM <DIR> Applications
05/08/2020 07:28 PM <DIR> Desktop
05/08/2020 07:28 PM <DIR> Downloads
05/08/2020 07:28 PM <DIR> Music
...
Note: In PowerShell, you can also use 'ls' like on Linux and Mac OS X.
$ cd Desktop
> cd Desktop
command-line
$ pwd
/Users/almabetter-student/Desktop
> cd
Users\almabetter
C:\Users\almabetter-student\
student\Desktop
Desktop
Here it is!
PRO tip: if you type cd D and then hit tab on your keyboard, the command line will automatically fill in the rest of the name so you can
navigate faster. If there is more than one folder starting with "D", hit the tab key twice to get a list of options.
Create directory
How about creating a practice directory on your desktop? You can do it this way:
Create directory: OS X and Linux
command-line
$ mkdir practice
This little command will create a folder with the name practice on your desktop. You can check if it's there by looking on your Desktop or by runnin
a ls or dir command! Try it. :)
PRO tip: If you don't want to type the same commands over and over, try pressing the up arrow and down arrow on your keyboard to
cycle through recently used commands.
Clean up
We don't want to leave a mess, so let's remove everything we did until that point.
First, we need to get back to Desktop:
Clean up: OS X and Linux
command-line
$ cd ..
Using .. with the cd command will change your current directory to the parent directory (that is, the directory that contains your current directory).
Check where you are:
Check location: OS X and Linux
command-line
$ pwd
/Users/almabetter-student/Desktop
> cd
C:\Users\almabetter-student\Desktop
Attention: Deleting files using del, rmdir or rm is irrecoverable, meaning the deleted files will be gone forever! So be very careful with this
command.
$ rm -r practice
$ ls
> dir
Exit
That's it for now! You can safely close the command line now.
Exit: OS X and Linux
command-line
$ exit
Exit: Windows
command-line
> exit
Essential Commands
Here is a summary of some useful commands:
Interview Questions
What is a CLI ?
CLI is a command line program that accepts text input to execute operating system functions.
A Command Line Interface connects a user to a computer program or operating system. Through the CLI, users interact with a system or application b
typing in text (commands). The command is typed on a specific line following a visual prompt from the computer.
GUI lets a user interact with the device/system with the help of graphical elements, like windows, menus, icons, etc. The CLI, on the other hand, lets
user interact with their device/system with the help of various commands.
Thank you