Show Menu
Cheatography

Your Operating System cheat sheet

Vi Editor

i - insert at cursor (goes into insert mode)
ESC - Terminate insert mode
a - write after cursor (goes into insert mode)
u - undo last change
A - Write at the end of line (goes into insert mode)
U - undo all changes to the entire line
dd - delete line
o - open a new line (goes into insert mode
3dd - delete 3 lines
C - delete contents of a line after the cursor and insert new text
dw - delete word
r - replace character
4dw - delete 4 words
R - overwrite characters from cursor onward
cw - change word
s - substitute one character under cursor continue to insert
x - delete character at the cursor
S - Substitute entire line and begin to insert at the beginning of the line
~~ change case of individual character

Vi Editor - moving with a file

k - move cursor up
h - move cursor left
j - move cursor down
l - move cursor right

Vi Editor - Saving and Closing the file

Shift+zz: save the file and quit
:q - quit without saving
:w - save the file but keep it open
:wq - save the file and quit

Misc

> : send output to file or another device
>> : appends new file to an existing file
< : reverse redire­ction, takes input for program from existing file instead of keyboard
> : redire­ction, combined with system commands to achieve any desired results
!! : current history
wc : word count

Bash/Nano Shortcuts

Ctrl-c: stop current command
Ctrl-a: go to start of line
Ctrl-z: sleep program
Ctrl-e: go to end of line
Ctrl-u: cut from start of line
Ctrl-k: cut to end of line
Ctrl-R: read file
Ctrl-O: save file
Alt-A; start marking text
Ctrl-X: close file
Ctrl-K: cut marked text or line
Ctrl-U: paste text
ALT-/ End of file
CTRL-E: End of line
CTRL-A: Beginning of line
CTRL-C: Show line number
CTRL-W: Find
ALT-W: Find next
CTRL-\: Search and replace
 

User Inform­ation and Management

# Display the user and group ids of your current user.
# Display the last users who have logged onto the system.
id
last
# Show who is logged into the system.
# Show who is logged in and what they are doing.
who
w
# Create a group named "­tes­t".
# Create an account named john, with a comment of "John Smith" and create the user's home directory.
groupadd test
useradd -c "John Smith" -m john
# Delete the john account.
# Add the john account to the sales group
userdel john
usermod -aG sales john

System Inform­ation

#Display Linux system inform­ation
#Show system host name
uname -a
hostname
#Display kernel release inform­ation
# Display the IP addresses of the host
uname -r
hostname -I
# Show which version of redhat installed
#Show the current date and time date
cat /etc/r­edh­at-­release
date
# Who you are logged in as
# Display who is online
whoami
w
# Show this month's calendar
# Show system host name
cal
hostname

Search + SSH Logins

#Search for pattern in file: grep pattern file
# Search recurs­ively for pattern in directory: grep -r pattern directory
# Find files and direct­ories by name: locate name
# Find files in /home/john that start with "­pre­fix­": find /home/john -name 'prefix*'
# Find files larger than 100MB in /home: find /home -size +100M
# Connect to host as your local username: ssh host
# Connect to host as user: ssh user@host
# Connect to host using port: ssh -p port user@host
grep 'word' filename – Search any line that contains the word in filename on Linux
grep -i 'bar' file1 – A case-i­nse­nsitive search for the word ‘bar’ in Linux and Unix
grep -R 'foo' . – Search all files in the current directory and in all of its subdir­ect­ories in Linux for the word ‘foo’
grep -c 'nixcraft' frontp­age.md – Search and display the total number of times that the string ‘nixcraft’ appears in a file named frontp­age.md
 

File and Directory Commands

# List all files in a long listing (detailed) format
# Display the present working directory
ls -al
pwd
# Create a directory
# Remove (delete) file
mkdri directory
rm file
# Remove the directory and its contents recurs­ively
# Force removal of file without prompting for confir­mation
rm -r directory
rm -f file
# Forcefully remove directory recurs­ively
#Copy file1 to file2
rm -rf directory
cp file1 file2
# Copy source­_di­rectory recurs­ively to destin­ation. If destin­ation exists, copy source­_di­rectory into destin­ation, otherwise create destin­ation with the contents of source­_di­rec­tory.
# Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2
cp -r source­_di­rectory destin­ation
mv file1 file2
# Create symbolic link to linkname
# Create an empty file or update the access and modifi­cation times of file.
ln -s /path/­to/file linkname
touch file
# Display the first/last 10 lines of file
#View/­browse the contents of file
head line/tail line
cat file/less file
# Display the last 10 lines of file and "­fol­low­" the file as it grows.
tail -f file

File Attributes

user group/­other permis­sions - link account - user - group - filesize - date - filename
r : read, w : write, x - excute

Vi Editor 2

/ to find
\> : searches for the next word that ends with a specific string
[] : finds the characters between brackets
/< : searches for the next word that begins with a specific string
$: searches for the line that ends with a specific character
:! - leave vi tempo
:q - cancel an editing session
:wq - write changes to disk and exit vi
ZZ: in command mode, save changes and exit vi
u : undo most recent change

Vi Editor 2

/ to find
\> : searches for the next word that ends with a specific string
[] : finds the characters between brackets
/< : searches for the next word that begins with a specific string

Vi Editor 2

/ to find
\> : searches for the next word that ends with a specific string
[] : finds the characters between brackets
/< : searches for the next word that begins with a specific string
                       
 

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
          Windows Terminal Cheat Sheet
          Master Measures & Weights with this Cheat Sheet Cheat Sheet