Day 12: Task: Linux and GitHub Cheat-Sheet

Day 12: Task: Linux and GitHub Cheat-Sheet

Linux Basic Commands

1) To check your present working directory

pwd

2) List all the files or directories

ls

3)Lists hidden files or directories:

ls -a

4) Long listing format:

ls -l

5) Create a new directory:

mkdir <directory_name>

6) Multiple directory creation:

mkdir -p A/B/C/D

7) Remove the directory:

rmdir <directory_name>

8) Remove multiple directories:

rm -rf <directory_name>

9) Remove files:

rm <file_name>

10) change directory:

cd <path_where_to_navigate>

11) create an empty file:

touch <file_name>

12) Copy file:

cp  <source_path> <destination_path>

13) Move file:

mv  <source_path> <destination_path>

14) To write some content inside a file:

echo <some msg> > <file_name>

15) display the contents of a file:

cat <file_name>

16) show previous commands/operations performed in the shell:

history

17) To search a word (string in a file):

grep "string" <filename>

18) Return the specified number of lines from the top:

head

19) Return the specified number of lines from the bottom:

tail

20) To show disk space:

df -H

21) Specific symbol use

#          : root user
$          : normal users
/            : root directory 
~            : home directory

22) Access manual pages for all Linux commands

man

23) Show the name of the kernel (OS)

uname

24) Show the version of the kernel

uname -r

25) Clears the terminal

clear

26) Show the current login user name

whoami

27) Show time and date

date

28) Show this month's calendar

cal

29) Details of the recent login of all users

lastlog

30) Change the directory to the home directory

cd ~ or cd

31) Go to the last working directory.

cd -

32) Change the directory to one step back

cd ..

33) Change the directory to 2 levels back

cd ../..

34) Display the username of all users currently logged on the system

users

35) Add a new user

useradd

36) change existing users' details

usermod

37) to delete the user & group

userdel & groupdel

File permissions

To change the permission of the file

chmod <permission> <file_name>

To show file type and access permission

r -read       u -user
w - write     g -group       
x -execute    o -other

0 - nothing
4 - only read
2 - only write
1 - only execute
4+1 = 5 read and execute
4+2 = 6 read and write both
4+2+1 = 7 read,write and execute

To change file or directory ownership

chown <user_name> <file_name>

To change group ownership

chgrp <group_name> <file_name>

To create the file and edit it

vim or nano

Compresses and decompresses files

gzip

uncompress archive file

unzip

schedules command (especially backup) to be executed automatically

crontab

Access Control List

setfacl and getfacl are used for setting up ACL and showing ACL respectively.

To check ACL permission:

getfacl <name of file or directory>

To set ACL user permission:

setfacl -m u:user:permissions /path_to_file

User management

To create a new user

sudo useradd <user_name>

To set a password for the user

sudo passwd <user_name>

To modify a Linux user

sudo usermod <user_name>

To delete a Linux user

sudo userdel <user_name>

To add a group account

sudo groupadd <group_name>

Process Management

shows the running processes

ps

kill active processes by process ID or name

kill

view active processes live with their system usage

top

Git Commands:

Initialize an empty git repository Transform the current directory into a Git list of all remote repositories that are currently connected to your local repository.

git init

Clone an existing git repository

git clone <repository_url>

Add files and Moves changes from the 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 commit -m "commit_message"

To show the status of your git repository

git status

Git Branch:

To list all of the branches

git branch

Create a new branch

git branch <branch_name>

For going to specific branch

git checkout <branch_name>

For creating and going to that branch

git checkout -b <branch_name>

For deleting branch

git checkout -d <branch_name>

Switches to another branch from the current branch

git switch <branch_name>
git checkout <branch_name>

Removes a branch from git

git branch -d <branch_name>

Git-Logs

shows logs of current branch events with more info

git log

shows logs of branch events in one line

git log --oneline

shows logs in a simple way

git reflog

Remote origin

list of all remote repositories that are currently connected to the local repository:

git remote -v

To add remote origin URL

git remote add origin <remote_git_url>

To remove 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 the local repository

git pull origin <branch_name>

To fetch down all the branches from that Git remote

git fetch

To check your git commits and all logs

git log

Git configuration

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

git config --global user.name <your_username>

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

git config --global user.email <your_email>

To merge two branches in Git

git merge <branch_name>

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 reset

Go back to the specific commit

git reset <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 the top of the stash stack:

git stash pop

Git -squash

combines multiple commits into one

git -squash

Thanks for Reading :)

Shubham Jangale