Linux Command Shell Scripting Cheatsheet:
- Basic commands:
ls
: lists files and directoriescd
: changes directorypwd
: prints the working directorymkdir
: creates a new directoryrm
: removes files or directoriescp
: copies files or directoriesmv
: moves files or directoriescat
: displays file contentsgrep
: searches for a pattern in a file or outputecho
: prints a message to the terminalchmod
: changes file permissionssudo
: executes a command as the superuser
- Variables:
To define a variable:
variable_name=value
To access a variable:
$variable_name
To use arithmetic operations:
$(($variable_name + 1))
- Control structures:
if
statement:
if [ condition ]; then
command1
else
command2
fi
for
loop:
for variable in list; do
command
done
while
loop:
while [ condition ]; do
command
done
- Functions:
- To define a function:
function_name() {
command1
command2
}
- To call a function:
function_name
- Input/output:
read
command: reads input from the user
read variable_name
echo
command: prints output to the terminal
echo "message"
Git and GitHub Cheatsheet:
- Basic commands:
git init
: initializes a new Git repositorygit clone
: clones a remote Git repositorygit add
: adds changes to the staging areagit commit
: commits changes to the repositorygit push
: pushes changes to a remote repositorygit pull
: pulls changes from a remote repositorygit status
: displays the status of the repositorygit log
: displays the commit history
- Branching:
git branch
: lists all branchesgit branch branch_name
: creates a new branchgit checkout branch_name
: switches to a different branchgit merge branch_name
: merges a branch into the current branch
- Collaboration:
git remote
: lists all remote repositoriesgit remote add remote_name remote_url
: adds a new remote repositorygit fetch
: fetches changes from a remote repositorygit merge origin/branch_name
: merges changes from a remote branch into the current branchgit pull --rebase
: pulls changes from a remote repository and rebases local changes on top
- GitHub:
git push -u origin branch_name
: pushes a new branch to a remote repositorygit pull-request
: creates a new pull requestgit remote add upstream upstream_url
: adds the original repository as a remote upstreamgit fetch upstream
: fetches changes from the original repositorygit merge upstream/master
: merges changes from the original repository into the current branch
Note: It's important to ensure that your changes are well tested before pushing to the remote repository, and to always fetch and merge changes before pushing your own changes to prevent conflicts.