Day13 of #90DaysofDevOps: Linux & Git-GitHub Cheat Sheet

Β·

4 min read

🌟 LINUX COMMANDS CHEAT SHEET 🌟

File and Directory Navigation:

  1. pwd
    Print Working Directory
    Displays the current directory path.

  2. ls [options]
    List Directory Contents
    Lists files and directories in the current location. Options:

    • -a β†’ Show hidden files.

    • -l β†’ List in long format with detailed info.

  3. cd [directory]
    Change Directory
    Navigates to the specified directory.

    • cd .. β†’ Move up one directory level.
  4. mkdir [directory_name]
    Make Directory
    Creates a new directory.

  5. rmdir [directory_name]
    Remove Directory
    Deletes an empty directory.

  6. rm [file]
    Remove File
    Deletes a file or directory.

    • -r β†’ Remove directories and contents recursively.

πŸ“ File Manipulation:

  1. touch [filename]
    Create a File
    Creates an empty file.

  2. cat [file]
    Concatenate Files and Output Content
    Displays content of a file or concatenates multiple files.

  3. cp [source] [destination]
    Copy Files
    Copies a file or directory from source to destination.

  4. mv [source] [destination]
    Move or Rename Files
    Moves or renames a file/directory.

  5. nano [file]
    Edit Files
    Opens the file in a simple text editor (Nano).

  6. vim [filename]
    Open File in Vim Editor
    Opens the specified file in the Vim text editor. If the file doesn't exist, Vim will create a new file with the given name.

  1. find [directory] -name [filename]
    Find Files by Name
    Searches for files matching the name in the specified directory.

  2. grep [pattern] [file]
    Global Regular Expression Print
    Searches for a specific pattern within a file.

🚦 Permissions and Ownership:

  1. chmod [permissions] [file]
    Change File Permissions
    Changes the permissions of a file (e.g., chmod 755 script.sh).

  2. chown [owner]:[group] [file]
    Change File Owner/Group
    Changes the owner and group of a file.

  3. usermod -aG [groupname] [username]

    command can be used to add a user to one or more groups.

    • -a: Append the user to the specified group(s). This option is critical when adding the user to additional groups without removing them from their existing groups.

    • -G: Specifies the group(s) the user will be added to. Multiple groups can be specified by separating them with commas.

βš™οΈ System Information:

  1. df -h
    Disk Free Space
    Displays disk space usage.

  2. top
    Task Manager
    Shows running processes and system resource usage.

  3. uname -a
    Display System Information
    Print system information

⌨️ Package Management:

  1. apt update
    Update Package List
    Updates the package list on Debian-based systems.

  2. apt upgrade
    Upgrade Installed Packages
    Installs the latest versions of all packages.

πŸ› οΈ GIT & GITHUB COMMANDS CHEAT SHEET πŸ› οΈ

🌱 Initial Setup:

  1. git config --global user.name "Your Name"
    Set Username
    Configures the Git username for commits.

  2. git config --global user.email "mail@example.com"
    Set Email
    Configures the Git email address for commits.

  3. git init
    Initialize Git Repository
    Creates a new Git repository in the current directory.

πŸ“‚ Working with Repositories:

  1. git clone [repository_url]
    Clone a Repository
    Downloads an existing repository from a URL.

  2. git status
    Check Status
    Displays the state of the working directory (untracked, modified, staged files).

  3. git add [file]
    Stage Changes
    Adds changes in the file(s) to the staging area for the next commit.

  4. git commit -m "Commit message"
    Commit Changes
    Commits the staged changes with a message.

  5. git push [remote] [branch]
    Push Changes to Remote
    Sends commits from your local repository to the remote repository.

  6. git pull [remote] [branch]
    Pull Changes from Remote
    Fetches and merges changes from the remote repository.

πŸ› οΈ Branching and Merging:

  1. git branch
    List Branches
    Lists all branches in the repository.

  2. git branch [branch_name]
    Create New Branch
    Creates a new branch.

  3. git checkout [branch_name]
    Switch Branches
    Create a New Branch and Switching to It.

  4. git merge [branch_name]
    Merge Branch
    Merges changes from the specified branch into the current branch.

  5. git rebase [branch_name]
    Rebase Branch
    Reapplies commits on top of another base tip.

πŸ”§ Undo Changes:

  1. git reset [file]
    Unstage a File
    Removes the file from the staging area without deleting changes.

  2. git reset --hard [commit]
    Reset to a Specific Commit
    Resets your working directory and index to a specific commit, deleting all newer commits.

  3. git revert [commit]
    Revert Commit
    Creates a new commit that undoes changes made by a previous commit.

πŸ“¦ GitHub Integration:

  1. git remote add origin [repository_url]
    Link Repository to GitHub
    Links the local repository to the remote GitHub repository.

  2. git push origin [branch_name]
    Push to GitHub
    Pushes the changes to the specified branch on GitHub.

  3. git fetch
    Fetch Changes
    Retrieves new changes from the remote without merging them.


Stay tuned for more insights as I continue my #90DayOfDevOps challenges. If you have any questions or tips, feel free to share them in the comments.

Let’s keep learning and growing together! πŸš€

Β