Bash Command Reference
This document provides a concise reference to common Bash commands that are useful in command line operations.
rm
: Removes files or directories.- Usage:
rm example.txt
(removesexample.txt
) - Usage:
rm -rf directory_name
(recursively removesdirectory_name
and its contents)
- Usage:
cd
: Changes the current directory.- Usage:
cd my_directory
(navigates tomy_directory
)
- Usage:
mkdir
: Creates a new directory.- Usage:
mkdir new_directory
(createsnew_directory
)
- Usage:
ls
: Lists all files and directories in the current directory.- Usage:
ls
- Usage:
ls -la
: Lists all files and directories in the current directory, including hidden ones, and provides detailed information.- Usage:
ls -la
- Usage:
cp
: Copies files or directories.- Usage:
cp file.txt new_location
(copiesfile.txt
tonew_location
) - Usage:
cp -r directory_name new_location
(recursively copiesdirectory_name
and its contents tonew_location
)
- Usage:
grep
: Searches for a specific pattern in files.- Usage:
grep "example" file.txt
(searches for "example" infile.txt
)
- Usage:
history
: Displays the command history.- Usage:
history
- Usage:
cat
: Displays the content of a file.- Usage:
cat file.txt
(displays content offile.txt
)
- Usage:
|
: Pipes the output of one command as input to another command.- Usage:
ls | grep "pattern"
(lists all files in the current directory and searches for "pattern" in the output)
- Usage:
sudo
: Runs a command with elevated privileges.- Usage:
sudo brew install package_name
(installs a package usingbrew
with root privileges)
- Usage:
su
: Switches to the root account to perform administrative tasks.- Usage:
su
(switches to the root account after entering the root password)
- Usage:
Note: Exercise caution when using these commands. Always double-check before executing any commands that may have irreversible effects.