Table of contents
Let's go through some Linux, Git, and Git-Hub useful Command
What is the command?
A command is a specific instruction given to a computer application to perform some kind of task or function.
Linux Commands:
ls - The most frequently used command in Linux to list directories
Syntax: ls
pwd - Print working directory command in Linux
Syntax: pwd
cd - Linux command to navigate through directories
Syntax: cd [dir-name]
mkdir - Command used to create directories in Linux
Syntax: mkdir [new-dir-name]
rmdir - Command used to permanently delete an empty directory
Syntax: rmdir [dir-name]
mv - Move or rename files in Linux
Syntax: mv [source] [destination]
cp - Similar usage as mv but for copying files in Linux
Syntax: cp <source> <destination>
rm - Delete files or directories
Syntax: rm [file/dir-name]
touch - Create blank/empty files
Syntax: touch [new-file-name]
ln - Create symbolic links (shortcuts) to other files
Syntax: ln [target-file] [link-name]
cat - Display file contents on the terminal
Syntax: cat [file-name]
clear - Clear the terminal display
Syntax: clear or keyboard key cnt+l
echo - Print any text that follows the command
Syntax: echo "text"
less - Linux command to display paged outputs in the terminal
Syntax: less [file-name]
man - Access manual pages for all Linux commands
Syntax: man [command-name]
uname - Linux command to get basic information about the OS
Syntax: uname
whoami - Get the active username
Syntax: whoami
tar - Command to extract and compress files in Linux
Syantx: tar [options] [archive-file]
grep - Search for a string within an output
Syntax: grep [pattern] [file-name]
head - Return the specified number of lines from the top
Syantx: head [file-name]
tail - Return the specified number of lines from the bottom
Syantx: tail [file-name]
diff - Find the difference between two files
Syantx: diff [file-name-1] [file-name-2]
cmp - Allows you to check if two files are identical
Syantx: cmp [file-name-1] [file-name-2]
comm - Combines the functionality of diff and cmp
Syantx: comm [file-name-1] [file-name-2]
sort - Linux command to sort the content of a file while outputting
Syantx: sort [file-name]
export - is bash shell BUILTINS commands, which means it is part of the shell. It marks an environment variables to be exported to child processes.
Syantx: export name[=value]
zip - To create a zip files in Linux
Syntax: zip [options] zip file files_list
unzip - Unzip files in Linux
Syntax: unzip [zip-file-name]
ssh - Secure Shell command used in Linux to connect remote server
Syntax: ssh -i [key-name] user_name@host(IP/Domain_name)
service - Linux command to start and stop services
Syntax: service [service-name] [start/stop/status/enable]
ps - Display active processes
Syntax: ps
kill and killall - Kill active processes by process ID or name
Syntax: ps [Process-ID/name]
df - Display disk filesystem information
Syntax: Syntax: df
mount - Mount file systems in Linux
Syntax: mount -t [type] [device dir]
chmod - Command to change file permissions
Syantx: chmod [permissions] [file-name]
chown - Command for granting ownership of files or folders
Syantx [chown owner_name] [file_name]
ifconfig - Display network interfaces and IP addresses
Syantx ifconfig
traceroute - Trace all the network hops to reach the destination
Syantx traceroute [route]
wget/curl - Direct download files from the internet
Syantx: weget/curl [request-url]
ufw - Firewall command
Syantx: ufw [allow] [port]
iptables - Base firewall for all other firewall utilities to interface with
apt, pacman, yum, rpm - Package managers depending on the distro
Syntax: sudo apt/pacman/yum/rpm
sudo - Command to escalate privileges in Linux
Syantx: sudo
cal - View a command-line calendar
Syantx: cal
alias - Create custom shortcuts for your regularly used commands
Syantx: alias [name]=[value]
dd - Majorly used for creating bootable USB sticks
whereis - Locate the binary, source, and manual pages for a command
Syntax: whereis [file-name]
whatis - Find what a command is used for
Syantx: whatis [command-name]
top - View active processes live with their system usage
Syantx: top
useradd and usermod - Add a new user or change existing users data
Syantx: sudo useradd [new-user-name]
Syantx: sudo usermod [change-data]
passwd - Create or update passwords for existing users
Syantx: sudo passwd [user-name]
Git And GitHub Commands:
git config:
It is used to set the name of the author and the email address which you want your commitment to addressing.Syntax: git config –global user.name “[user-name]”
Syntax: git config –global user.email “[email address]”
git init:
It is used to start a new git repository. This is generally used at the beginning.Syntax: git init [repo name]
git clone:
This command is used to clone or copy a repository from a URL. This URL generally is a GitHub, bitbucket server, a stash, or any other version control and source code management repository holding service.Syntax: git clone [URL]
git add:
It is used to add a file to the staging area. Instead of choosing a single file name, you can also choose to give all filenames with an *.Syntax: git add (filename)
Syntax: git add *
git commit –m:
It is used to snapshot or record/save a file in its version history permanently.Giving a message text at the end of the commit command helps in identifying the details about the commit code.
Syntax: git commit –m [type in a message]
git commit –a:
This commit command is used to commit any such file which has been added as a result of the git add command. It is also responsible for committing any other files to which you have brought a change to since then.Syntax: git commit -a
git diff:
As the name suggests, this command is used to display all the differences between the files until the changes have not yet been staged.Syntax: git git diff
git diff –staged:
It is used to display all the differences between staging area files and the latest version, which might be present.Syntax: git diff -staged
git diff [first branch] [second branch]:
This is a very effective command as it is used to display the differences present between the two branches.Syntax: git diff [first branch] [second branch]
git diff [commit-id-1] [commit-id-2]:
This is a very effective command as it is used to display the differences present between the two commits.Syntax: git diff [commit-id-1] [commit-id-2]
git reset [file]:
This command, as the name suggests, is used to unstage a file. Even though it unstages the file, still the contents of the file have stayed intact.Syntax: git reset [file]
Git reset [commit]:
It is used to undo all the changes that have been incorporated as a part of a commit after a specified commit has taken place. This helps in saving the changes locally on the computer.Syntax: git reset [commit]
Git reset –hard [commit]:
This command is used to discard all the history and takes us to the last specified commit.git reset –hard [commit]
Git status: This is one of the most frequently used as this is used to list down all the files which are ready to be committed.
git status
Git rm:
As in Unix, rm is used to remove; in the same way, rm is used to delete the file from the present working directory and is also used to stage the deletion process.Syntax: git rm [file]
Git log:
This is used for listing down the version history for the current working branch.Syntax: git log
Git log --online:
This is used for listing down the version history for the current working branch with short information.Syntax: git log
git log –follow:
This is similar to that of git log with the additional difference that it lists the version history for a particular file, which often includes the renaming of the file also.Syntax: git log –follow [file]
git show:
This is used to display the metadata and all the content related changes of a particular commit.Syntax: git show [commit]
git tag:
This is used to give particular tags to the code commits.Syntax: git tag [commit-id]
git branch:
Git branch command is used to list down all the branches that are locally present in the repository.Syntax: git branch
Git branch [branch-name]:
This is used to create a new branch.Syntax: git branch [branch-name]
git branch -d [branch name]
This command deletes the feature branch.Syntax: git branch -d [branch-name]
git checkout
This command is used to switch from one branch to another.Syntax: git checkout [branch-name]
git checkout -b [branch name]
This command creates a new branch and also switches to it.Syntax: git checkout -b [branch-name]
git merge
git merge [branch name]
This command merges the specified branch’s history into the current branch.Syntax: git merge [current-branch-name]
git remote
This command is used to connect your local repository to the remote server.Syntax: git remote add [Remote Repo Link]
git remote:
This git command lists all the remote connections of your local repository that you have with the other repositories.Syntax: git remote
git push
This command sends the committed changes of the master branch to your remote repository.Syntax: git push [Repo-url] master
git push –all [variable name]
This command pushes all branches to your remote repository.Syntax: git push [Repo-url]
git push [variable name] :[branch name]
This command deletes a branch on your remote repository.Syntax: git push [Repo-url] [branch-name]
git pull
This command fetches and merges changes on the remote server to your working directory.Syntax: git pull [Repo-url]
git stash
This command temporarily stores all the modified tracked files.Syntax: git stash save
git stash pop
This command restores the most recently stashed files.Syntax: git stash pop
git stash[stash-id]
This command restores the specific stashed files.Syntax: git stash [stash-id]
git stash list
This command lists all stashed changesets.Syantx: git stash list
git stash drop
This command discards the most recently stashed changeset.Syantx: git stash drop
Thank you for reading the article
Happy Learning!
#linux #git #github #devops