Show Menu
Cheatography

Bash Cheat Sheet (DRAFT) by

asddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd

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

File Commands

ls
List files in the directory
ls -a
List files, include hidden files
pwd
Show current directory
mkdir [name]
Create a directory
rm [file]
Remove a file
rm -r [direc­tory]
Recurs­ively remove directory
rm -rf [direc­tory]
Force remove directory
cp [file1] [file2]
Copy file1 to file2
cp -r [direc­tory1] [direc­tory2]
Copy directory1 to directory2
mv [filen­ame1] [filen­ame2]
Rename a file
touch [file]
Create a new file
more [file]
Show file contents
head [file]
Show first 10 lines of a file
tail [file]
Show last 10 lines of a file
shred -u [file]
Overwrite and delete a file
ls | xargs wc
Words/­lin­es/­bytes in directory
diff [file1] [file2]
Compare two files

File Permission

chmod 777 [file]
File read, write, execute permis­sions to everyone
chmod 755 [file]
Full permission to owner, read permis­sions for others
chmod 766 [file]
Full permission to owner, read and write for others
chown [user] [file]
Change file ownership
chown [user]­:[g­roup] [file]
Change file owner and group

Process Management

ps
Display your currently active processes
pmap
Show process memory usage
top
Display all running processes
kill [proce­ss_id]
Kill the process by ID
pkill [proce­ss_­name]
Kill the process by name
killall [proce­ss_­name]
Kill all processes by name
bg
List background processes
fg
Most recent suspended job to foreground

Keyboard Shortcuts

Ctrl + C
Kill current process
Ctrl + Z
Stop process (can be resumed)
Ctrl + W
Cut the word before the cursor
Ctrl + U
Cut part of the line before the cursor
Ctrl + K
Cut part of the line after the cursor
Ctrl + Y
Paste from clipboard
Ctrl + R
Recall last command
Ctrl + O
Run the recalled command
Ctrl + G
Exit command history
!!
Repeat the last command
exit
Log out of the session
 

Directory Navigation

cd ..
Move up one level
cd
Change directory to $HOME
cd [/loca­tion]
Change to a specified directory

Users and Groups

id
Show active user details
last
Show last system logins
who
Show who is logged in
w
Show logged users and activity
groupadd [group]
Add a new group
adduser [user]
Add a new user
usermod -aG [group] [user]
Add user to group
userdel [user]
Delete a user
usermod
Modify user inform­ation
chgrp [group] [direc­tory]
Change directory group

System Management and Info

uname -r
Show system inform­ation
uname -a
Show kernel release info
uptime
Show uptime length­/avg. load
hostname
Show system hostname
hostname -l
Show system IP address
last reboot
Show reboot history
date
Show current time and date
cal
Show current day and month
whoami
Show the current user
finger [username]
Show user inform­ation
shutdown [hh:mm]
Schedule a system shut down
df
Show disk usage
du
Show directory space usage
free
Show memory and swap usage
whereis app
Show possible locations of app
which app
Show which app will be run by default

Shell Command Management

alias [alias­]='­[co­mmand]'
Create command alias
watch -n [interval] [command]
Set interval to run a command
sleep [interval] && [command]
Postpone command execution
at [hh:mm]
Schedule a job
man [command]
Display command manual
history
Print command history