Skip to content

Instantly share code, notes, and snippets.

@microideation
Last active November 3, 2018 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save microideation/75c3c4d7e2f0a055628abb1ff93b1972 to your computer and use it in GitHub Desktop.
Save microideation/75c3c4d7e2f0a055628abb1ff93b1972 to your computer and use it in GitHub Desktop.
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
pwd
  • 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
:w
  1. Exiting the editor by ignoring the changes
:q!
  1. Quit the editor
:q

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
top
  1. View the current free and available memory
free -m
  1. View the current mounts and free space
df
  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


ipconfig

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