Bash Command Reference
Navigation
cd: Change directory
ls: List directory contents
- Usage:
ls [options] [directory]
pwd: Print working directory
- Finding help:
cd --help
- Returning home:
cd ~
File Operations
touch: Create an empty file
cp: Copy files and directories
- Usage:
cp [options] [source] [destination]
mv: Move or rename files and directories
- Usage:
mv [options] [source] [destination]
rm: Remove files and directories
- Usage:
rm [options] [file/directory]
File Viewing and Editing
cat: Concatenate and display file content
less: Display file content one page at a time
head: Display the beginning of a file
- Usage:
head [options] [filename]
tail: Display the end of a file
- Usage:
tail [options] [filename]
nano: Text editor
File Permission Management
chmod: Change file permissions
- Usage:
chmod [options] [mode] [filename]
chown: Change file owner and group
- Usage:
chown [options] [owner:group] [filename]
Process Management
ps: Display information about processes
kill: Terminate processes
- Usage:
kill [options] [process_id]
Miscellaneous
echo: Display text
grep: Search for patterns in files
- Usage:
grep [options] [pattern] [file]
find: Search for files and directories
- Usage:
find [options] [path] [expression]
Help
man: Display manual pages for commands
Variables
name="John"
echo $name # see below
echo "$name"
echo "${name}!"
Quotes
name="John"
echo "Hi $name" #=> Hi John
echo 'Hi $name' #=> Hi $name
Functions
get_name() {
echo "John"
}
echo "You are $(get_name)"