Day13 of #90DaysofDevOps: Linux & Git-GitHub Cheat Sheet
π LINUX COMMANDS CHEAT SHEET π
File and Directory Navigation:
pwd
Print Working Directory
Displays the current directory path.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.
cd [directory]
Change Directory
Navigates to the specified directory.cd ..
β Move up one directory level.
mkdir [directory_name]
Make Directory
Creates a new directory.rmdir [directory_name]
Remove Directory
Deletes an empty directory.rm [file]
Remove File
Deletes a file or directory.-r
β Remove directories and contents recursively.
π File Manipulation:
touch [filename]
Create a File
Creates an empty file.cat [file]
Concatenate Files and Output Content
Displays content of a file or concatenates multiple files.cp [source] [destination]
Copy Files
Copies a file or directory from source to destination.mv [source] [destination]
Move or Rename Files
Moves or renames a file/directory.nano [file]
Edit Files
Opens the file in a simple text editor (Nano).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.
π File Search:
find [directory] -name [filename]
Find Files by Name
Searches for files matching the name in the specified directory.grep [pattern] [file]
Global Regular Expression Print
Searches for a specific pattern within a file.
π¦ Permissions and Ownership:
chmod [permissions] [file]
Change File Permissions
Changes the permissions of a file (e.g.,chmod 755
script.sh
).chown [owner]:[group] [file]
Change File Owner/Group
Changes the owner and group of a file.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:
df -h
Disk Free Space
Displays disk space usage.top
Task Manager
Shows running processes and system resource usage.uname -a
Display System Information
Print system information
β¨οΈ Package Management:
apt update
Update Package List
Updates the package list on Debian-based systems.apt upgrade
Upgrade Installed Packages
Installs the latest versions of all packages.
π οΈ GIT & GITHUB COMMANDS CHEAT SHEET π οΈ
π± Initial Setup:
git config --global
user.name
"Your Name"
Set Username
Configures the Git username for commits.git config --global
user.email
"
mail@example.com
"
Set Email
Configures the Git email address for commits.git init
Initialize Git Repository
Creates a new Git repository in the current directory.
π Working with Repositories:
git clone [repository_url]
Clone a Repository
Downloads an existing repository from a URL.git status
Check Status
Displays the state of the working directory (untracked, modified, staged files).git add [file]
Stage Changes
Adds changes in the file(s) to the staging area for the next commit.git commit -m "Commit message"
Commit Changes
Commits the staged changes with a message.git push [remote] [branch]
Push Changes to Remote
Sends commits from your local repository to the remote repository.git pull [remote] [branch]
Pull Changes from Remote
Fetches and merges changes from the remote repository.
π οΈ Branching and Merging:
git branch
List Branches
Lists all branches in the repository.git branch [branch_name]
Create New Branch
Creates a new branch.git checkout [branch_name]
Switch Branches
Create a New Branch and Switching to It.git merge [branch_name]
Merge Branch
Merges changes from the specified branch into the current branch.git rebase [branch_name]
Rebase Branch
Reapplies commits on top of another base tip.
π§ Undo Changes:
git reset [file]
Unstage a File
Removes the file from the staging area without deleting changes.git reset --hard [commit]
Reset to a Specific Commit
Resets your working directory and index to a specific commit, deleting all newer commits.git revert [commit]
Revert Commit
Creates a new commit that undoes changes made by a previous commit.
π¦ GitHub Integration:
git remote add origin [repository_url]
Link Repository to GitHub
Links the local repository to the remote GitHub repository.git push origin [branch_name]
Push to GitHub
Pushes the changes to the specified branch on GitHub.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! π