๐Ÿ“‹ Day 17: Linux and Git/GitHub Cheat Sheet

#Day14ofDevOpsBlog

ยท

4 min read

๐Ÿ“‹ Day 17: Linux and Git/GitHub Cheat Sheet

Finally!! ๐ŸŽ‰

You have completed the Linux & Git-GitHub hands-on tasks, and I hope you have learned something interesting from it. ๐Ÿ™Œ

Now, let's create an interesting ๐Ÿ˜‰ blog that will benefit the DevOps community!

๐Ÿ’ป Linux Commands Cheat Sheet

๐Ÿ“‚ File and Directory Operations

  • ls: List files and directories in the current directory.

  • cd <directory>: Change the current directory.

  • pwd: Print the current working directory.

  • mkdir <directory>: Create a new directory.

  • rmdir <directory>: Remove an empty directory.

  • touch <file>: Create an empty file or update the timestamp of an existing file.

  • cp <source> <destination>: Copy files or directories.

  • mv <source> <destination>: Move or rename files or directories.

  • rm <file>: Remove files.

  • cat <file>: View the content of a file.

๐Ÿ“ File Permissions

  • chmod <permissions> <file>: Change file or directory permissions (e.g., chmod 777 <file>).

  • chown <user>:<group> <file>: Change the owner and group of a file.

๐Ÿ”Ž Viewing and Searching

  • cat <file>: Display the contents of a file.

  • less <file>: View the content of a file page by page.

  • grep <pattern> <file>: Search for a specific pattern in a file.

  • find <directory> -name <filename>: Search for a file by name in a directory.

๐Ÿ–ฅ System Monitoring

  • top: Display real-time system processes.

  • ps: Display currently running processes.

  • df -h: Show disk space usage in a human-readable format.

  • free -m: Display memory usage in megabytes.

๐ŸŒ Networking

  • ifconfig: Display network interfaces and IP addresses.

  • ping <host>: Send ICMP echo requests to check connectivity to a host.

  • netstat: Display network connections, routing tables, and interface statistics.

๐Ÿ“ฆ Package Management

  • apt update: Update package list (Debian/Ubuntu).

  • apt upgrade: Upgrade installed packages (Debian/Ubuntu).

  • yum update: Update packages (CentOS/RHEL).

  • yum install <package>: Install a package (CentOS/RHEL).

๐Ÿ”„ Process Management

  • kill <PID>: Terminate a process by PID.

  • killall <process_name>: Terminate all processes with a specific name.

  • nice -n <priority> <command>: Run a command with a specific priority.

๐Ÿ›  Shell Scripting

  • nano <script.sh>: Edit a script file using the Nano text editor.

  • ./script.sh: Execute a shell script.

  • echo "text": Print text to the terminal.

๐Ÿ“‚ Archiving and Compression

  • tar -cvf <archive.tar> <files>: Create a tar archive.

  • tar -xvf <archive.tar>: Extract a tar archive.

  • gzip <file>: Compress a file using gzip.

  • gunzip <file.gz>: Decompress a gzip file.

โš™๏ธ For more advanced commands, like AWK, GREP and SED, please refer my Advanced Linux blog :)


๐Ÿ›  Git and GitHub Commands Cheat Sheet

๐ŸŒฑ Getting Started with Git

  • git init: Initialize a new Git repository in the current directory.

  • git config --global user.name <Name> and git config --global user.email <Email>: Used to configure git and to help it recognize out machine.

  • git clone <repo_url>: Clone a repository into a new directory.

๐Ÿ“‚ Working with Files

  • git add <file>: Add a file to the staging area.

  • git add .: Add all changes in the current directory to the staging area.

  • git commit -m "message": Commit changes in the staging area with a descriptive message.

  • git status: Show the working tree status.

  • git diff: View changes between the working directory and the staging area.

๐Ÿ” Viewing History

  • git log: Show the commit history.

  • git log --oneline: Show the commit history in a condensed, one-line format.

๐Ÿ”„ Undoing Changes

  • git restore <file_name>: Discard changes in the working directory.

  • git reset <file_name>: Unstage a file without losing its changes. Not recommended to do.

  • git revert <commit_hash>: Create a new commit that undoes the changes of a specific commit.

๐ŸŒฟ Branching

  • git branch: List branches.

  • git branch <branch_name>: Create a new branch.

  • git checkout <branch_name>: Switch to an existing branch.

  • git switch <branch_name>: Another way to switch branches.

๐Ÿ”— Merging & Rebase

  • git merge <branch_name>: Merge a branch into the current branch.

  • git rebase <branch_name>: Reapply commits from the current branch onto another branch.

๐Ÿ”„ Syncing with Remote

  • git remote add origin <repo_url>: Add a remote repository.

  • git push origin <branch_name>: Push changes to the remote repository.

  • git pull origin <branch_name>: Fetch and merge changes from the remote repository.

๐Ÿ“‚ GitHub Basics

  • git fork: Create a copy of a repository on your GitHub account.

  • git clone <forked_repo_url>: Clone the forked repository.

  • git push origin <branch_name>: Push changes to your forked repository.

  • Pull Request (PR): After pushing changes to GitHub, create a PR to merge changes into the original repository.

๐Ÿ”— Github Advanced commands

  • git cherry-pick <commit_id>: Used to merge a particular commit from one branch to another rather than merging the complete branch.

  • git stash <branch_name>: Reapply commits from the current branch onto another branch.

๐Ÿ”‘ SSH Setup

  • ssh-keygen -t rsa -b 4096 -C "your_email@example.com": Generate a new SSH key.

  • eval "$(ssh-agent -s)": Start the SSH agent.

  • ssh-add ~/.ssh/id_rsa: Add your SSH private key to the agent.


This bog covers the essentials of working with Linux, Git and GitHub, focusing on the most frequently used commands. ๐Ÿ“. I hope this helps, for any queries please feel free to reach me out on Linkedin :)

ย