Skip to content

Linux Commands

List files and Navigate

Command Description
ls list files and directories in cwd
ls-R also list files in sub directories
ls-a also list hidden files
ls-al list files with detailed info like permissions and size
cd or cd~ go home
cd .. navigate up 1 level
cd <dir> navigate to
cd / navigate to root
history list of all past commands typed in terminal
clear clear terminal
man help on command
apt-get install/update (some) package
chsh change shell
printenv display all env variables (or env)
printenv <KEY> display value of env variable
export <KEY> set env variable (or unset)
sudo elevated privileges (superuser/root)
sudo ln -sf /bin/zsh bin/sh link shell to /bin/zsh (older)
sudo ln -sf /bin/dash bin/sh link shell to /bin/dash (newer)

R/W Files and Directories

Command Description
cat filename display file contents
cat < filename display file contents
cat file1 file2 display contents of multiple files
cat file1; cat file2 display contents of multiple files
cat song.text more display more (or less) of file content
cat -n filename display file with line numbers
cat -e filename display $ at the end of each line
cat -T filename display file with tabs replaced by ^I
cat > filename create new file
cat file > file2 overwrite file2 with output of file1
cat file >> file2 append to file2 output of file1
cat file1 file2 > file3 join file1 and file2 and store in file3
cat file1 file2 file3 sort > file4 save sorted content to file4
mv file path/to/location move file to new location
mf filename new_name rename file to new_name
rm filename remove file
mkdir dir_name create directory
rmdir delete directory
mv rename directory
pr -x divide file into x columns
pr -h assign header to file
pr -n denote file with line numbers
diff file1 file2 get diff of two files

File Permissions

Command Description
ls-l show file type and access permission
r read permission
w write permission
x execute permission
-= no permission
chown user change ownership of file/directory
chown user:group filename change user and group for a file/directory
chmod 777 <filename> set program rwx permissions (owner, group, other)
chmod 4755 <filename> change program to setuid

Printing

Command Description
lp -nc, lpr c print c copies of file
lp-d lp-P specifies name of the printer

Send Email

Send mail

1
 mail -s 'subject' -c 'cc-address' -b 'bcc-address' 'to-address'

Send mail with attachment

1
mail -s "Subject" to-address < Filename

User management

Command Description
sudo adduser username add new user
sudo passwd -l 'username' change pwd of user
sudo userdel -r 'username' remove newly created user
sudo usermod -a -G GROUPNAME add user to a group
sudo deluser USER GROUPNAME remove user from a group
finger show info of all users logged in
finger username show info on a specific user
su username substitute user
/usr/bin/passwd change current user password
cat /etc/shadow read user passwords
cat /etc/passwd lists all users

Env & Variables

Command Description
echo $VAR display value of variable
env display env variables
VAR_NAME=value create new variable
Unset Remove variable
export Variable=value set value of env variable

Networking

Command Description
SSH username@ip-address or hostname Login to remote linux machine using SSH
Ping hostname="" or="" ping or analyze connection
dir display files in current directory of remote computer
cd "dirname" change to "dirname" on remote computer
put file upload file from local to remote computer
get file download file from remote to local computer
quit logout

Processes

Command Description
bg send a process to the background
fg run stopped process in the foreground
top details on active processes
ps Give status of processes running for a user
ps PID Gives status of specified process
pidof Get process ID (PID) of a process
kill PID kill specified process
nice Start process with given priority
renice Change priority of a currently running process
df Gives (amount of?) free hard disk space on system
free Gives (amount of?) free RAM on system

VI Commands

Command Description
i Insert at cursor (goes into insert mode)
a Write after cursor (goes into insert mode)
A Write at the end of line (goes into insert mode)
ESC Terminate insert mode
u Undo last change
U Undo all changes to the entire line
o Open a new line (goes into insert mode)
dd Delete line
3dd Delete 3 lines
D Delete contents of line after the cursor
C Delete contents of a line after the cursor and insert new text. Press ESC key to end insertion.
dw Delete word
4dw Delete 4 words
cw Change word
x Delete character at the cursor
r Replace character
R Overwrite characters from cursor onward
s Substitute one character under cursor continue to insert
S Substitute entire line and begin to insert at the beginning of the line
~ Change case of individual character