-
Notifications
You must be signed in to change notification settings - Fork 3
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
i
to enter insert mode (for editing). - Press
Esc
to exit insert mode. - To save changes and exit:
:wq
while not in insert mode. - To exit without saving:
:q!
while not in insert mode.
-
chmod permissions filename
: Change file permissions. - Example:
chmod +x script.sh
makes 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.txt
searches 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.