Handfull of commands for more than 80% of command line tasks.

jindalanuj

Anuj Jindal

Posted on January 17, 2023

Handfull of commands for more than 80% of command line tasks.

Here's a quick cheat sheet of some commonly used bash commands:

  1. 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.
  2. 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.
  3. Environment Variables
    • export: Set an environment variable.
    • printenv: Show all environment variables.
    • env: Show all environment variables.
  4. 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.
  5. 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.
  6. 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.

💖 💪 🙅 🚩
jindalanuj
Anuj Jindal

Posted on January 17, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related