Day12 of #90daysofdevops | Linux and Git cheat sheet

Rahul TRahul T
4 min read

Linux commands

1. File and Directory Operations:

  • ls: List files and directories.

  • cd: Change directory.

  • pwd: Print the working directory.

  • mkdir: Create a new directory.

  • rm: Remove files or directories. (Use with caution!)

  • cp: Copy files or directories.

  • mv: Move or rename files or directories.

  • touch: Create an empty file.

  • cat: Concatenate and display file content.

  • nano or vim: Text editors for creating/editing files.

  • find: Search for files and directories.

2. File Permissions:

  • chmod: Change file permissions.

  • chown: Change file ownership.

  • chgrp: Change group ownership.

  • umask: Set default permissions for new files and directories.

3. User and Group Management:

  • useradd: Create a new user.

  • usermod: Modify user properties.

  • userdel: Delete a user.

  • groupadd: Create a new group.

  • groupmod: Modify group properties.

  • groupdel: Delete a group.

4. Process Management:

  • ps: Display running processes.

  • top: Monitor real-time system activity.

  • kill: Terminate processes.

  • killall: Kill processes by name.

  • bg: Put a process in the background.

  • fg: Bring a process to the foreground.

5. System Information:

  • uname: Display system information.

  • df: Show disk space usage.

  • free: Display free and used memory.

  • du: Estimate file and directory space usage.

6. Networking:

  • ifconfig or ip: Display network configuration.

  • ping: Check network connectivity.

  • netstat: Network statistics.

  • ssh: Securely connect to remote servers.

  • scp: Securely copy files between local and remote systems.

  • wget or curl: Download files from the web.

  • nslookup or dig: DNS-related commands.

7. Package Management:

  • apt (Debian/Ubuntu) or yum (CentOS/RHEL): Install, update, and manage software packages.

  • dpkg (Debian/Ubuntu) or rpm (CentOS/RHEL): Direct package management.

8. File Compression and Archiving:

  • tar: Create and extract tar archives.

  • gzip, bzip2, xz: Compress and decompress files.

9. System Maintenance:

  • reboot: Reboot the system.

  • shutdown: Shutdown the system.

  • cron: Schedule tasks to run at specified times.

  • journalctl: View system logs.

10. File System Management:

  • mount and umount: Mount and unmount filesystems.

  • fsck: File system check and repair.

Git commands

  1. Git Configuration:
  • git config --global user.name "Your Name": Set your username globally.

  • git config --global user.email "youremail@example.com": Set your email globally.

  • git config --global core.editor "editor": Set your preferred text editor for commit messages.

  1. Creating and Cloning Repositories:
  • git init: Initialize a new Git repository in the current directory.

  • git clone <repository-url>: Clone a remote repository to your local machine.

  1. Basic Git Workflow:
  • git status: View the status of your working directory and staged changes.

  • git add <file>: Stage changes for the next commit. Use git add . to add all changes.

  • git commit -m "Your commit message": Commit staged changes with a descriptive message.

  • git push origin <branch-name>: Push commits to a remote repository on a specific branch.

  • git pull origin <branch-name>: Pull changes from a remote repository to your local branch.

  • git fetch: Fetch changes from the remote repository without merging.

  1. Branching and Merging:
  • git branch: List all branches in the repository. The current branch is highlighted with an asterisk.

  • git branch <branch-name>: Create a new branch with the specified name.

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

  • git checkout -b <new-branch-name>: Create a new branch and switch to it in one command.

  • git merge <branch-name>: Merge the specified branch into the current branch.

  • git rebase <branch-name>: Rebase the current branch onto the specified branch.

  1. Viewing and Comparing Commits:
  • git log: View the commit history.

  • git log --oneline: View the commit history in a simplified one-line format.

  • git show <commit-hash>: Show the details of a specific commit.

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

  • git diff --cached: View the changes between the staging area and the last commit.

  1. Undoing Changes:
  • git reset <file>: Unstaged changes from the staging area.

  • git reset --hard: Discard all changes and revert to the last commit.

  • git revert <commit-hash>: Create a new commit that undoes the changes introduced by the specified commit.

  1. Remote Repositories:
  • git remote add <remote-name> <remote-url>: Add a new remote repository.

  • git remote -v: List all remote repositories.

  • git push --set-upstream origin <branch-name>: Set the upstream branch for pushing and pulling.

  • git pull --rebase: Pull changes and rebase the current branch instead of merging.

  1. Miscellaneous:
  • git stash: Stash your current changes to work on them later.

  • git stash list: List all stashed changes.

  • git stash apply: Apply the most recent stashed changes.

  • git clean -n: Preview untracked files that will be removed with git clean -f.

  • git blame <file>: Show the author and commit information for each line in a file.

Tip to remember:

Always be cautious when using administrative commands, especially those related to file deletion or system configuration. Double-check commands before executing them, and have proper backups in place.

Thanks for reading the blog & do share them with someone in need :)

Please share your views and suggestions, they are always welcome.

See you then in the next blog.

Happy learning :)

0
Subscribe to my newsletter

Read articles from Rahul T directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rahul T
Rahul T

In the exciting realm of DevOps, I am enthusiastic about embracing the culture, methodologies, and technologies that drive successful software delivery. With a commitment to lifelong learning and a passion for problem-solving, I am ready to embark on this journey as an aspiring DevOps engineer, making a positive impact and helping organizations achieve their technological goals.