Here's a quick cheat sheet of some commonly used bash commands:
-
Navigating the file system
-
pwd
: Show the current working directory. -
ls
: List the files in the current directory. -
cd
: Change the current working directory. -
mkdir
: Create a new directory. -
rmdir
: Remove an empty directory. -
rm
: Remove a file or directory. -
mv
: Move or rename a file or directory. -
cp
: Copy a file or directory.
-
-
Manipulating files and directories
-
touch
: Create a new empty file. -
cat
: Display the contents of a file. -
head
: Display the first few lines of a file. -
tail
: Display the last few lines of a file. -
grep
: Search for a pattern in a file or a group of files. -
sed
: Edit files automatically. -
awk
: Process and analyze text files.
-
-
Environment Variables
-
export
: Set an environment variable. -
printenv
: Show all environment variables. -
env
: Show all environment variables.
-
-
Working with processes
-
ps
: Show running processes. -
kill
: Send a signal to a process to terminate it. -
top
: Show the processes using the most resources. -
htop
: Show the processes using the most resources with a interactive interface.
-
-
Working with shell
-
echo
: Output a message or the value of a variable. -
read
: Read input from the user and store it in a variable. -
if
: Perform actions based on the success or failure of a command. -
for
: Perform a set of commands for a list of items. -
while
: Perform a set of commands until a certain condition is met. -
until
: Perform a set of commands until a certain condition is met.
-
-
Working with Git
-
git init
: Initialize a git repository in the current directory. -
git status
: Show the status of the current repository. -
git add
: Add files to the next commit. -
git commit
: Create a new commit. -
git log
: Show the commit history. -
git diff
: Show the differences between commits. -
git branch
: List, create, or delete branches. -
git checkout
: Switch to a different branch or commit. -
git merge
: Merge one branch into another. -
git pull
: Fetch changes from a remote repository and merge them. -
git push
: Send changes to a remote repository.
-
This is not an exhaustive list and there are many other commands and options available in bash. But the above commands should be sufficient to get you started with basic shell scripting.
Top comments (1)
Useful ❤