Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Linux basic command cheatsheet for developers

Basic Linux Commands

Remote access to server using SSH

  1. Using username and password
    ssh user@hostname
    ssh user@ip
  2. Using a key file
    ssh -i /path/to/key/file.pem user@ip_or_hostname

Directory navigation commands

  • Print currenct directory
  • Change to specific directory
cd /path/to/directory

Listing of files

  1. List all the files in a directory
ls -l
  1. List the files including hidden
ls -la 
  1. List the files based on creation time
ls -lt

Directory commands

  1. Creating a directory
mkdir name-of-dir
  1. Deleting a directory ( works only when the directory is empty )
rmdir name-of-dir
  1. Delete the contents of a directory recursively ( Please use this with caution )
rm -rf directory/

vi editor commands

  1. Opening a file
vi filename
  1. Editing a file
Press <i> to start insert mode
  1. Saving a file
  1. Exiting the editor by ignoring the changes
  1. Quit the editor

Tailing a file

  • Continously tail a log file
tail -f filename
  • View the last n lines from the file
tail -n <number-of-lines> filename

Resource monitoring

  1. View the current processes, cpu and memory
  1. View the current free and available memory
free -m
  1. View the current mounts and free space
  1. View the size of the files and folders
du -sh * 

Making an API / webservice call using cURL

  1. Simple GET request
curl -X GET "http://server:port/api/endpoint"
  1. GET with headers
curl -H "Authorization:Basic xxxx" -X GET "http://server:port/api/endpoint"
  1. POST call with params
curl -H "Authorization: Basic xxx" -H "Content-Type: application/x-www-form-urlencoded" --data "grant_type=password&username=test&password=secret&client_id=trustedService" -X POST http://localhost:50002/oauth/token

Running a command continously

watch command 

Getting the network IP address or interface details


Find the process id using port number of application

lsof -i:portnumber

Killing a process

  1. Using process id ( gracefully )
kill -9 processid
  1. Kill by process name
killall processname

More Details

You can get more details on the above commands at the following link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.