#12 Linux and GIT Cheatsheet

#12 Linux and GIT Cheatsheet

Linux Cheatsheet

Basic Commands

CommandsDescription
dateIt shows the current date and time
calIt shows the current month's calendar
uptimeIt shows when your system running
whoamiIt will show you
usersIt shows user information
whoIt will show you who you are and your public IP
manIt will show you command details eg. man who
lsIt will show files and directories in the current working directory
ls -aShows hidden files
pwdShows the path of the present working directory

Files and Directories

CommandsDescription
touchTo create empty files and to update timestamp
cat > filenameIt creates a file and allows to add content
cat <filename>Shows the content of the file
head <filename>Shows the first top 10 lines of a file
tail <filename>Shows the bottom 10 lines of a file
rm <filename>Removes file
rm -rf <filename>Removes file forcefully
cp <filname1> <filename2>It copies the content of a filename1 to filename2
mv <filename1> <filename2>It is used to rename or move files.
mkdir <dirname>To create a directory
cd <dirname>To change the directory
rm -r <dir name>Removes directory
rm -rf <dir name>Forcefully removes directory
findTo search files or directories in Linux
grepTo search patterns in a file
difffind the difference between file
sedTo search and replace content from a file

User Management

All the user information is stored in /etc/passwd.

CommandsDescription
addgroup <groupname>It will add a new group
useradd <username>It will create a user
su <username>To switch user
deluser <username>To delete user
del group <groupname>To delete a group
chownTo change ownership of a file
chgrpTo change group membership of a file
usermod -gTo change the group of a user
usermod -a -GTo add a user to multiple groups
passwdTo change the password

System Management

CommandsDescription
historyshows list commands executed by the user
freeIt shows free and used memory in the system
/proc/meminfoIt shows memory information
/proc/cpuinfoIt shows CPU information
uname -aIt shows kernel information
duIt shows directory-wise disk usage (for memory monitoring)
dfIt shows filesystem disk usage (for memory monitoring)
top / topfor CPU monitoring

Software Management

yum is the tool to install, delete, update and manage RHEL software packages.

CommandsDescription
yum install <package name>It will install the package. eg. yum install git
yum remove <package name>It will remove the package
yum update <package name>It will update the package
yum info <package name>It will give package info
yum list availableIt will show available packages on Yum
yum list installedIt will show installed packages.

apt-get command is used to install, remove, and perform other operations on installed software packages. The apt-get command, and other core APT utilities, are available by default in the Debian, Ubuntu, and Linux Mint operating systems.

CommandsDescription
apt-get install <package name>It will install the package
apt-get remove <package name>It will remove the package
apt-get purge <packga name>It will remove the package and its configuration
dpkg -lIt will show all installed package

Networking

CommandsDescription
ping hostping host and output result
hostnamelist the hostname of the server
wgetIt will download packages or software on the Linux system
telnetconnect to the remote host
curlaccess the application from the browser

Services

CommandsDescription
service <name of the service> statusTo see the status of the service
service <name of the service> startStart the service
service <name of the service> stopstop the service
service <name of the service> reloadReload the service
service <name of the service> restartRestart the service

Process Management

CommandsDescription
ps -efTo display the current working process
topDisplay all running process
kill -9Kill the process

Compression

CommandsDescription
gzip filecompress the file and rename it to file.gz
gzip -d file.gzDecompresses file.gz back to the file
tar cf file.tar fileCreate a tar named file.tar containing file
tar xf file.tarExtract the files from the file.tar
tar czf file.tar.gz filesCreate a tar with Gzip compression
tar xzf file.tar.gz filesExtract a tar using Gzip compression

GIT Cheatsheet

  • Configuring user information for all local repositories

$ git config --global user.name "[Enter name]"Configuring the name
$ git config --global user.email "[email id]"configuring the email
  • Create Repositories

git initInitialize an existing directory as a Git repository
git clone <url>Copy the entire repository from the central hosted location via URL
  • Stage and snapshot

git status

Shows the status of a file like tracked untracked.

git add (file)

adding a file from the working area to the staging area

git add .

It will add all the files from the working area to the staging area

git reset (file)

Unstage a file while retaining the changes in the working directory

git commit -m <"Message">

It will commit all the files from the staging area to the commit area.

  • Branch and Merge

git branch

It will list all branch

git branch <branch name>

It will create a new branch

git branch checkout

It will switch to another branch

git merge <branch name>

It will merge branch history into the current branch

git branch -d <branch name>

It will remove a branch

git log

It will show all the commit history currently active branch

  • Compare

git log <branch1> <branch2>

Shows the commit on branch1 that are not in branch2

git log --merge

It will show commits that cause conflicts

git diff <branch1> <branch2>

Shows the difference between the two branch

  • Share and Update

git remote add origin <url>

add remote origin URL

git remote remove origin <url>

remove remote origin

git merge <branch name>

Merge a remote branch into a current branch

git push origin <branch name>

push local changes to the remote branch

git pull origin <branch name>

pull remote changes to the local branch

  • Tracking Path Changes

git rm <filename>

It will remove the file from the project and stage the removal for the commit

git mv <existing path> <new path>

change an existing file path and stage the move

git log --stat -M

Show all commit logs with an indication of any paths that moved

  • Rewrite History

git rebase <branch>

Apply any commits of the current branch ahead of the specified one.

git reset --hard [commit]

clear staging area, rewrite the working tree from a specific commit

  • Temporary Commits

git stash

Save modified and stage changes

git stash list

To see stashed item list

git stash pop

Popping an item from the stash

git stash drop

Delete a stash from the queue

git stash clear

To clear the stash

Thank You for reading this blog

Parimal Pradhan

You can follow me on LinkedIn for my daily updates:- linkedin.com/in/parimal-pradhan-b62021168

Great initiative by the #trainwithshubham community. Thank you Shubham Londhe

Did you find this article valuable?

Support Parimal Pradhan by becoming a sponsor. Any amount is appreciated!