Essential Linux and Git-GitHub Commands - CheatSheet

Essential Linux and Git-GitHub Commands - CheatSheet

Linux and Git-GitHub are two powerful tools that developers use every day to create, manage, and collaborate on software projects. Learning to use the

LINUX COMMANDS

File System Navigation

  • cd: changes the current working directory to the user's home directory.

  • cd ..: changes the current working directory to the previous directory.

  • cd [directory]: changes the current working directory to the specified directory.

  • pwd: displays the current working directory.

  • ls: lists the contents of the current directory.

  • ls [directory]: lists the contents of the specified directory.

  • ls -a: lists all files and directories (including hidden files) in the current directory.

  • ls -l: lists the contents of the current directory with detailed information.

  • ls -lh: lists the contents of the current directory with detailed information, and displays file sizes in a human-readable format.

  • mkdir [directory]: creates a new directory with the specified name.

  • mkdir -p [dir1]/[dir2]/[dir3]/.../[dir n]: creates nested directory.

  • chown [user:group] [file]: changes the owner and group of the specified file.

  • chmod [permissions] [file]: changes the permissions of the specified file.

  • rm [file]: removes the specified file.

  • rm -r [directory]: removes the specified directory and its contents.

  • tree [directory]: displays a hierarchical tree view of the specified directory and its contents.

  • find [directory] -name [filename]: searches for files with the specified name in the specified directory and its subdirectories.

  • locate [filename]: searches for files with the specified name using an indexed database.

  • which [command]: displays the full path of the specified command.

  • grep [pattern] [file]: searches for lines in the specified file that match the specified pattern.

  • less [file]: displays the contents of the specified file, allowing the user to navigate through the contents with arrow keys.

File Manipulation

  • touch [file]: creates a new empty file with the specified name.

  • diff [file1] [file2]: displays the differences between the contents of file1 and file2.

  • cat [file]: displays the contents of the specified file.

  • cp [file1] [file2]: copies the contents of file1 into file2.

  • cp -r [directory1] [directory2]: copies directory1 and its contents to directory2.

  • cp -p [file1] [file2]: copies file1 to file2, preserving the original file's permissions, ownership, and timestamps.

  • mv [file1] [file2]: renames or moves file1 to file2.

  • mv -i [file1] [file2]: renames or moves file1 to file2, prompting the user if file2 already exists.

  • rm -f [file]: forcefully removes the specified file without prompting for confirmation.

  • rm -i [file]: prompts the user for confirmation before removing the specified file.

  • rm -rf [directory]: forcefully removes the specified directory and its contents without prompting for confirmation.

  • tar -cvzf [archive name] [directory]: creates a compressed tar archive of the specified directory.

  • tar -xvzf [archive name]: extracts the contents of the specified compressed tar archive.

  • split -b [size] [file]: splits the specified file into multiple smaller files with the specified size.

  • join [file1] [file2]: joins the specified files into a single file.

  • awk: a scripting language for text processing that can manipulate files line by line.

  • sed: a stream editor for performing basic text transformations on an input stream.

User and Group Management

  • useradd [username]: creates a new user with the specified username.

  • userdel [username]: deletes the specified user.

  • groupadd [groupname]: creates a new group with the specified name.

  • groupdel [groupname]: deletes the specified group.

  • passwd [username]: sets the password for the specified user.

  • usermod -aG [groupname] [username]: adds the specified user to the specified group.

  • id [username]: displays information about the specified user, including their UID and GID.

  • groups [username]: displays the groups to which the specified user belongs.

  • chgrp [groupname] [file]: changes the group ownership of the specified file.

  • chown [username] [file]: changes the owner of the specified file.

System Information

  • uname: displays information about the system kernel.

  • top: displays real-time information about running processes.

  • top -p [PID]: displays real-time information about the specified process ID.

  • ps: displays information about running processes.

  • ps -ef: displays detailed information about all running processes.

  • df: displays disk usage information.

  • du: displays the disk usage of files and directories.

  • df -h: displays disk usage information with file sizes in a human-readable format.

  • htop: an interactive process viewer that displays real-time information about running processes.

  • free -h: displays information about system memory usage in a human-readable format.

  • ifconfig: displays network interface configuration information.

  • netstat: displays information about active network connections and associated processes.

  • netstat -tulpn: displays information about active network connections and associated processes.

  • iostat: displays I/O statistics for storage devices and partitions.

  • vmstat: displays virtual memory statistics, including memory usage, page activity, and CPU usage.

  • ip: displays and manipulates network interface information.

System Management

  • sudo [command]: executes the specified command with elevated privileges.

  • apt-get install [package]: installs the specified package.

  • apt-get remove [package]: removes the specified package.

  • apt-get update: updates the local package index.

  • apt-get upgrade: upgrades all installed packages to their latest versions.

  • apt-get dist-upgrade: upgrades the distribution to the latest version.

  • apt-get autoremove: removes all packages that are no longer needed by any installed packages.

  • reboot: restarts the system.

  • shutdown: shuts down the system.

  • reboot -h now: shuts down the system immediately.

  • shutdown -h now: shuts down the system immediately.

  • crontab -e: opens the user's crontab file for editing.

  • cron -r: removes the current user's crontab file.

  • systemctl start [service name]: starts the specified system service.

  • systemctl stop [service name]: stops the specified system service.

  • systemctl restart [service name]: restarts the specified system service.

  • journalctl: displays system logs.

  • iptables: a powerful firewall tool for managing network traffic.

  • sysctl: allows the user to modify and query kernel parameters at runtime.

at: schedules a command to be executed at a specific time.


GIT AND GITHUB COMMANDS

Setting Up

  • git config --global user.name "[username]": sets your username for Git.

  • git config --global user.email "[email]": sets your email address for Git.

  • git init: initializes a new Git repository.

  • git config --list: displays a list of all Git configuration settings.

  • ssh-keygen: generates a new SSH key pair for secure communication with GitHub.

Working with Repositories

  • git clone [repository URL]: clones a repository from GitHub.

  • git status: displays the current status of the repository.

  • git add [file]: stages the specified file for commit.

  • git add -A: stages all changes, including deleted files and renamed files.

  • git commit -m "[commit message]": commits the staged changes with a message.

  • git commit --amend: modifies the previous commit with staged changes.

  • git commit -a: commits all changes, including modifications and deletions, without staging.

  • git push: pushes the committed changes to the remote repository.

  • git pull: pulls the latest changes from the remote repository.

  • git reset [file]: unstages the specified file.

  • git reset --hard: resets the working directory to the last commit and discards all changes.

  • git stash: saves the current changes temporarily to the stash.

  • git stash apply: applies the last stashed changes to the working directory.

  • git stash save [message]: saves the current changes temporarily to the stash with a custom message.

  • git log: displays the commit history of the repository.

  • git log --graph: displays the commit history as a graph.

  • git log --oneline: displays the commit history with one-line messages.

  • git log --author=[author name]: displays the commit history filtered by the specified

Branching and Merging

  • git branch: displays a list of branches.

  • git branch [branch name]: creates a new branch with the specified name.

  • git branch -a: displays a list of all local and remote branches.

  • git branch -d [branch name]: deletes the specified branch.

  • git checkout [branch name]: switches to the specified branch.

  • git checkout -b [new branch name]: creates a new branch with the specified name and switches to it.

  • git merge [branch name]: merges the specified branch into the current branch.

  • git merge --abort: aborts a merge in progress.

  • git merge --no-ff [branch name]: merges the specified branch into the current branch with a commit message, even if it can be fast-forwarded.

  • git merge --no-commit [branch name]: merges the specified branch into the current branch, but does not commit the changes.

  • git merge --squash [branch name]: merges the specified branch into the current branch, but does not create a merge commit.

  • git rebase [branch name]: reapplies commits from the specified branch onto the current branch.

  • git rebase -i [commit hash]: starts an interactive rebase of the current branch, allowing the user to modify commits, delete commits, or squash commits.

  • git rebase --onto [new base] [old base] [branch name]: moves the specified branch onto a new base branch, discarding any commits that are only reachable from the old base branch.

  • git cherry-pick [commit hash]: applies the changes from the specified commit onto the current branch.

Collaborating with Others

  • git remote add [name] [repository URL]: adds a remote repository with the specified name and URL.

  • git remote set-url [name] [new URL]: changes the URL of a remote repository.

  • git remote -v: displays a list of remote repositories.

  • git fetch: retrieves the latest changes from the remote repository.

  • git fetch --all: fetches the latest changes from all remote repositories.

  • git fetch [name] [branch name]: fetches the latest changes from the specified branch of the remote repository.

  • git merge [name]/[branch name]: merges the specified branch from the remote repository into the current branch.

  • git push [name] [branch name]: pushes the committed changes to the specified branch of the remote repository.

  • git push [name] :[branch name]: deletes the specified branch from the remote repository.

  • git push --tags: pushes all tags to the remote repository.

  • git push [name] --force: forces a push to the specified branch of the remote repository, overwriting any conflicting changes.

  • git push [name] --tags: pushes all tags to the specified remote repository.

  • git clone --depth=1 [repository URL]: clones a repository from GitHub with only the latest commit history.

  • git remote rename [old name] [new name]: renames a remote repository.

  • git remote remove [name]: removes a remote repository.

  • git pull --rebase: pulls the latest changes from the remote repository and reapplies local commits on top.


Thank you for reading this Blog. Hope you learned something new today! If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future.

If you have some suggestions I am happy to learn with you.

I would love to connect with you on LinkedIn

Meet you in the next blog....till then Stay Safe ➕ Stay Healthy

#HappyLearning #LinuxCommands #GitCommands #GitHub #DeveloperTools #SystemAdministration #Collaboration #Productivity #OpenSource #Programming #VersionControl #TechTips #CommandLine #Terminal #SoftwareDevelopment #Coding #TechSkills #IT #SysAdmin #devops