0% found this document useful (0 votes)
3 views

Linux & Git-GitHub Cheat Sheet

This document is a comprehensive cheat sheet for Linux and Git commands. It covers file operations, directory management, process handling, system information, package installation, and Git basics including version control, branching, and remote repository management. Each section provides essential commands with brief descriptions for quick reference.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Linux & Git-GitHub Cheat Sheet

This document is a comprehensive cheat sheet for Linux and Git commands. It covers file operations, directory management, process handling, system information, package installation, and Git basics including version control, branching, and remote repository management. Each section provides essential commands with brief descriptions for quick reference.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Linux Cheatsheet

File Operations:

ls - To list the files and directories present in the current working directory.
ls -R - To list sub-directories as well.
ls -al - To get detailed information about files and directories like file permissions,
size etc.
cd - Used to change working directory
pwd - To print the present the current working directory.
cd .. - change directory to one step back.
cd ../.. - change directory to two steps back.
cat > filename - Creates a file.
cat filename - displays the content of a file.
cat file1 file2 > file3 - combines file1 and file2 in to one file3.
touch filename - creates empty file.
rm filename - deletes a file.
cp - to copy files from source to destination path.
mv - to move files from source to destination path.
find / -name filename - finds a file or directory from its name starting from root.
grep - Searches a string within a file
history - To list previous commands that we run.

file permissions:
chmod - Modifies a file’s read, write, and execute permissions
chown - Changes a file, directory, or symbolic link’s ownership.

Directory Operations:
mkdir - To create a directory.
rmdir directoryname - deletes a directory.
find / -type d -name directoryname - finds a directory.

Process Operations:
ps - displays the current process status.
top - displays all running processes.

Archive and compression:


tar cf file.tar files - creates a tar named file.tar containing files.
tar xf file.tar files - extracts the file from file.tar.
gzip - compresses file and renames it to file.gz
gzip -d file.gz - decompresses file.gz back to file
gzip -r file.gz - creates a zip archive named file.zip
unzip file.zip - extracts the content of a zip file.

Disk Usage:
df - displays the system’s overall disk usage
du - displays the directories space usage
free - displays memory and swap usage

System info:
date - displays the current date and time
uptime - displays current uptime
whomi - ho you are logged in as

Package Installation:
sudo apt-get update - updates all the packages and dependencies
sudo apt-get install pkgname - Install package name
sudo apt-get remove pkgname - removes package name

Git-GitHub Cheat Sheet


Git Basics:
git init - Initialize Git in your Local Repository
git clone - to clone remote repo onto local repo
git config --global user.name "name" - Set your user name which will be
associated with your commits.
git config --global user.email "email" - email address, which will be associated
with your commits.
git add <directory> - stage all changes in <dir> for the next commit.
git commit <directory> - To commit changes from staging area to repository
git status - to check the status of repo
git log - To check who has committed
git diff - displays un-staged changes b/w index and working dir.

Undo changes:
git revert - Git revert is used to undo the changes introduced by a specific commit
by creating a new commit with the opposite changes.
git reset - removes file from staging area, but leaves the working directory
unchanged.
git clean -n - displays which file would be removed from working directory.

Remote Repository:
git remote add origin <remote_repository_url> - creates new connection to remote
repo.
git push -u origin <remote> - This command pushes the 'main' branch (or the
branch you are currently on) to the 'origin' remote repository.

Git Branches:

git branch - lists all the branches in your repo. Add a branch argument to create a new
branch with the name <branch>.
git checkout -b <branch> - create and check a new new branch named <branch>.
git merge - to merge <branch> into current branch.

Git Log:

git log --oneline - condense each commit to a single line.


git log -p - display the full diff of each commit.

Git diff:
git diff HEAD - displays difference b/w working directory and last commit.
git diff --cached - displays difference b/w staged changes and last commit.

You might also like