Linux Command Line Cheat sheets-[A list of Shortcuts]
Linux: Linux command is the Service of Linux operating systems. All the tasks either it is basic or advanced tasks can be done by executing the Linux commands. Below in this article, you can get to know about the basic Linux commands that are used commonly. To know about this in detail, read the article fully.
Linux Logo
Last updated on Sep 13, 2021.
Download Linux command line Cheatsheet for offline study here: Linux command line Cheatsheet.PDF
Linux Bash Commands
Commands
Description
uname -a
This command shows the system and the kernel.
mount
Displays the mounted file.
date
Displays the system date.
uptime
To present the uptime.
whoami
This command displays your username.
date
Displays the system date.
man command
This presents the manual for the command.
Linux Shortcuts for bash
Shortcuts
usage
CTRL-c
To stop the current command.
CTRL-z
Shortcut for sleep program.
CTRL-a
To go to the start of the line.
CTRL-e
This shortcut is to go to the end of the line.
CTRL-u
This is to cut from the start of the line.
CTRL-k
To cut to the end of the line.
CTRL-r
Shortcut for search history.
!!
To repeat the last command.
!abc
This shortcut is to run the last command starting with abc.
!abc:p
To print the last command starting with abc.
!$
To execute the last word of the previous command.
ALT-
Last argument of the previous command.
!*
To get to all the arguments of the previous command.
^abc^123
This shortcut runs the previous command, replacing abc with 123.
Linux Bash Variables
Variables
Description
env
This one shows the environmental variables.
echo $NAME
This presents the output value of the $NAME variable.
export NAME=value
To set $ name to value.
$PATH
Executable search path.
$HOME
Variable is a Home directory.
$SHELL
variable for the current shell.
IO Redirection
Here, cmd refers to the command.
cmd< file
This command is the input of cmd from the file.
cmd1 <(cmd2)
This is for the output of cmd2 as file input to cmd1.
cmd>file
This command is for the standard output of cmd to file.
cmd> /dev/null
This command is to discard the standard out (stdout) of cmd.
cmd>> file
To add stdout to file.
cmd 2>file
This command is for the error output of cmd to file.
cmd1>&2
stdout to the same place as stderr.
cmd2>&1
stderr to the same place as stdout.
cmd&>file
Indicates the shortcut to every output to file.
Pipes
cmd1 |cmd2
stdout of cmd1 to cmd2
cmd1|&cmd2
stderr of cmd1 to cmd2.
Command lists
Commands
usage
cmd1; cmd2
To run cmd1, then cmd2.
cmd1 && cmd2
to run cmd2 if cmd1 is successful.
cmd1||cmd2
This command is to run cmd2 if cmd1 is not successful.
cmd &
To run cmd in a subshell.
Directory operations
pwd
It shows the current directory.
mkdir dir
To make directory dir.
cd dir
To change directory to dir.
cd ..
This is to go up a directory.
ls
To list files.
ls
-a
To show all the files including hidden one.
-R
For recursive list.
-r
To reverse the order.
-t
To sort by the last modified.
-S
This is to arrange by the file size.
-I
To form a long-lasting list format.
-l
This command is for one file per line.
-m
To get comma-separated output.
-Q
To get quoted output.
Search Files
Pattern files
Description
grep pattern files
To search for the pattern in files.
grep-i
This enables case-insensitive search.
grep-r
For recursive search.
grep-v
For inverted search.
grep0
This pattern shows the matched part of the file only.
find/dir/name name
This pattern finds files starting with the name in dir.
find/dir/ -user name
Find files owned by name in dir.
find/dir/=mmin num
To find files modified less than num minutes ago in dir.
whereis command
This one pattern is to find binary, source, manual for the command.
locate file
This command finds the files.
File operations
touch file1
Is to create file 1.
cat file 1file 2
To concatenate files and output.
less file 1
To view and paginate file 1.
file file1
This is to get a type of file 1.
cp file1 file2
To copy file 1 and file 2.
mv file1file2
This is to move file 1 to file 2.
rm file 1
For deleting file 1.
head file 1
This is to show the first 10 lines of file 1.
tail file 1
To show the last 10 lines of file 1.
tail -F file 1
This command outputs the last lines of file 1 as it changes1.
watch -n 5’ntpq -p’
This command issues the ‘ntpq -p’ command every 5 seconds and display the output.
Process Management
ps
This one displays the snapshot of processes.
top
Displays the show real-time processes.
kill pid
This kill process with id pid.
pkill name
To kill the process with name name.
killall name
This kills all processes with names beginning name.
Nano Shortcuts
Shortcut key
Used to
Ctrl-R
To read the file.
Ctrl-O
This is a shortcut is to save files.
Ctrl-X
Shortcut to close the file.
ALT-A
This shortcut is to start marketing text.
CTRL-K
To cut marked text or line.
CTRL-U
Shortcut to paste text
ALT-/
Navigation shortcut key to go to the end of the file.
CTRL-A
To navigate to the beginning of the file.
CTRL-E
Navigating shortcut key to the end of the line.
CTRL-C
To show line number.
CTRL-_
To go to line number.
CTRL-W
This shortcut is to find.
ALT-W
To find next
CTRL-\
Shortcut key to search and replace.
Screen shortcuts
screen
To start a screen session.
screen-r
To resume a screen session.
screen-list
Displays your current screen sessions.
CTRL-A
To activate commands for the screen.
CTRL-A c
Generate a new instance of terminal.
CTRL-A n
To go to the next instance of terminal.
CTRL-A p
This shortcut is to go to the previous instance of the terminal.
CTRL-A “
To show current instances of the terminal.
CTRL-A
To rename the current instance.
File permissions
chmod 775 file
To change the mode of a file to 775.
chmod -R 600 folder
For to recursively chmod folder to 600.
chown user group file
To change file owner to user and group to group.
File permission Numbers
4
This number is to read (r).
2
To write(w).
1
To execute (x).
In this article, we explained the basic Linux commands that are used commonly. Thank you for visiting this site.