Day 12: 90DaysOfChallenge

"cheat-sheet" of Linux and Git-GitHub

Day 12: 90DaysOfChallenge

Linux Commands

CommandsDefinition
lsList the files and directories in the current directory.
ls -aList all the files or directories including hidden files.
cdChange the current directory. For example, "cd ubuntu" will move you into the "ubuntu" directory.
pwdPrint the working directory, which shows you the path of the current directory.
mkdirCreate a new directory. For instance, "mkdir abc" will create a directory named "abc"
touchCreate an empty file. For example, "touch text1.txt" will create a file named "text1.txt"
touch file{1...5}.txtCreates 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)
cpCopy files or directories. For instance, "cp text1.txt /path/to/destination" will copy "file.txt" to the specified destination.
mvMove or rename files or directories. For example, "mv text1.txt new_location/" will move the file to the "new_location" directory.
catDisplay the contents of a file on the terminal. For instance, "cat text1.txt" will show the content of "text1.txt."
echoPrint 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
manAccess the manual pages for commands. For example, "man ls" will show the manual for the ls command.
sudoExecute a command with superuser (administrator) privileges. Be careful when using "sudo" as it allows you to make changes that can affect the system.
mkdir -pCreate 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)
dateDisplays the system date and time
clearClears the terminal
whoamiShows the current user
crontab -lLists the crontab entries
crontab -eOpens the crontab editors
sudo <user>Switchs to the given user
sudo cat /etc/passwdShows all the users inside the system
sudo useradd <username>Creates a new user
sudo cat /etc/groupShows 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 -keygenGenerates a connection in between public and private key
find <typeOfFile>find files and directories
historyShows 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
exitExits from the user
sudo apt updateUpdate the packages
sudo apt upgradeUpgrade the packages
sudo apt install <packageName>Install the packages
sudo apt purge <packageName>Uninstall the packages

Git Commands

CommandsDescription
git initInitializes an empty repository
git statusDisplays 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 logDisplays the most recent commits with commit id and the status of the head
git log --onelineDisplays only the commit id and the commit message
git log --oneline --prettySame 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 branchShows all the existing branch. The current branch is shown in green color.
git clone urlCopies the github repository to local
git remote -vShows 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 revertReverts the changes but maintains the version history by creating a new commit
git resetReverts the changes and do not maintain the version history
git merge <branchName>Merges one branch to another
git rebaseMerge the branch in a linear manner
git stashStores the changes into the working directory without actually committing the file.
git stash popBring 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