Skip to content

Instantly share code, notes, and snippets.

@prerakmody
Last active September 14, 2021 14:08
Show Gist options
  • Save prerakmody/3bfc1755be4fa02c939f54cf8e0ebced to your computer and use it in GitHub Desktop.
Save prerakmody/3bfc1755be4fa02c939f54cf8e0ebced to your computer and use it in GitHub Desktop.
Useful Ubuntu Commands

PORTS

  1. Checking the process running on a port
    • lsof -i :<port_number>
    • sudo netstat -peanut | grep <port_number>
  2. Checking processes
    • ps aux | grep <process_name>

LOGS

  1. Checking logs of various processes
    • tail -f /var/log/<>.log

Run a simple rsync

  • rsync -azPh --dry-run -e "ssh -i key.pem" [email protected]:/home/ubuntu/datasets/lidar/SCANS/ ./
  • rsync -azPh -e "ssh -i key.pem" [email protected]:/home/ubuntu/datasets/lidar/SCANS/ ./
  • rsync -v --stats --progress -azh -e "ssh -i key.pem" [email protected]:/home/ubuntu/datasets/lidar/SCANS/ ./
  • - a : archive / recursive
    - z : compress
    - h : human readable
    - P : progress
    

Run a rsync for extended duration

  • n=0; while [[ $n -lt 10 ]]; do rsync -rvzhu -e ssh playment-gpu:/home/play/data/pspnet/processed/driveai/*_overlay.jpeg ./; sleep 5; n=$((n+1)); done

Killing Processes

  • ps ax | grep 'ipykernel' | awk -F ' ' '{print $1}' | xargs sudo kill -9

Finding File Count in a folder

  • ll | wc -l

Find a file/folder using findutils

  • find ./ -iname '*data*'
  • find /usr -iname '*opencv*'
  • find ./ -iname '*cuda*'

HTOP

  • sudo apt install htop
  • htop
  • htop -p <pid>
  • htop --pid=<pid1>,<pid2>

Jupyter Process

  • ps aux | grep jupyter/kernel
  • ps aux | grep jupyter/kernel | awk -F ' ' '{print $2}'

Single Process

  • ps aux | grep jupyter/kernel | awk -F ' ' '{print $2}' | head -n 1
  • pid_jupyterkernel=$(ps aux | grep jupyter/kernel | awk -F ' ' '{print $2}' | head -n 1)
    • echo $pid_jupyterkernel
  • pid_jupyterkernel=$(ps aux | grep jupyter/kernel | awk -F ' ' '{print $2}' | head -n 1) && htop -p $pid_jupyterkernel
  • Adding to ~/.basrhc
    • alias jupyter_htop="pid_jupyterkernel=$(ps aux | grep jupyter/kernel | awk -F ' ' '{print $2}' | head -n 1) && htop -p $pid_jupyterkernel"
    • You can press "Shift + h" (for capital H) and avoid seeing all the child processes

All Process

  • pid_jupyterkernel=$(ps aux | grep jupyter/kernel | awk -F ' ' '{print $2}' | tr '\n' ',') && htop --pid=$pid_jupyterkernel
  • Adding to ~/.basrhc
    • alias jupyter_htop="pid_jupyterkernel=$(ps aux | grep jupyter/kernel | awk -F ' ' '{print $2}' | tr '\n' ',') && htop --pid=$pid_jupyterkernel"
    • alias jupyter_htop="pid_jupyterkernel=$(ps aux | grep jupyter/kernel | awk -F ' ' '{print $2}' | tr '\n' ',') && echo $pid_jupyterkernel && sleep 3 && htop --pid=$pid_jupyterkernel"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment