Skip to main content

Command Palette

Search for a command to run...

Day12: Linux and Git command cheatsheet

Published
•7 min read•View as Markdown

Linux Commands:

# To check your present working directory:

COPY

pwd

# List all the files or directories

COPY

ls

# Lists hidden files or directories:

COPY

ls -a

# Long listing format:

COPY

ls -l

# Create a new directory:

COPY

mkdir <directory_name>

# Multiple directory creation:

COPY

mkdir -p A/B/C/D

# Remove directory:

COPY

rmdir <directory_name>

# Remove multiple directories:

COPY

rm -rf <directory_name>

# Remove files:

COPY

rm <file_name>

# change directory:

COPY

cd <path_where_to_navigate>

# create an empty file:

COPY

touch <file_name>

# Copy file:

COPY

cp  <source_path> <destination_path>

# Move file:

COPY

mv  <source_path> <destination_path>

# To write some content inside a file:

COPY

echo <some msg> > <file_name>

# Display contents of a file:

COPY

cat <file_name>

# show previous commands/operations performed in shell:

COPY

history

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

COPY

grep "string" <filename>

# Return the specified number of lines from the top:

COPY

head -n #number of line

# Return the specified number of lines from the bottom:

COPY

tail -n #number of line

# To show disk space:

COPY

df -H

File permissions:

# To change the permission of the file

COPY

chmod <permission> <file_name>

eg. chmod 700 a.txt #readwriteexeute to the user only

COPY

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

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

# To change file or directory ownership:

COPY

chown <user_name> <file_name>

# To change group ownership:

COPY

chgrp <group_name> <file_name>

Access Control List:

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

# For check ACL permission:

COPY

getfacl <name of file or directory>

# For set ACL permission to user:

COPY

setfacl -m u:user:permissions /path_to_file

User management:

# To create a new user :

COPY

sudo useradd <user_name>

# To set a password for user:

COPY

sudo passwd <user_name>

# To modify a Linux user:

COPY

sudo usermod <user_name>

# To delete a Linux user:

COPY

sudo userdel <user_name>

# For add group account:

COPY

sudo groupadd <group_name>

COPY

sudo groupadd <group_name>

Git Commands:

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

COPY

git init

# Clone an existing git repository:

COPY

git clone <repository_url>

# Add files and Moves changes from the working directory to the staging area:

COPY

git add <file_name>

# Add all current directory files to git :

COPY

git add .

# Commit all the staged files to git.

COPY

git commit -m "commit_message"

# To show the status of your git repository:

COPY

git status

Git Branch:

COPY

git branch

# Create a new branch:

COPY

git branch <branch_name>

# For going to specific branch:

COPY

git checkout <branch_name>

# for creating and going to that branch:

COPY

git checkout -b <branch_name>

# For deleting branch:

COPY

git checkout -d <branch_name>

Remote origin:

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

COPY

git remote -v

# To add remote origin URL:

COPY

git remote add origin <remote_git_url>

# To remove remote origin URL:

COPY

git remote remove origin

# To upload local repository content to a remote repository:

COPY

git push origin <branch_name>

# To pull your remote repository content to local repository:

COPY

git pull origin <branch_name>

# To fetch down all the branches from that Git remote:

COPY

git fetch

# To check your git commits and all logs:

COPY

git log

git configuration:

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

COPY

git config --global user.name <your_username>

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

COPY

git config --global user.email <your_email>

# to merge two branches in Git:

COPY

COPY

git merge <branch_name>

Cherry-pick:

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

COPY

git cherry-pick [commit_id]

git revert:

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

COPY

git revert <commit_id>

git reset:

# Go back to specific commit:

COPY

git reset <commit_id>

git rebase:

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

COPY

git rebase <other_branch_name>

Temporary commits:

# To save modified and staged changes:

COPY

git stash

# list stack-order of stashed file changes:

COPY

git stash list

# write working from top of stash stack:

COPY

git stash pop

Linux and Git Interview Questions

  1. What is the boot process in Linux?

  2. How to create zero size file Linux?

  3. What is soft link and hard link? How to create? What is the difference between these two?

  4. What is first line written in shell script? What is the meaning of that? If I didn’t write that line what will happen? Then how to run the script?

  5. How to run a shell script in background?

  6. What is cron tab? Explain it? How to configure the schedule a job?

  7. How to allow the ports in Linux?

  8. How to troubleshoot the remote server having some issues?

  9. What is ping? Telnet? Curl? Wget?

  10. How to check the services in Linux machine?

  11. How to kill the process in Linux?

  12. What is inode value?

  13. How to check the CPU utilization?

  14. Difference between Top/HTop?

  15. What is a mount? How to create a mount?

  16. How to troubleshoot live logs?

  17. What is sed command?

  18. What is AWK command

  19. What is grep and egrep?

  20. How to list out the only directories in a Linux?

  21. How to check the process in Linux?

  22. How to check the running ports?

  23. How to declare a variable in a shell script?

  24. How to read a command line input in shell script?

  25. What is umask?

  26. How to change file permission in Linux?

  27. How to connect remote servers without a password? How to achieve this?

  28. How to open files in read-only mode in the VI editor?

  29. What is the purpose of export command?

Git Interview questions

  1. What is git?

  2. What is difference between git and GitHub and GitLab?

  3. Are any other version control tools other than git?

  4. What is difference between svn and git?

  5. What is merge conflicts have you faced ever in your experience? if you face ahow you resolve it?

  6. What is git stash?

  7. What is git HEAD?

  8. What is staging area in git?

  9. What is difference between git fetch and pull and clone?

  10. What is difference between git merge and rebase?

  11. What is .gitignore file? What is the purpose of the file?

  12. What is git branch? Have you worked on branches?

  13. How to merge branches?

  14. What is cherry-pick in git?

  15. How to create a git project?

  16. How to check difference in between two files?

  17. How edit the committed message?

  18. How to check the last few commits?

  19. How to delete remote branch and local branch?

  20. How to create local branch?

  21. What is tag? How many types in tag? How we will create tags?

  22. How to roll back committed code.

  23. Git branch strategy

  24. How to check the difference in file between working are and staging area ?