-
Notifications
You must be signed in to change notification settings - Fork 5
1.1 Bash Cheat Sheet
Antoine Dangeard edited this page Jan 6, 2024
·
1 revision
-
pwd: Print the current working directory. -
ls: List files and directories in the current directory. -
ls -l: Detailed list with file permissions and sizes. -
ls -a: Show hidden files. -
cd: Change directory. -
cd ..: Move up one directory. -
cd ~: Navigate to the home directory. -
cd /path/to/directory: Navigate to a directory using absolute path. -
cd path/to/directory: Navigate to a directory using relative path. -
mkdir directoryname: Create a new directory.
-
vim <filename>: Open a file in the Vim text editor. - Press
ito enter insert mode (for editing). - Press
Escto exit insert mode. - To save changes and exit:
:wqwhile not in insert mode. - To exit without saving:
:q!while not in insert mode.
-
chmod permissions filename: Change file permissions. - Example:
chmod +x script.shmakes a script executable.
-
echo $VARIABLE: Display the value of an environment variable. -
export VARIABLE=value: Set an environment variable. -
unset VARIABLE: Remove an environment variable.
- .bashrc is a script executed every time you start a new Bash session (i.e. a new terminal tab).
- Useful to run scripts that set environment variables for new terminals.
-
grep pattern filename: Search for a regex pattern in a file. - Example:
grep "error" log.txtsearches for "error" in log.txt. - Piping (
|): Send the output of one command as input to another. - Example:
ls | grep "file"only lists files containing "file" in their names.
-
*: Matches any characters (e.g., *.txt matches all .txt files). -
?: Matches a single character.