Command line interface

From English Wiki
Revision as of 05:15, 15 August 2022 by Kentlee7 (talk | contribs) (Created page with "The command line interface (CLI) or shell interface is an old fashioned, non-graphical interface in a shell, which is still convenient for serious Linux users. It may seem old...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The command line interface (CLI) or shell interface is an old fashioned, non-graphical interface in a shell, which is still convenient for serious Linux users. It may seem old fashioned, but seasoned Linux afficionados find it to be much faster, more convenient, more effective, and more powerful for many tasks than using a GUI.


1 Command line interface: General commands

Command Function
!! Repeat last command
!cmd# Re-execute a command by its history number
cmd –help Brief help information on a command
cmd & Start a process and send it to the background
cmd < file Read input of command from a file
cmd 2> file Error output (stderr) of cmd to file
& cmd2 stderr of cmd1 to cmd2
cmd1; cmd2 Execute separate commands in succession
&& Run command #2 if command #1 is okay (command1 && command2)
# Shell prompt symbol used for superuser
Move up in command history
Move down in command history
> Redirect: Send output of a process to a file (create a new file or overwrite an existing file)
>& OR &> Send output to a location
>> Append: Append output of a process to the end of an existing file
| command2)
$ Shell prompt symbol for normal user
1> Send stdoutput (standard output, e.g., to the screen) to a location
1>2& Redirect stdout (standard output) to stderr (error file)
2> Send stderror (error messages) to a location
2> /dev/null Redirect stderr to bitbucket
apropos keyword Display command names based on keyword search
bc Launch a high-precision calculator shell
cal Show a calendar for the current month
cal -3 Shows calendar for three months: previous, current, and following month
cal -n no. Shows calendar for specified number of months around the current date
cal month Shows calendar for specified month
cal month# year Shows calendar for specified month (by number) and year (e.g., cal 1 1812 = January 1812)
cal year Shows calendar for a specified year (from 01 to 9999 CE)
cd - Move to previous directory
chsh Change shell
clear Clear screen
CTL-ALT [F1, F2, F3...] Switch to alternate system terminal (tty)
date -d Print formatted date.
dmesg -k Display system messages
echo text Echo a message to the standard output (i.e., the screen)
echo text > file Redirect text to a new file (or overwrite an existing file)
at time at 12.00)
echo “ “Hello, world.” ” Display a message containing quotation marks or other escape characters, e.g., “ ‘ [ ] | / \ ( ) { } * ?
exit Exit the current shell
export A command for assigning or removing an environment variable.
expr Evaluate an expression.
history Displays history of previously entered commands in the shell
grep keyword Search history for a particular command
localectl Show locale related environmental settings
ls -S List and sort files by file size
man cmd Full manual entry for command
screenfetch Display system, OS and DM information
script Record terminal session activity and create output for the session in a file
source script . script Load a configuration file into current script or shell session
stderr Standard error, i.e., error messages
stdin Standard input (input to a command)
stdout Standard output, e.g., of a command to the screen
stty Set key commands or shortcuts
su - Log in as superuser
sudo Root or superuser privilege to execute commands
sudo -ll Show commands that the user is allowed to execute
sudo !! Rerun last command with sudo privileges
tee Read stdin and send output to stdout and file


CLI environment variables

Command Function
$HOME Home directory
$HOME/.bashrc Location of user bash configuration file
$PATH Executable search path, i.e., paths for commands and executable files
$SHELL Current shell
alias Show defined aliases
alias [alias]=”[command]” Define a new alias in the bash environment file
cat etcvconsole.conf See keyboard settings for terminal sessions
echo "­STR­ING­" Output string
echo $NAME Output value of variable NAME
echo $Variable_name Output the value of a defined variable on the terminal.
env Display environment variables.
export NAME = value set "­value to NAME
export PATH="$PATH:/some/addition" Export new variable to bash configuration
export VAR Export a variable to the current shell and child processes
export Variable = value Assign an environment variable a new value.
localectl Show locale related environmental settings
printenv Print defined environmental variables
source .bashrc Reload bash shell settings after editing configuration file
Unset Remove or delete a variable.
variable_name = variable_value Assign a variable value to variable name
vi /etc/l­oca­le.gen Edit localization file for environmental variables


2 CLI keyboard khortcuts

Command Function
!! Execute a previously executed command.
CTL + C Kill a running process.
CTL + G Exit command history.
CTL + K Cut a line fragment succeeding the cursor.
CTL + O Execute the previously recalled command.
CTL + R Recall the last used command.
CTL + U Cut a line fragment preceding the cursor.
CTL + W Cut a single word preceding the cursor.
CTL + Y Paste from clipboard.
CTL + Z Stop or suspend a currently active process.
exit Sign off from an active session.



3 See also