Essential Linux and Git-GitHub Cheat Sheet for Quick Reference #Day-14
Table of contents
A "Quick Reference: Linux and Git-GitHub Cheat Sheet" is a handy guide designed to provide users with a compact and accessible summary of essential commands and workflows. For Linux, it typically includes fundamental commands for file management, navigation, process control, and system monitoring. For Git and GitHub, it outlines crucial commands for version control, including repository creation, commit management, branching, merging, and collaboration on GitHub. This cheat sheet serves as a valuable resource for developers, system administrators, and anyone working with these technologies, helping them efficiently perform common tasks without needing to search for documentation.
LINUX Commands
Navigation:
- ls: List files and directories in the current location.
Example: ls
Example: ls -a (for hidden files)
- cd: Change your current location (directory).
Example: cd /path/to/directory
- pwd: Show the current directory’s path.
Example: pwd
File Management:
- cp: Copy files or directories.
Example: cp file1.txt destination_folder_name
- mv: Move or rename files or directories.
Example: mv file.txt /path/to/destination/
Example: mv old_name.txt new_name.txt
- rm: Delete files or directories.
Example: rm file.txt
- touch: Create an empty file.
Example: touch new_file.txt
- chmod: Change file permissions.
Example: chmod 755 file.sh
- chown: Change file ownership.
Example: chown user:group file.txt
- cat: Display content of a file.
Example: cat file.txt
- grep: Search for a specific pattern in files.
Example: grep “pattern” file.txt
- find: Search for files and directories.
Example: find /path/to/search -name “file.txt”
- tar: Create or extract compressed archives.
Example (create): tar -cvf archive.tar files/
Example (extract): tar -xvf archive.tar
Directory Management:
- mkdir: Make a new directory.
Example: mkdir new_directory
- rmdir: Remove an empty directory.
Example: rmdir empty_directory
Process Management:
- ps: Display info about running processes.
Example: ps aux
- top: Show real-time system performance and resource usage.
Example: top
- kill: End a process.
Example: kill process_id
- bg: Shift a process to the background.
Example: bg
- fg: Bring a background process to the foreground.
Example: fg
System Information:
- uname: Show details about the operating system.
Example: uname -a
- df: Display disk usage information.
Example: df -h
- free: View memory usage details.
Example: free -m
- uptime: See how long the system has been running.
Example: uptime
- du: Show disk usage of a directory.
Example: du -h /path/to/directory
User Management:
- adduser: Add a new user.
Example: adduser new_user
- deluser: Remove a user.
Example: deluser old_user
- addgroup: Create a new group.
Example: addgroup new_group
- delgroup: Delete a group.
Example: delgroup old_group
- usermod: Modify a user account.
Example: usermod -aG new_group username
Package Management:
- apt-get: Manage packages on Debian-based systems.
Example (install): sudo apt-get install package_name
Example (update): sudo apt-get update
Example (remove): sudo apt-get remove package_name
- yum/dnf: Handle packages on Fedora-based systems.
Example (install): sudo dnf install package_name
Example (update): sudo dnf update
Example (remove): sudo dnf remove package_name
- pacman: Manage packages on Arch-based systems.
Example (install): sudo pacman -S package_name
Example (update): sudo pacman -Syu
Example (remove): sudo pacman -R package_name
GIT Commands
Starting a Repository:
- git init: Start a new Git repository.
Example: git init
- git clone: Copy a repository to a new directory.
Example: git clone https://github.com/example/repository.git
Making Changes:
- git add: Include changes in the staging area.
Example: git add file.txt
- git commit: Confirm changes to the repository.
Example: git commit -m “Commit message”
- git status: Display the status of changes as untracked, modified, or staged.
Example: git status
Branching:
- git branch: List all branches in the repository.
Example: git branch
- git checkout: Move to a different branch.
Example: git checkout branch_name
- git checkout -b: Create and move to a new branch.
Example: git checkout -b new_branch
- git merge: Combine changes from one branch into another.
Example: git merge branch_name
- git branch -d: Remove a branch.
Example: git branch -d branch_name
Remote Repositories:
- git remote: Show remote repositories.
Example: git remote
- git remote add: Include a remote repository.
Example: git remote add origin https://github.com/example/repository.git
- git pull: Fetch changes from a remote repository and merge them.
Example: git pull origin master
- git push: Upload changes to a remote repository.
Example: git push origin master
Viewing Changes:
- git log: Present commit history.
Example: git log
- git diff: Indicate changes between commits, the working directory, or branches.
Example: git diff
Undoing Changes:
- git reset: Cancel changes in the staging area.
Example: git reset file.txt
- git revert: Produce a new commit that undoes changes.
Example: git revert commit_hash
- git checkout — : Discard changes in the working directory.
Example: git checkout — file.txt
Other frequently used commands:
- git config: Adjust Git settings.
Example: git config — global user.name “Your Name”
- git tag: Make, display, or delete tags.
Example (create): git tag -a v1.0 -m “Version 1.0”
- git stash: Preserve changes that have not been committed.
Example: git stash
Conclusion
Mastering Linux and Git commands is essential for efficient system and version control management. This cheat sheet provides a quick reference to fundamental commands, helping users navigate, manage files, handle processes, and interact with repositories effectively. Whether you're a beginner or an experienced user, these commands will enhance your productivity and streamline your workflow. Keep this guide handy as you continue to explore and utilize the powerful capabilities of Linux and Git.
Connect and Follow:
Like ❤ | Share 📲 | Comment 💭
Subscribe to my newsletter
Read articles from Nikunj Vaishnav directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Nikunj Vaishnav
Nikunj Vaishnav
👋 Hi there! I'm Nikunj Vaishnav, a passionate QA engineer Cloud, and DevOps. I thrive on exploring new technologies and sharing my journey through code. From designing cloud infrastructures to ensuring software quality, I'm deeply involved in CI/CD pipelines, automated testing, and containerization with Docker. I'm always eager to grow in the ever-evolving fields of Software Testing, Cloud and DevOps. My goal is to simplify complex concepts, offer practical tips on automation and testing, and inspire others in the tech community. Let's connect, learn, and build high-quality software together! 📝 Check out my blog for tutorials and insights on cloud infrastructure, QA best practices, and DevOps. Feel free to reach out – I’m always open to discussions, collaborations, and feedback!