Skip to content

Instantly share code, notes, and snippets.

@Hansimov
Last active September 5, 2023 03:52
Show Gist options
  • Save Hansimov/cab44ae4bc3a6d3c9b5447d258fbbd07 to your computer and use it in GitHub Desktop.
Save Hansimov/cab44ae4bc3a6d3c9b5447d258fbbd07 to your computer and use it in GitHub Desktop.
Collection of useful Linux commands in daily work

List some useful Linux commands here.

@Hansimov
Copy link
Author

Hansimov commented Jul 5, 2021

Get head of http(s) response from url:

curl -I <url>

@Hansimov
Copy link
Author

Hansimov commented Jul 7, 2021

Check disk space usage:

ncdu --exclude ~/.snapshot ~

@Hansimov
Copy link
Author

Hansimov commented Jan 30, 2023

Find text or string in all files:

grep -rnw '/path/to/somewhere/' -e 'pattern'
  • -r or -R: recursive
  • -n: show line number
  • -w: match the whole word
  • -l (lower-case L): just show the file name of matching files
  • -e: pattern used during the search

Example:

grep --include=\*.{py,sh} -rnw './script' -e 'threshold'

References:

@Hansimov
Copy link
Author

Hansimov commented Apr 11, 2023

List file structure by tree:

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'

also contain files:

find . | sed -e "s/[^-][^\/]*\//  |/g" -e "s/|\([^ ]\)/|-\1/"

Add alias to ~./.bashrc:

alias lr=ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'
# use `lr` instead of `lt` to avoid default settings `alias lt='ls -lt'`
alias lf=find . | sed -e "s/[^-][^\/]*\//  |/g" -e "s/|\([^ ]\)/|-\1/"

References:

@Hansimov
Copy link
Author

nvidia-smi -q -x | grep pid | sed -e 's/<pid>//g' -e 's/<\/pid>//g' -e 's/^[[:space:]]*//'`

References:

@Hansimov
Copy link
Author

Hansimov commented Sep 5, 2023

List process run on port 28888:

lsof -i:28888

Kill a process run on port 28888:

kill $(lsof -i:28888 | awk 'NR>1 {print $2}')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment