List some useful Linux commands here.
Last active
September 5, 2023 03:52
-
-
Save Hansimov/cab44ae4bc3a6d3c9b5447d258fbbd07 to your computer and use it in GitHub Desktop.
Collection of useful Linux commands in daily work
get ip from domain:
dig +short xxx.yyy.com
- Linux command to translate DomainName to IP - Stack Overflow
Get head of http(s) response from url:
curl -I <url>
Check disk space usage:
ncdu --exclude ~/.snapshot ~
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:
- How to find all files containing specific text (string) on Linux? - Stack Overflow
- grep Man Page - Linux - SS64.com
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:
- Linux command to print directory structure in the form of a tree - Stack Overflow
nvidia-smi -q -x | grep pid | sed -e 's/<pid>//g' -e 's/<\/pid>//g' -e 's/^[[:space:]]*//'`
References:
- cuda - How do I customize nvidia-smi 's output to show PID username? - Stack Overflow
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
copy directory content recursively:
cp -a <src>/. <dst>/
-a
option is an improved recursive option, that preserve all file attributes, and also preserve symlinks..
at end of the source path is a specificcp
syntax that allow to copy all files and folders, included hidden ones.command line - How can I copy the contents of a folder to another folder in a different directory using terminal? - Ask Ubuntu
Another solution:
cp -R <src>/* <dst>