Linux Commands:
Navigation:
Commands | Use Cases |
pwd | Print current working directory |
ls | List files and directories |
ls -l | Detailed listing |
ls -a | Show hidden files |
cd | Change directory |
cd ~ | Go to home directory |
cd .. | Move up one directory |
mkdir | Create a new directory |
mkdir my_folder | Create a directory name "my_folder" |
File Operations:
Commands | Use Cases |
touch | Create an empty file |
touch new_file.txt | Create a file named "file.txt" |
vim or nano | Opens text editor |
vim new_file.txt or nano new_file.txt | Both will be used to edit text-based files |
cp | Copy files and directories |
cp <option> <source> <destination> | Copy file and directories to destination |
mv | Move or rename file |
mv file.txt new_file.txt | Rename file |
mv <option> <source> <destination> | Move file to destination |
rm | Remove files and directory |
rm file.txt | Remove file |
rm -r my_folder | Remove directory and its contents |
chmod | Change file permission |
chown | Change file owner |
chgrp | Change file permission |
Text Processing:
Commands | Use Cases |
cat | Concatenate and display file content |
cat file.txt | Display contents of "file.txt" |
grep | Search for pattern in files |
grep "pattern" file.txt | Search for a pattern in :file.txt" |
sed | Stream editor for text manipulation |
sed 's/old/new/g' file.txt | Replace all occurences of "old" with "new" in "file.txt" |
awk | Powerful pattern scanning and text processing tool |
awk '{print $1}' file.txt | Print the first column of "file.txt" |
head and tail | Display the beginning or end of a file |
System Information:
Commands | Use Cases |
uname | Print system information |
uname -a | Display all system information |
df | Display disk space usage |
df -h | Human readable disk space usage |
free | Display system memory usage |
free -m | Display memory usage in megabytes |
Process Management:
Commands | Use Cases |
ps | Display information about processes |
ps aux | Display detailed information about all processes |
kill | Terminate a process |
kill PID | Terminate the process with specified PID |
top | Display real time system statics |
ifconfig | Display network interface configuration |
ping | Test network connectivity |
ping google.com | Ping google server |
Package Management:
Commands | Use Cases |
apt | Debain/Ubuntu |
apt update | Update package information |
apt install package | Install a package |
apt remove package | Remove a package |
apt search keyword | Search for a package |
systemctl | Control system services |
User Management:
Command | Use Cases |
useradd and userdel | Add or remove a user |
passwd | Change user password |
su or sudo | Switch user or execute a command with superuser privileges |
File Compression and Archives:
Commands | Use Cases |
tar | Create or Extract tar archives |
tar -cvf archiv.tar file1 file2 | Create a tar archive |
tar -xvf archive.tar | Extract file from a tar archive |
gzip or gunzip | Compress or decompress files |
gzip file.txt | Compress "file.txt" |
gunzip file.txt.gz | Decompress "file.txt.gz" |
Git-GitHub Commands:
- Git is the free and open source distributed version control system that's responsible for everything GitHub related that happens locally on your computer. This cheat sheet features the most important and commonly used Git commands for easy reference.
Git Basics:
- Initialize a Repository:
Command | Use Cases |
git init | Initialize a new Git repository |
- Clone a Repository:
Command | Use Cases |
git clone <repository_url> | Clone a repository for URL |
- Stage and Commit:
Commands | Use Cases |
git add <file> | Stage changes for commit |
git commi -m "commit message" | Commit staged changes with a message |
- Branching:
Commands | Use Cases |
git branch | List branches |
git branch <branch_name> | Create a new branch |
git checkout <branch_name> or git switch <branch_name> | Switch to a branch |
git merge <branch_name> | Merge changes from another branch into the current branch |
- Remote Repositories:
Commands | Use Cases |
git remote -v | View remote repository |
git remote add origin <repository_url> | Add remote repository |
git push -u origin <branch_name> | Push changes to remote repository |
git pull origin <branch_name> | pull changes from a remote repository |
Git Workflow:
- Status and Changes:
Commands | Use Cases |
git status | Show the status of changes |
git diff | Show changes between working directory and staging area |
git diff --staged | Shows changes between staging area and last commit |
- Log and History:
Commands | Use Cases |
git log | Show commit history |
git log --oneline | Show abbreviated commit history |
- Undoing Changes:
Commands | Use Cases |
git reset Head <file> | Unstage changes |
git checkout --<file> | Discard changes into working directory |
git revert <commit_hash> | Create a new commit to reverse changes from a specific commit |
- Tagging:
Commands | Use Cases |
git tag <tag_name> | Create a lightweight tag for the current commit |
git tag -a <tag_name> -m "Tag message" | Create an annotated tag with the message |
- Collaboration:
Commands | Use Cases |
git fetch | Fetch changes from the remote repository |
git branch -d <branch_name> | Delete a local branch |
git push origin --delete <branch_name> | Delete a remote branch |
Forking:
- Fork a repository on GitHub
Cloning Forked Repository:
- Clone the forked repository to your local machine
Upstream Connection:
git remote add upstream <original_repository_url>
: Add upstream repository for updates
Keeping Fork Updated:
git fetch upstream
: Fetch updates from the upstream repositorygit merge upstream/main
: Merge updates into your local main branchgit push origin main
: Push updates to your fork on GitHub
Pull Requests:
Create a new branch for your feature or bug fix
Commit changes and push the branch to your fork
Open a pull request from your branch to the upstream repository
Happy Learning
Thanks For Reading! :)
-SriParthu💝💥