How To Access The Command Line In Linux

Command Line:
A command Line, CLI, Command Line Interface, or Terminal, is a text based interface to the system. Enter the commands by typing them on the keyboard and feedback will be given back by Command Line or Terminal. The command line typically presents a prompt. As type, it will be displayed after the prompt. Most of the time you will be issuing commmands. A command line is a text-based interface which can be used to input instruction top a computer system.

Shell:
A shell is a user inteface to a computer system that relies on keyboard input. Shell is a command language interpreter that executes commands read from the standard input keyboard of from a file. Shell is not part of system kernel, but uses the system kernel to execute programs, create file etc. The dedault Linux command line interface or terminal is the Bourne Again SHell or Bash Shell. A bash is a command interpreter. The Bash Shell is similar in concep to the command line interpreter found in Microsoft Windows CMS.
Type the command #echo $O or #echo $SHELL in the terminal to see which shell you are using

Command:
A command is an instruction given by a user telling a computer to do something, command the name of the program to run. Commands are generally issued by typing them in at the command line and then pressing the ENTER key, which passes them to the shell. One command consists of three parts, Command name, Options, and Arguments.
Example: command-name optionA optionB argument1 argument2. Command[options] [arguments].
Between command-name, Option and arguments, space is necessary. Option always start with “_”
OR “–“.
Example: ls -l /etc where ls is a Command name -l is Option and /etc is Arguments

Kernel:
The Kernel is a software code that servers as a layer between the hardware and main programs that runs on a computer. It is the first part to load when the OS boots up. Its loaded in memory and stay there throughout the entire time the computer is in session. The Linux kernel allows for communication between the hardware via drivers included in the kernel or added via kernel modules and the software. It also responsible for the eddicient managemet of the system’s resources such as memory management, process and task management, and dick management.

GNOME:
GNOME stands for GNU Network Object Model Enviroment. GNOME is a full point-and-click enviroment — colors, little, pictures, the works. GNOME is a desktop enviroment and graphical user interface that runs on top of a computer operating system. Is is composed entirely of free and open source software. It is an international project that includes ceating software development frameworks, selecting application software fot the desktop, and working on the program that manage application launching, files handling, and window and task management. GNOME can be used with various Unix like operating systems.

KDE:
KDE stands for K Dekstop Enviroment. KDE is a desktop working platform with a graphical user interface (GUI) released in the form of an open-source package. It is a sdesktop enviroment for Linux based operating system. KDE as a GUI forLinux OS. KDE has proved Linux user to make it use as easy as they use windows. KDE provides Linux users a graphical interface to choose their own customized dekstop enviroment.

Different between a normal user and a super user.

When a regular user starts a shell, the default prompt ends with a $ character.
E.g. [student@desktop ~]$

When a super user starts a shell, the default prompts end with a # character. This makes it more obvious that is a superuser shell, which helps to avoid accidents and mistakes in the privileged account. Super user is also called as root.
E.g. [root@desktop -]#

mportant Console Access Terms

Shell – The interpreter that executes commands types as string.
Prompt – The visual cue that indicates an interactive shell is waiting for the user to type a command.
Command – The name of a program to run.
Options – The part of the command line that adjust the behavior of a command.
Argument – The part of the command lie that specifies the target that the command should operate on.
Physical console – The hardware display and keyboard used to interact with a system.
Virtual console – One of multiple logical consoles that can each support an independent login session.
Terminal – An interface that provides a display for output and a keyboard for input to a shell session.

Bash command and keyboard shortcuts

Ctrl + Left Arrow – Jump to the beginning of the previous word on the command line.
; – Separate commands on the same line.
Ctrl + k – Clear from the cursor to the end of the command line.
!string – Re-execute a recent command by matching the command name.
Tab – Shortcut used to complete commands, file names, and options.
!number – Re-execute a specific command in the history list.
Ctrl + a – Jump to the beginning for the command line
history – Display the list of previous commands.
Esc+. – Copy the last argument of previous commands.

Basic Commands

[cms-lab1@localhost ~]

$ whoami
cms-lab1

[root@localhost ~]

# whoami
root

date – The date command is used to display the current date and time.

[cms-lab1@localhost ~]

$ date
Sat Jun 8 10:36:41 IST 2019

[cms-lab1@localhost ~]

$ date +%R
10:37

[cms-lab1@localhost ~]

$ date +%r
10:37:35 AM

[cms-lab1@localhost ~]

$ date +%x
06/08/2019

[cms-lab1@localhost ~]

$ date +%X
10:38:04 AM

[root@localhost ~]

# cal
June 2019
Su Mo Tu We Th Fr Sa
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30

Changing User from normal to superuser(root)

[cms-lab1@localhost ~]

$ su root
Password:

[root@localhost cms-lab1]

#
or

[cms-lab1@localhost ~]

$ su –
Password:
Last login: Sat Jun 8 10:49:59 IST 2019 on pts/0

[root@localhost ~]

#

Changing User from superuser to normal user.

[root@localhost ~]

# su cms-lab1

[cms-lab1@localhost root]

$ cd ~

[cms-lab1@localhost ~]

$
Note: We used “cd ~” command to change the directory from root to normal user.

passwd – The passwd command changes a user’s own password.

[cms-lab1@localhost ~]

$ passwd
Changing password for user student.
Changing password for student.
(current) UNIX password: old_password
New password: new_password
Retype new password – new_password
passwd: all authentication tokens update successfully.

file – Linux does not require the file name extensions to classify by type. The file command scans the beginning of a file’s contents and display what type it is. The files to be classified are passed as argument to the command.

[cms-lab1@localhost ~]

$ file /etc/passwd
/etc/passwd: ASCII text

[cms-lab1@localhost ~]

$ file /bin/passwd
/bin/passwd: setuid ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=0a16a7915f7f9b01d96442755257e22067ce5b2c, stripped

[cms-lab1@localhost ~]

$ file /home
/home: directory

ls for Listing Files – If you want to see the list of files on your Linux system, uuse the ‘ls’ command.

[cms-lab1@localhost ~]

$ ls
Desktop Documents Downloads Music Pictures Public Templates Videos

[cms-lab1@localhost ~]

$ ls -l
total 0
drwxr-xr-x. 2 cms-lab1 cms-lab1 6 Jun 1 12:26 Desktop
drwxr-xr-x. 2 cms-lab1 cms-lab1 6 Jun 1 12:26 Documents
drwxr-xr-x. 2 cms-lab1 cms-lab1 6 Jun 1 12:26 Downloads
drwxr-xr-x. 2 cms-lab1 cms-lab1 6 Jun 1 12:26 Music
drwxr-xr-x. 2 cms-lab1 cms-lab1 6 Jun 1 12:26 Pictures
drwxr-xr-x. 2 cms-lab1 cms-lab1 6 Jun 1 12:26 Public
drwxr-xr-x. 2 cms-lab1 cms-lab1 6 Jun 1 12:26 Templates
drwxr-xr-x. 2 cms-lab1 cms-lab1 6 Jun 1 12:26 Videos

If you want to see hidden files on your Linux system, use ‘ls -a’ command.

[cms-lab1@localhost ~]

$ ls -a
. .bash_profile Desktop .ICEauthority Pictures
.. .bashrc Documents .local Public
.bash_history .cache Downloads .mozilla Templates
.bash_logout .config .esd_auth Music Videos

You can use ‘ls-R’ to shows all the files not only in directories but also in subdirectories

[cms-lab1@localhost ~]

$ ls -R
.:
Desktop Documents Downloads Music Pictures Public Templates Videos

./Desktop:

./Documents:

./Downloads:

./Music:

./Pictures:

./Public:

./Templates:

./Videos:

‘ls -al’ gives detailed information of the files. The command provices information in a columnar format.

[cms-lab1@localhost ~]

$ ls -al
total 36
drwx——. 14 cms-lab1 cms-lab1 4096 Jun 8 10:50 .
drwxr-xr-x. 3 root root 21 Jun 1 18:50 ..
-rw——-. 1 cms-lab1 cms-lab1 5 Jun 1 12:31 .bash_history
-rw-r–r–. 1 cms-lab1 cms-lab1 18 Jul 8 2015 .bash_logout
-rw-r–r–. 1 cms-lab1 cms-lab1 193 Jul 8 2015 .bash_profile
-rw-r–r–. 1 cms-lab1 cms-lab1 231 Jul 8 2015 .bashrc
drwx——. 10 cms-lab1 cms-lab1 4096 Jun 1 12:27 .cache
drwxr-xr-x. 15 cms-lab1 cms-lab1 4096 Jun 1 12:27 .config
drwxr-xr-x. 2 cms-lab1 cms-lab1 6 Jun 1 12:26 Desktop
drwxr-xr-x. 2 cms-lab1 cms-lab1 6 Jun 1 12:26 Documents
drwxr-xr-x. 2 cms-lab1 cms-lab1 6 Jun 1 12:26 Downloads
-rw——-. 1 cms-lab1 cms-lab1 16 Jun 1 12:26 .esd_auth
-rw——-. 1 cms-lab1 cms-lab1 628 Jun 8 10:36 .ICEauthority
drwx——. 3 cms-lab1 cms-lab1 18 Jun 1 12:26 .local
drwxr-xr-x. 4 cms-lab1 cms-lab1 37 Jun 1 18:21 .mozilla
drwxr-xr-x. 2 cms-lab1 cms-lab1 6 Jun 1 12:26 Music
drwxr-xr-x. 2 cms-lab1 cms-lab1 6 Jun 1 12:26 Pictures
drwxr-xr-x. 2 cms-lab1 cms-lab1 6 Jun 1 12:26 Public
drwxr-xr-x. 2 cms-lab1 cms-lab1 6 Jun 1 12:26 Templates
drwxr-xr-x. 2 cms-lab1 cms-lab1 6 Jun 1 12:26 Videos

head tail – The head and tail command display the beginning and end of a file respectively. By default, these commands display 10 lines, but they both have a -n option that allows a different number of lines to be specified. The file to display is passed as an arguments to these commands.

[cms-lab1@localhost ~]

$ head /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin

[cms-lab1@localhost ~]

$ tail /etc/passwd
mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin
gnome-initial-setup:x:989:984::/run/gnome-initial-setup/:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
dovecot:x:97:97:Dovecot IMAP server:/usr/libexec/dovecot:/sbin/nologin
dovenull:x:988:983:Dovecot’s unauthorized user:/usr/libexec/dovecot:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
cms-lab1:x:1000:1000:cms-lab1:/home/cms-lab1:/bin/bash

[cms-lab1@localhost ~]

$ head -n 4 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin

[cms-lab1@localhost ~]

$ tail -n 3 /etc/passwd
ntp:x:38:38::/etc/ntp:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
cms-lab1:x:1000:1000:cms-lab1:/home/cms-lab1:/bin/bash

wc – the wc command count lines, words and characters in a file. It can take a -l, -w, or -c option to display only the lines words, or characters, respectively.

[cms-lab1@localhost ~]

$ wc /etc/passwd
48 98 2593 /etc/passwd

[cms-lab1@localhost ~]

$ wc -l /etc/passwd
48 /etc/passwd

[cms-lab1@localhost ~]

$ wc -c /etc/passwd
2593 /etc/passwd

[cms-lab1@localhost ~]

$ wc -c /etc/group
1039 /etc/group

[cms-lab1@localhost ~]

$ wc -c /etc/hosts
158 /etc/hosts

[cms-lab1@localhost ~]

$ wc -w /etc/passwd
98 /etc/passwd

Tab completion – Tab completion allows a user to quick complete commands or file names once they have typed enough at the prompt to make it unique. if the characters type are not unique, pressing the Tab key twice displays all commands that begin with the characters already typed.

[cms-lab1@localhost ~]

$ pas
passwd paste pasuspender

[cms-lab1@localhost ~]

$ pass

[cms-lab1@localhost ~]

$ passwd
Changing password for user student.
Changing password for student.
(current) UNIX password: old_password

Print command (pr) – This command helps in formating the file for printing on the terminal.

history – The history command display a list of previously executed commands prefixed with a command number
The exclamation point character, !, is a meta character that is used to expand previous commands without having retype them. !number expand to the command matching the number specified. !string expands to the most recent command that begins with the string specified.

[cms-lab1@localhost ~]

$ history
1 su –
2 cd ..
3 ls
4 date
5 date +%R
6 date +%r
7 date +%x
8 date +%X
9 file /etc/passwd
10 file /bin/passwd
11 file /home
12 head /etc/passwd
13 tail /etc/passwd
14 head -n 4 /etc/passwd
15 tail -n 3 /etc/passwd
16 wc -c
17 wc /etc/passwd
18 wc -l /etc/passwd
19 wc -c /etc/passwd
20 wc -c /etc/group
21 wc -c /etc/host
22 wc -c /etc/hosts
23 wc -w /etc/passwd
24 history

[cms-lab1@localhost ~]

$ !ls
ls
Desktop Documents Downloads Music Pictures Public Templates Videos

[cms-lab1@localhost ~]

$ !22
wc -c /etc/hosts
158 /etc/hosts

clear – The ‘clear’ command will clear all the clutter on the terminal and gives you a clean window to work on.

[cms-lab1@localhost ~]

$ clear

Leave a Reply

Your email address will not be published. Required fields are marked *