Useful Commands in Ubuntu

Git

Install git

sudo apt install nginx

List local branches

git branch

List remote branches

git branch -r

List all local and remote branches

git branch -a

Change Branch

git checkout <branch_name>
git checkout -b <branch_name>

Stage file (to consider the file in commit)

Stage a particular file

git add <file_name> 

Stage all files

git add -A

Stage new and modified, without deleted

git add 

Stage modified and deleted, without new

git add -u  

Unstage file (Remove staged file from staged files list)

Unstage a particular file

git reset <file_name> 

Unstage all files

git reset 

Take Pull

Pull in active branch from the same branch in server

git pull 

Pull in active branch from master branch server

git pull origin master

Pull in active branch from the specified branch in server

git pull origin <branch_name> 

NPM

Install npm

sudo apt-get install npm 

NPM - Install all dependency packages

npm install

PM2 Process Manager

Install Process Manager (Process Manage is used to run any service 24 hours)

npm install pm2 -g

Start the process to run continuously

pm2 start --name <process_name> <process_command> 

So for e.g. To start the nodejs service with pm2, the command can be like

pm2 start --name node_service node src/app.js

To start reactjs service with pm2, the command can be like

pm2 start --name reactjs_service npm -- start

Check the status of all processes

pm2 [list|ls|status]

Restart/Stop/Delete a particular process

pm2 restart <process_name>
pm2 stop <process_name>
pm2 delete <process_name> 

Restart/Stop/Delete all processes

pm2 restart all
pm2 stop all  
pm2 delete all 

Files & Directories

Create directory

mkdir <dir-name> 

Delete directory

rm <dir-name> -fr 

Delete file

rm <file-name> 

Get directory size

du -h 

Get number of files in a directory

ls | wc -l 

Unzip the zip file

zip -r <file-name>.zip <dir-name>/ 

Redis Commands

Connect with redis server

redis-cli -h <host-name> -p <port> 

Get redis server information

INFO 

List all keys

keys * 

List all keys containing the string "cache"

keys *cache* 

Set value in a key

SET <key-name> <key-value> 

Get value of a particular key

GET <key-name> 

Delete a particular key

DEL <key-name> 

Delete all keys

FLUSHDB 

View processed commands

MONITOR 

AWS CLI Commands

Copy file from local server to s3 bucket or vice-versa

aws s3 cp <source-path> <destination-path>
e.g. 
aws s3 cp my-folder/file1.txt s3://s3-folder/
aws s3 cp s3://s3-folder/file2.txt my-folder/

Copy directory from server to s3 bucket or vice-versa

aws s3 cp <source-path> <destination-path> ./ --recursive
e.g. 
aws s3 cp my-folder s3://s3-folder/ --recursive

Others

List commands history

history | grep ""