Table of contents
Linux Commands
Commands | Definition |
ls | List the files and directories in the current directory. |
ls -a | List all the files or directories including hidden files. |
cd | Change the current directory. For example, "cd ubuntu" will move you into the "ubuntu" directory. |
pwd | Print the working directory, which shows you the path of the current directory. |
mkdir | Create a new directory. For instance, "mkdir abc" will create a directory named "abc" |
touch | Create an empty file. For example, "touch text1.txt" will create a file named "text1.txt" |
touch file{1...5}.txt | Creates multiple empty files. For example, file1.txt, file2.txt, file3.txt, file4.txt, file5.txt |
rm <filename> | Deletes a single file. For example, "rm text1.txt" will delete the "text1.txt" file. |
rm -r <foldername> | Deletes the folder and all the files within the folder. (r-recursively) |
rm -rf <foldername> | Deletes the folder and all the files within the folder without any prompt. (r-recursive, f-forcefully) |
cp | Copy files or directories. For instance, "cp text1.txt /path/to/destination" will copy "file.txt" to the specified destination. |
mv | Move or rename files or directories. For example, "mv text1.txt new_location/" will move the file to the "new_location" directory. |
cat | Display the contents of a file on the terminal. For instance, "cat text1.txt" will show the content of "text1.txt." |
echo | Print text to the terminal. For example, echo "Hello, Linux!" will display "Hello, Linux!" on the screen. |
grep <keyword> <pathOfFile> | Search for a specific string in a file. For instance, grep "keyword" text1.txt will find lines containing the "keyword" in "file.txt." |
grep -i <keyword> <pathOfFile> | Search for a specific string in a file insensitively. |
grep -ir <keyword> <pathDirectory> | Search recursively for a string in the directory |
grep -c <keyword> <pathfile> | Displays the count of the number of matches |
man | Access the manual pages for commands. For example, "man ls" will show the manual for the ls command. |
sudo | Execute a command with superuser (administrator) privileges. Be careful when using "sudo" as it allows you to make changes that can affect the system. |
mkdir -p | Create a nested directory A/B/C/D/E. For instance, "mkdir -p A/B/C/D/E" creates a nested directory A/B/C/D/E. (p-parent directory) |
date | Displays the system date and time |
clear | Clears the terminal |
whoami | Shows the current user |
crontab -l | Lists the crontab entries |
crontab -e | Opens the crontab editors |
sudo <user> | Switchs to the given user |
sudo cat /etc/passwd | Shows all the users inside the system |
sudo useradd <username> | Creates a new user |
sudo cat /etc/group | Shows all the groups inside the system |
sudo groupadd <groupname> | Creates a new group |
sudo usermod -aG <groupname> <username> | Adds a user to a particular group |
sudo gpasswd -M <user1>, <user2>, <user3>, <user4> <groupname> | Adds a multiple user to a particular group (M-multiple) |
sudo gpasswd -d <user> <group> | Deletes a user from a particular group (d-delete) |
sudo groupdel <groupname> | Delete a particular group |
chmod [permission] <filename> | Change the access mode of a file(Permissions: r-read,w-write,x-execute) |
ssh -keygen | Generates a connection in between public and private key |
find <typeOfFile> | find files and directories |
history | Shows the history of all commands used |
vim <filename.txt> | Created and opens a text editor |
head -n <filename> | Shows starting 2 records of the file |
tail -n <filename> | Shows the last 2 records of the file |
exit | Exits from the user |
sudo apt update | Update the packages |
sudo apt upgrade | Upgrade the packages |
sudo apt install <packageName> | Install the packages |
sudo apt purge <packageName> | Uninstall the packages |
Git Commands
Commands | Description |
git init | Initializes an empty repository |
git status | Displays the state of the working tree and staging area. Shows the tracked, untracked, staged, unstaged file and changes |
git add <fileName> | Adds new or changed files to the Git staging area |
git commit -m "Message" | Moves the file from staging area to the local working directory (m-message) |
git rm --cached <filename> | Remove one or many files from the Git index but keeps the file in the working area (rm-removes) |
git rm <filename> | Remove one or many files from the Git index and also from the working area (rm-removes) |
git restore <filename> | Restores the deleted files |
git log | Displays the most recent commits with commit id and the status of the head |
git log --oneline | Displays only the commit id and the commit message |
git log --oneline --pretty | Same as git log except commit id is shortened |
git config --global user.name="username" | Setting the Git username globally on your computer |
git config --global user.name="email" | Setting the Git email globally on your computer |
git checkout -b <branchName> | Creates a new branch with <branchName> and switch to the created branch |
git checkout <branchName> | Switch to the given branch |
git branch | Shows all the existing branch. The current branch is shown in green color. |
git clone url | Copies the github repository to local |
git remote -v | Shows the remote url of the current repository |
git pull origin <branchName> | Pull the changes of the origin branch to the branch we are checked out in |
git push origin <branchName> | Pushes the changes of the local branch to the origin branch |
git remote set-url origin <newurl> | Sets the URL for existing remote repository |
git remote set-url [--push] origin <newurl> | Updates the push URL with the <newurl> |
git remote set-url --add origin <newurl> | Adds the <newurl> of the remote repository in local |
git remote set-url --delete origin <oldurl> | Deletes the <oldurl> of the remote repository in local |
git revert | Reverts the changes but maintains the version history by creating a new commit |
git reset | Reverts the changes and do not maintain the version history |
git merge <branchName> | Merges one branch to another |
git rebase | Merge the branch in a linear manner |
git stash | Stores the changes into the working directory without actually committing the file. |
git stash pop | Bring back the stashed file to the current working directory |
git cherry-pick <commitid> | Applies any specific commit to any other branch. |
Hope this cheat sheet would be useful! Thanks for reading!
~Shilpi