Show Menu
Cheatography

Linux Commands & Options Cheat Sheet (DRAFT) by

NOS-120 Commands & Command Options (but for CPCC this time)

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Keyboard Shortcuts

Shortcut
What It Does
Notes
Esc + .
Insert last argument entered
Repeat to go back to previous arguments
Up Arrow
Auto-fill last command entered
Repeat to go back to previous commands
Ctrl+D
Logout / Exit
Ctrl+L
Clear terminal output
Ctrl+Shift+T
Open new terminal tab
Ctrl+Arrow (Right­/Left)
Move to beginn­ing/end of a word

Wildcards & Shortcuts

Wildcard
What It Represents
Example
~
Current user's home directory
.
The directory you're currently in
..
Parent directory of your current directory
*
All files in current directory
ls i*
= all files starting with "­i"
?
"Any charac­ter­"
f??e
matches anything with 4 characters that starts with "­f" & ends with "­e"
[aou]
Match to any one of the enclosed characters
c[aou]t
matches to "­cat­", "­cot­", and "­cut­"
!!
"Last command run" (inserts into current command)
sudo !!
= rerun command as root
^x^y
Rerun last command but replace x with y
ls /usr
followed by
^usr^tmp
will run
ls /tmp
!3
Rerun 3rd command from command history
!ls
Runs most recent command from history that had "­ls" in it

Important Direct­ories & Files

Directory/File
(Stands For) Purpose
/root
Root user's home directory
/home
Normal users' home direct­ories
/var
(Varia­bles) Database locations, spool files for mail, etc.
 
/usr
(User System Resources) System resources used by users
— /usr/bin
(Binaries) Execut­ables usable by normal users
— /usr/sbin
(System Binaries) Execut­ables only usable by root user
— /usr/lib
52-bit libraries
— /usr/lib64
64-bit libraries
 
/etc
(Extended Text Config­ura­tions) Config­uration files
— /etc/passwd
User account config files
— /etc/group
Group membership info & config files
— /etc/shadow
User password info & config files
— /etc/sudoers
Main file for sudo config
— /etc/sudoe­rs.d/
Destin­ation for sudo config "­dro­pping files"
— /etc/login.defs
Defines default properties used for new user accounts

vim Editor Controls

--- Command Mode ---
o
Starts new line and switches to Insert mode
cw
"­Change word" - deletes word and switches to Insert mode
G
Go to end of file
dd
Delete or cut entire line
yy
Copy entire line
p
Paste copied text
x
Delete character cursor is on top of
dw
Delete word cursor is on top of
d$
Delete from cursor to end of line
ZZ
Save & quit (existing files)
--- Extended Command Mode ---
:w filename
Save (new files)
:wq
Save & quit (existing files)
 

Misc. Commands

echo
date
+%F
+%R
+%s
tmux
ps -au
Show current processes & which user started them
ssh user@ip.address
-v
verbose; shows in detail what's happening while establ­ishing connection
-Y
enables graphical applic­ation support
-p port#
connect to ssh service not listening on default port 22

Basic File/D­ire­ctory Commands

ls dir1
List contents of dir1
-l
additional info (owner, perms, etc.)
-a
lists all, including hidden files
-i
adds file inode to info displayed
-d
info for directory itself (rather than its contents)
mkdir dir1
Create a new directory
-p
creates full path (multiple direct­ories if needed)
-v
verbose (output shows action taken)
cp dir1 dir2
 
Copy dir1 into dir2
-r
recurs­ively ("and its conten­ts")
 
rm dir1
Removes (deletes) an empty directory
-r
recurs­ively ("and it's conten­ts"), including special files
 
mv file1 dir1
Move file1 into dir1
-v
verbose (output shows action taken)
 
ln target link
Creates a hard link from file "­lin­k" to file "­tar­get­"
-s
makes a symbolic link instead of a hard link

Users & Groups

Command
Options
What It Does
id user1
Show UID, GID, & secondary groups
(current user if not specified)
getent passwd usr1
Find out if usr1 is known to the system
useradd user1
Add a new user
-u #
set a specific UID
 
-s /sbin/nologin
create a user without a login shell
usermod user1
Change properties of existing user
-c "text"
adds text to comment field
-g group1
changes primary group to group1
-G group1
replaces supple­mentary group with group1
-aG group1
appends group1 to supple­mentary groups
-L user1
locks user1's account (instead of deleting)
newgrp group1
Change current user's primary group
(temporary; current session only)
userdel user1
Deletes user1 but not their home directory
-r
deletes both user and home directory
groups user1
Displays simple list of groups user1 is a member of
passwd user1
Set password for user1
chage user1
Change password aging properties for user
-m days
minimum # of days between password changes
-M days
maximum # of days between password changes
-W days
warning period before password expires
-I days
inactivity period (password usable after expira­tion)
-d 0
require password change on next login
-E date
date when account expires
getent group grp1
Find out if grp1 is known to the system
groupadd group1
Create a new group
-g #
set a specific GID
-r
create a system group
groupmod group1
Change properties of existing group
-g #
change GID to specified number
To set the number of days from today when user's account expires:
chage -E $(date +days %Y-%m-%d)


To give full admin privileges to a user or group:
echo "[user1|%group1] ALL=(ALL) ALL" >> /etc/s­udo­ers.d/name