A cheatsheet for Bash:
Basic Commands
ls
– List directory contentscd
– Change the current working directorymkdir
– Create a new directorytouch
– Create a new file or update the timestamp of an existing filecat
– Print the contents of a file to the screenecho
– Print a message to the screenpwd
– Print the current working directoryrm
– Remove a file or directorycp
– Copy a file or directory to a new locationmv
– Move or rename a file or directorychmod
– Change the permissions of a file or directory
Navigation
cd /path/to/directory
– Change directory to the specified pathcd ~
– Change directory to the home directorycd ..
– Change directory to the parent directorycd -
– Change directory to the previous directory
File Management
ls -a
– List all files, including hidden filesls -l
– List files with detailed informationls -lh
– List files with detailed information, including file size in human-readable formatrm -r
– Remove a directory and its contentscp -r
– Copy a directory and its contents to a new locationmv file.txt newfile.txt
– Rename a filemv /path/to/file.txt .
– Move a file to the current directory
Input/Output
>
– Redirect output to a file (overwrite)>>
– Redirect output to a file (append)<
– Redirect input from a file|
– Pipe output to another command
File Permissions
chmod +x file.sh
– Grant execute permission to a filechmod u+x file.sh
– Grant execute permission to the owner of a filechmod o-r file.txt
– Remove read permission from others for a file
Other Commands
man
– Display the manual page for a commandhistory
– Show a list of previously executed commandsgrep
– Search for a pattern in a file or outputfind
– Find files or directories that match a certain criteriawget
– Download a file from the internettar
– Compress or extract files from an archive
Wildcards
*
– Matches any sequence of characters?
– Matches any single character[]
– Matches any single character within the specified range
Environment Variables
echo $PATH
– Display the value of the PATH environment variableexport VAR=value
– Set an environment variableunset VAR
– Unset an environment variable
Processes
ps
– List running processeskill PID
– Send a signal to a process to terminate itpkill name
– Send a signal to all processes with a specific nametop
– Display real-time information about running processes
SSH
ssh user@host
– Connect to a remote host via SSHscp file user@host:/path
– Copy a file to a remote host via SSH
Text Editing
nano file.txt
– Open a file for editing in the Nano text editorvim file.txt
– Open a file for editing in the Vim text editorsed 's/old/new/g' file.txt
– Replace all occurrences of a string in a file
Networking
ping host
– Send a ping to a host to test network connectivityifconfig
– Display network interface configurationnetstat
– Display network connections and routing tablesroute
– Display or modify the system’s routing table
Job Control
jobs
– Display a list of current jobsbg
– Move a job to the backgroundfg
– Bring a job to the foregroundctrl + c
– Interrupt a running commandctrl + z
– Suspend a running command
This is just a small selection of the many commands available in Bash. With these tools at your disposal, you can navigate the file system, manage processes, edit files, and much more. As you become more familiar with Bash, you’ll discover new commands and techniques that can help you work more efficiently and productively.