Linux & Git-GitHub Cheat Sheet
Linux & Git-GitHub Cheat Sheet
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.
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
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 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.