Amazon

Monday, May 6, 2019

Access the Command Line

Important 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.

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 -]#

Basic Commands

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

[student@desktop ~]$ date
Tue  Jan   1  10:30:50 PDT 2019
[student@desktop ~]$ date +%R
10:30
[student@desktop ~]$ date +%x
01/01/2019

passwd - The passwd command changes a user's own password.

[student@desktop ~]$ 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.

[student@desktop ~]$ file /etc/passwd
[student@desktop ~]$ file /bin/passwd
[student@desktop ~]$ file /home

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.

[student@desktop ~]$ head /etc/passwd

[student@desktop ~]$ tail -n 3 /etc/passwd

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.

[student@desktop ~]$ wc /etc/passwd
[student@desktop ~]$ wc -l /etc/passwd
[student@desktop ~]$ wc - c /etc/group /etc/hosts

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.

[student@desktop ~]$ pas<Tab><Tab>
passwd    paste    pasuspender
[student@desktop ~]$ pass<Tab>
[student@desktop ~]$ passwd
Changing password for user student.
Changing password for student.
(current) UNIX password: old_password

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.

[student@desktop ~]$ history

[student@desktop ~]$ !ls

[student@desktop ~]$ !26

No comments:

Post a Comment