Show Menu
Cheatography

Learning Linux Command Line Cheat Sheet by

Cheat sheet for the LinkedIN course about Linux Command Line

General Command Syntax

Command
Option(s)
Argume­nt(s)
ls
-ahl
/usr/bin
sort
-u
users.txt
grep
-i "­nee­dle­"
heystack
Commands are programs that take a particular action
Options tell the command how to operate
Arguments tell the command what to operate on

Finding Help for Commands

man
argument
argument
--help
apropos
functionality search

Useful Keyboard Shortcuts

Tab
Tab completion
Ctrl - A
Move to beginning of line
Ctrl - E
Move to end of line
Ctrl - Left arrow
Move left one word
Ctrl - Rig arrow
Move right one word
Ctrl - U
Delete from cursor to line start
Ctrl - K
Delete from cursor to line end
Ctrl - Shift - C
Copy selected text to clipboard
Ctrl - Shift - V
Paste text from clipboard
Up arrow
Recall previous command
Down arrow
Scroll previous command
Ctrl - R
Search command history
Ctrl - C
Cancel command

Commands for File Inform­ation

Command
Option(s)
Argume­nt(s)
Descri­ption
file
 
argument
Determine file type
stat
 
argument
Display file status

Notable File System Direct­ories

/
File system root
/home
User home direct­ories
/root
Root user's home directory
/etc
Common config­uration files
/bin, /sbin
Common programs or commands
/lib
Shared libraries and modules
/mnt, /media
Standard location for mounting other file systems
/dev, /proc, /sys
Kernel and system inform­ation

Paths in Linux

/
Absolute path
.
Current working directory
..
Parent directory
~
Current user's home directory
\ - space
Equivalent to space key

The File System

cd
Change the shell working directory
pwd
Print the name of File system root: / User home direct­ories: /home Root user's home directory: /root
ls

The File System

Command
Option(s)
Argume­nt(s)
Descri­ption
cd
available
new directory
Change the shell working directory
pwd
available
 
Print the name of the current working directory
ls
-lh
directory
List inform­ation about the files

Working with Direct­ories and Files

Command
Option(s)
Argume­nt(s)
Descri­ption
mkdir
available
direct­ory­(ies)
Create the direct­ory­(ie­s)C­reate the direct­ory­(ies)
rmdir
available
direct­ory­(ies)
Remove the direct­ory­(ies), if they are empty
cp
available
source - destin­ation
Copy source to destin­ation
mv
available
source - destin­ation
Move source to destin­ation
rm
-r
file(s)
Remove the file(s) (recur­sively)
find
-name
directory - "­exp­res­sion*?
Find directory or file by name

Search for Text

Command
Option(s)
Argume­nt(s)
Descri­ption
grep
options
"­pat­tern*? file name
Search for patterns in file

Tools for Text

Command
Option(s)
Argume­nt(s)
Descri­ption
cat
available
file name
Concat­enate to standard output
head
available
file name
Print the first number of something
tail
available
file name
Print the last number of something

Tools for Working with Text

Command
Descri­ption
awk
Often used to extract specific text from a file according to rule
sed
Often used to modify text in a command pipeline or in place
sort
Often used to sort text
Vim and nano are very popular text editors in CLI
 

Hard and Symbolic Links

Command
Option(s)
Argume­nt(s)
Descri­ption
ln
-s
source file link name
Creates a soft link
ln
 
source file link name
Creates a hard link
- A hard link points to specific data (by inode) on the disk
- A soft link or symbolic link (symlink) points to another file

File Permis­sions

User
Group
Others
Descri­ption
rwx
rwx
rwx
Up to three letters indicate the permis­sions for the file or directory
 
Command
Option(s)
Argume­nt(s)
Descri­ption
chmod
octal or symbolic change
file or directory
Changes the mode of the file or directory
chown
new owner
file or directory
Changes the owner of the file or directory
chgrp
new group
file or directory
Changes the group of the file or directory
r: read (value of 4)
w: write (value of 2)
e: execute (value of 1)

u: user
g: group
o: others
a: all

Two methods to represent permis­sions:
- Octal (like 755, 644, 777)
- Symbolic (like a=r, g+w, and o-x)

Tape Archives and Data Compre­ssion

Command
Option(s)
Argume­nt(s)
Descri­ption
tar
-cvf
file name.tar directory
Creates a tape archive
tar
-caf
file name.tar.g­z/t­ar.bz2 directory
Creates a compressed tape archive, the compre­ssion type depends on the extension
tar
-xf
file name -C target directory
Extracts a compressed tape archive inside a certain directory
zip
-r
file name directory to compress
Compresses a directory
unzip
 
file name -d target directory
Extracts a directory
Formats for compressed .tar files are: .tar.gz, .tgz, .tar.bz2

Superuser Rights

sudo + command
Executes the command with superuser rights (requires user password)
sudo + -s
Activates superuser rights for a period of time
sudo + -k
Gives up superuser rights

Enviro­nment Variables and PATH

env
Set some attributes in the enviro­nment
which
Locate a command
~/.bas­h_p­rofile
Bash profile (create with command nano)
Inside nano, write:
PATH = "­$PATH : /my/cu­sto­m/path : /some/­oth­er/­pat­h"

Redire­ction

Stream
Number
Usage
Standard Input (stdin)
0
Text input
Standard Output (stdout)
1
Text output
Standard Error (stderr)
2
Error text
 
command
number>
file name
Redirects the output to the file
command
number>>
file name
Appends the output to the file

Inform­ation About Linux Distri­bution & Hardware

Command
Descri­ption
ls -l /etc/*­release
List of the files that contain inform­ation about the release
cat /etc/*­release
Shows inform­ation about the two files in the release folder
uname -a
Show inform­ation about Linux Kernel
uname -r
Shows only the version of the Linux Kernel
free -h
Shows how much memory the system has
cat /proc/­cpuinfo
Shows how much CPU the system has
lscpu
Shows more compre­hensive inform­ation about the system's CPU
df -h
Shows how much storage the system has

Install and Update Software

apt search search
Looks for packages whose descri­ption match the search term
apt show package
Displays inform­ation about the package
sudo apt update
Retrieve an updated list of the packages from the reposi­tories before installing new software or upgrading the software package
sudo apt install package
Install the package
sudo apt upgrade
Upgrade the software package
       
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Linux Command Line Cheat Sheet
          Tmux basics Cheat Sheet
          Windows Terminal Cheat Sheet