Linux and Github (Cheat sheet)

Linux and Github (Cheat sheet)

#90DaysOfDevOps

Linux Basics commands

To check your current working directory

pwd

list all the files and directories

ls

list hidden files or directories

ls -a

list files in sub-directories as well

ls -R

list files and directories with detailed information like; permission, size and owner etc

ls -la

create new directory

mkdir<dir_name>

To create multiple directories

mkdir -p A/B/C/D

To remove directory

rmdir<dir_name>

To remove multiple directories

rm -rf <dir_name>

to change directory

cd or cd~

Move to the root directory

cd/

to change to a particular directory

cd

Allows regular users to run programs with the security privileges of the superuser or root

sudo

create an empty file

touch<file_name>

Delete a file

rm <file_name>

Copy file

cp<source_path> <destination_path>

move file

mv<source_path> <destination_path>

To write some content inside a file

echo<mssg> > <file_name>

Display the file contents

cat <file_name>

Gives a list of all past commands typed in the current terminal session

history

clear the terminal

clear

To search a word

grep"str" <file_name>

Return the specified number of lines from the top

head

Return the specified number of lines from the bottom

tail

Display disk filesystem information

df

Mount file system

mount

Display the user manual of any command

man

Find the files and directories path

find

List the hostname of the server

hostname

Linux File Permission Commands

To change the permission of the file

chmod<permission> <file_name>

To show file type and access permission

ls -l

To change file or directory ownership

chown<user_name> <file_name>

To change group ownership

chgrp<group_name> <file_name>

User Management Commands of Linux

To create a new user

sudo useradd<user_name>

To set a password for the user

sudo passwd <user_name>

To modify a Linux server

sudo usermod <user_name>

To delete a linux user

sudo userdel <user_name>

For adding a group account

sudo groupadd <group_name>

to add a user to a group

sudo usermod -a -G <groupname> <username>

To remove a user from a group

sudo deluser <user> <group_name>

Gives information about a particular user

finger

List all the files and directories in the present working directory

finger username

Access Control List

For checking ACL permission

getfacl <name of the file or directory>

To set ACL permission to the user

setfacl -m u:user:permissions/path_to_file

Git Commands

Git configuration:

To set author name to be used for all commits by the current user

git config --global user.name <"name">

to set author email to be used for all commits by the current user

git config --global user.email <"email">

To show config info

git config --list

Git Basics

Initialize an empty git repository

git init

Clone an existing git repository

git clone <repo_url>

Add files and move changes from working directory to the staging area

git add <file_name>

Add all current directory files to git

git add .

Commit all the staged files to git

git commands -m "commit messages"

To show the status of your git repository

git status

To check your git commits and all logs

git log

Show unstaged changes between your index and working directory

git diff

Git Branches

To list all of the branches

git branch

Create a new branch

git branch <branch_name>

For creating and going to that branch

git checkout -b <branch_name>

For going to specific branch

git checkout <branch_name>

Merge branch into current branch

git merge <branch_name>

Remote Repositories

List of all remote repo that are currently connected to local repo

git remote -v

To add remote origin URL

git remote add origin <remote_git_url>

To remove the remote origin URL

git remote remove origin

To upload local repository content to a remote repository

git push origin <branch_name>

To pull your remote repository content to local repository

git pull origin <branch_name>

To fetch down all the branches from that git remote

git remote

Cherry-pick

Merge just one specific commit from another branch to your current branch

git cherry-pick<commit_id>

Git Revert

Undo a single given commit, without modifying commits that come after it

git revert <commit_id>

Git Rebase

To rebase all the commits between another branch and the current branch state

git rebase<other_branch_name>

Temporary commits

To save modified and staged changes

git stash

List stack-order of stashed file changes

git stash list

Write working from top of stash stack

git stash pop

Discard the changes from the top of the stash stack

git stash drop

apply the stash without removing it from the list

git stash apply

Thanks for giving your valuable time to read this article. If you find it insightful kindly follow me.

~Prabhakar Yadav