# Linux and Github (Cheat sheet)

#90DaysOfDevOps

# Linux Basics commands

<table><tbody><tr><td colspan="1" rowspan="1"><p>To check your current working directory</p></td><td colspan="1" rowspan="1"><p>pwd</p></td></tr><tr><td colspan="1" rowspan="1"><p>list all the files and directories</p></td><td colspan="1" rowspan="1"><p>ls</p></td></tr><tr><td colspan="1" rowspan="1"><p>list hidden files or directories</p></td><td colspan="1" rowspan="1"><p>ls -a</p></td></tr><tr><td colspan="1" rowspan="1"><p>list files in sub-directories as well</p></td><td colspan="1" rowspan="1"><p>ls -R</p></td></tr><tr><td colspan="1" rowspan="1"><p>list files and directories with detailed information like; permission, size and owner etc</p></td><td colspan="1" rowspan="1"><p>ls -la</p></td></tr><tr><td colspan="1" rowspan="1"><p>create new directory</p></td><td colspan="1" rowspan="1"><p>mkdir&lt;dir_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>To create multiple directories</p></td><td colspan="1" rowspan="1"><p>mkdir -p A/B/C/D</p></td></tr><tr><td colspan="1" rowspan="1"><p>To remove directory</p></td><td colspan="1" rowspan="1"><p>rmdir&lt;dir_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>To remove multiple directories</p></td><td colspan="1" rowspan="1"><p>rm -rf &lt;dir_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>to change directory</p></td><td colspan="1" rowspan="1"><p>cd or cd~</p></td></tr><tr><td colspan="1" rowspan="1"><p>Move to the root directory</p></td><td colspan="1" rowspan="1"><p>cd/</p></td></tr><tr><td colspan="1" rowspan="1"><p>to change to a particular directory</p></td><td colspan="1" rowspan="1"><p>cd</p></td></tr><tr><td colspan="1" rowspan="1"><p>Allows regular users to run programs with the security privileges of the superuser or root</p></td><td colspan="1" rowspan="1"><p>sudo</p></td></tr><tr><td colspan="1" rowspan="1"><p>create an empty file</p></td><td colspan="1" rowspan="1"><p>touch&lt;file_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>Delete a file</p></td><td colspan="1" rowspan="1"><p>rm &lt;file_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>Copy file</p></td><td colspan="1" rowspan="1"><p>cp&lt;source_path&gt; &lt;destination_path&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>move file</p></td><td colspan="1" rowspan="1"><p>mv&lt;source_path&gt; &lt;destination_path&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>To write some content inside a file</p></td><td colspan="1" rowspan="1"><p>echo&lt;mssg&gt; &gt; &lt;file_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>Display the file contents</p></td><td colspan="1" rowspan="1"><p>cat &lt;file_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>Gives a list of all past commands typed in the current terminal session</p></td><td colspan="1" rowspan="1"><p>history</p></td></tr><tr><td colspan="1" rowspan="1"><p>clear the terminal</p></td><td colspan="1" rowspan="1"><p>clear</p></td></tr><tr><td colspan="1" rowspan="1"><p>To search a word</p></td><td colspan="1" rowspan="1"><p>grep"str" &lt;file_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>Return the specified number of lines from the top</p></td><td colspan="1" rowspan="1"><p>head</p></td></tr><tr><td colspan="1" rowspan="1"><p>Return the specified number of lines from the bottom</p></td><td colspan="1" rowspan="1"><p>tail</p></td></tr><tr><td colspan="1" rowspan="1"><p>Display disk filesystem information</p></td><td colspan="1" rowspan="1"><p>df</p></td></tr><tr><td colspan="1" rowspan="1"><p>Mount file system</p></td><td colspan="1" rowspan="1"><p>mount</p></td></tr><tr><td colspan="1" rowspan="1"><p>Display the user manual of any command</p></td><td colspan="1" rowspan="1"><p>man</p></td></tr><tr><td colspan="1" rowspan="1"><p>Find the files and directories path</p></td><td colspan="1" rowspan="1"><p>find</p></td></tr><tr><td colspan="1" rowspan="1"><p>List the hostname of the server</p></td><td colspan="1" rowspan="1"><p>hostname</p></td></tr></tbody></table>

# Linux File Permission Commands

<table><tbody><tr><td colspan="1" rowspan="1"><p>To change the permission of the file</p></td><td colspan="1" rowspan="1"><p>chmod&lt;permission&gt; &lt;file_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>To show file type and access permission</p></td><td colspan="1" rowspan="1"><p>ls -l</p></td></tr><tr><td colspan="1" rowspan="1"><p>To change file or directory ownership</p></td><td colspan="1" rowspan="1"><p>chown&lt;user_name&gt; &lt;file_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>To change group ownership</p></td><td colspan="1" rowspan="1"><p>chgrp&lt;group_name&gt; &lt;file_name&gt;</p></td></tr></tbody></table>

# User Management Commands of Linux

<table><tbody><tr><td colspan="1" rowspan="1"><p>To create a new user</p></td><td colspan="1" rowspan="1"><p>sudo useradd&lt;user_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>To set a password for the user</p></td><td colspan="1" rowspan="1"><p>sudo passwd &lt;user_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>To modify a Linux server</p></td><td colspan="1" rowspan="1"><p>sudo usermod &lt;user_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>To delete a linux user</p></td><td colspan="1" rowspan="1"><p>sudo userdel &lt;user_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>For adding a group account</p></td><td colspan="1" rowspan="1"><p>sudo groupadd &lt;group_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>to add a user to a group</p></td><td colspan="1" rowspan="1"><p>sudo usermod -a -G &lt;groupname&gt; &lt;username&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>To remove a user from a group</p></td><td colspan="1" rowspan="1"><p>sudo deluser &lt;user&gt; &lt;group_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>Gives information about a particular user</p></td><td colspan="1" rowspan="1"><p>finger</p></td></tr><tr><td colspan="1" rowspan="1"><p>List all the files and directories in the present working directory</p></td><td colspan="1" rowspan="1"><p>finger username</p></td></tr></tbody></table>

# Access Control List

<table><tbody><tr><td colspan="1" rowspan="1"><p>For checking ACL permission</p></td><td colspan="1" rowspan="1"><p>getfacl &lt;name of the file or directory&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>To set ACL permission to the user</p></td><td colspan="1" rowspan="1"><p>setfacl -m u:user:permissions/path_to_file</p></td></tr></tbody></table>

# Git Commands

## Git configuration:

<table><tbody><tr><td colspan="1" rowspan="1"><p>To set author name to be used for all commits by the current user</p></td><td colspan="1" rowspan="1"><p>git config --global user.name &lt;"name"&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>to set author email to be used for all commits by the current user</p></td><td colspan="1" rowspan="1"><p>git config --global user.email &lt;"email"&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>To show config info</p></td><td colspan="1" rowspan="1"><p>git config --list</p></td></tr></tbody></table>

# Git Basics

<table><tbody><tr><td colspan="1" rowspan="1"><p>Initialize an empty git repository</p></td><td colspan="1" rowspan="1"><p>git init</p></td></tr><tr><td colspan="1" rowspan="1"><p>Clone an existing git repository</p></td><td colspan="1" rowspan="1"><p>git clone &lt;repo_url&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>Add files and move changes from working directory to the staging area</p></td><td colspan="1" rowspan="1"><p>git add &lt;file_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>Add all current directory files to git</p></td><td colspan="1" rowspan="1"><p>git add .</p></td></tr><tr><td colspan="1" rowspan="1"><p>Commit all the staged files to git</p></td><td colspan="1" rowspan="1"><p>git commands -m "commit messages"</p></td></tr><tr><td colspan="1" rowspan="1"><p>To show the status of your git repository</p></td><td colspan="1" rowspan="1"><p>git status</p></td></tr><tr><td colspan="1" rowspan="1"><p>To check your git commits and all logs</p></td><td colspan="1" rowspan="1"><p>git log</p></td></tr><tr><td colspan="1" rowspan="1"><p>Show unstaged changes between your index and working directory</p></td><td colspan="1" rowspan="1"><p>git diff</p></td></tr></tbody></table>

# Git Branches

<table><tbody><tr><td colspan="1" rowspan="1"><p>To list all of the branches</p></td><td colspan="1" rowspan="1"><p>git branch</p></td></tr><tr><td colspan="1" rowspan="1"><p>Create a new branch</p></td><td colspan="1" rowspan="1"><p>git branch &lt;branch_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>For creating and going to that branch</p></td><td colspan="1" rowspan="1"><p>git checkout -b &lt;branch_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>For going to specific branch</p></td><td colspan="1" rowspan="1"><p>git checkout &lt;branch_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1"><p>Merge branch into current branch</p></td><td colspan="1" rowspan="1"><p>git merge &lt;branch_name&gt;</p></td></tr></tbody></table>

# Remote Repositories

<table><tbody><tr><td colspan="1" rowspan="1" colwidth="495"><p>List of all remote repo that are currently connected to local repo</p></td><td colspan="1" rowspan="1"><p>git remote -v</p></td></tr><tr><td colspan="1" rowspan="1" colwidth="495"><p>To add remote origin URL</p></td><td colspan="1" rowspan="1"><p>git remote add origin &lt;remote_git_url&gt;</p></td></tr><tr><td colspan="1" rowspan="1" colwidth="495"><p>To remove the remote origin URL</p></td><td colspan="1" rowspan="1"><p>git remote remove origin</p></td></tr><tr><td colspan="1" rowspan="1" colwidth="495"><p>To upload local repository content to a remote repository</p></td><td colspan="1" rowspan="1"><p>git push origin &lt;branch_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1" colwidth="495"><p>To pull your remote repository content to local repository</p></td><td colspan="1" rowspan="1"><p>git pull origin &lt;branch_name&gt;</p></td></tr><tr><td colspan="1" rowspan="1" colwidth="495"><p>To fetch down all the branches from that git remote</p></td><td colspan="1" rowspan="1"><p>git remote</p></td></tr></tbody></table>

# Cherry-pick

<table><tbody><tr><td colspan="1" rowspan="1"><p>Merge just one specific commit from another branch to your current branch</p></td><td colspan="1" rowspan="1"><p>git cherry-pick&lt;commit_id&gt;</p></td></tr></tbody></table>

# Git Revert

<table><tbody><tr><td colspan="1" rowspan="1"><p>Undo a single given commit, without modifying commits that come after it</p></td><td colspan="1" rowspan="1"><p>git revert &lt;commit_id&gt;</p></td></tr></tbody></table>

# Git Rebase

<table><tbody><tr><td colspan="1" rowspan="1"><p>To rebase all the commits between another branch and the current branch state</p></td><td colspan="1" rowspan="1"><p>git rebase&lt;other_branch_name&gt;</p></td></tr></tbody></table>

# Temporary commits

<table><tbody><tr><td colspan="1" rowspan="1"><p>To save modified and staged changes</p></td><td colspan="1" rowspan="1"><p>git stash</p></td></tr><tr><td colspan="1" rowspan="1"><p>List stack-order of stashed file changes</p></td><td colspan="1" rowspan="1"><p>git stash list</p></td></tr><tr><td colspan="1" rowspan="1"><p>Write working from top of stash stack</p></td><td colspan="1" rowspan="1"><p>git stash pop</p></td></tr><tr><td colspan="1" rowspan="1"><p>Discard the changes from the top of the stash stack</p></td><td colspan="1" rowspan="1"><p>git stash drop</p></td></tr><tr><td colspan="1" rowspan="1"><p>apply the stash without removing it from the list</p></td><td colspan="1" rowspan="1"><p>git stash apply</p></td></tr></tbody></table>

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

**~Prabhakar Yadav**
