Skip to content

Instantly share code, notes, and snippets.

@sirusdas
Last active August 12, 2025 06:02
Show Gist options
  • Select an option

  • Save sirusdas/0da925f4168268334c5dcde41f1de9ce to your computer and use it in GitHub Desktop.

Select an option

Save sirusdas/0da925f4168268334c5dcde41f1de9ce to your computer and use it in GitHub Desktop.
Useful terminal commands( Ubuntu and other..)

Get a running process details

ps -fax | grep node

Froce a process to kill itself( Zombie Kill )

kill -9 process_id

Finding the PID of the process using a specific port?

$ sudo ss -lptn 'sport = :80' or $ sudo netstat -nlp | grep :80 or $ sudo lsof -n -i :80 | grep LISTEN

Check which process is using more memory

ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head

Download all the files of a specific file format(eg .mp3) using terminal

wget -c -A '*.mp3' -r -l 1 -nd http://example.org/musics/

-c: continue getting a partially-downloaded file.
-A: only accept mp3 files. change this format with another format you want to download.
-r: recurse
-l 1: one level deep (ie, only files directly linked from this page)
-nd: don't create a directory structure, just download all the files into current directory.

Search any text in any file in a directory and sub-directories

grep -r

Search for first occurance

grep -ri -m1 '*.coffee'

Increase the specker vol

amixer -D pulse sset Master 5%+

Change both owner and the group

chown sirus:friends tmpfile https://www.thegeekstuff.com/2012/06/chown-examples/

To remove the lock file in the /var/lib/dpkg/ directory:

sudo rm /var/lib/dpkg/lock sudo dpkg --configure -a

Alternatively, delete the lock files in the /var/lib/apt/lists/ and cache directory as below

sudo rm /var/lib/apt/lists/lock sudo rm /var/cache/apt/archives/lock

Update your packages sources

sudo apt update sudo apt-get update

Bash find files between two dates:

find . -type f -newermt 2010-10-07 ! -newermt 2014-10-08

Recursive, Non-Overwriting File Copy?

sudo cp -vnpr /xxx/* /yyy

xxx = source

yyy = destination

v = verbose

n = no clobber (no overwrite)

p = preserve permissions

r = recursive

Find between date range and copy the files to a different server using scp

sudo find . -type f -newermt 2019-04-11 ! -newermt 2019-04-24 -exec scp -i /var/www/furtadosonline/furtadosonline.pem {} [email protected]:/webapps/ftp_uploads ;

Will copy after 11 and before 24 to the respective server. It will list all files even within sub-directories but wont create dir's on the uploading server.

Replacing all occurrences of one string with another in all files in the current directory

Non recursive, files in this directory only:

sed -i -- 's/foo/bar/g' *

Sed command allows you to change the delimiter / to something else. So I am going to use +:

sed -i -- 's+foo+bar+g' *

View tmp size or clean it up older than 10 days files

df -k /tmp
sudo find /tmp -type f -atime +10 -delete

Getting the Size of a Directory top 5 files taking more space > https://linuxize.com/post/how-get-size-of-file-directory-linux/

sudo du -h /var/ | sort -rh | head -5

Find a file in a date, month etc range

find /path/to/dir -type f -name "*" -newermt 2013-02-07 ! -newermt 2013-02-08

Ultimate Zip command

zip -r ../workspace.zip .
-x "/.git/*"
-x "
/.DS_Store"
-x "/node_modules/*"
-x "
/build/"
-x "**/dist/
"
-x "/vendor/*"
-x "
/target/"
-x "**/pycache/
"
-x "/.venv/*"
-x "
/bin/"
-x "**/_build/
"
-x "/log/*"
-x "
/temp/"
-x "/pubspec.lock"
-x "
/.dart_tool/
"
-x "/ios/Pods/*"
-x "
/android/.gradle/"
-x "**/android/app/build/
"
-x "/Lib/*"
-x "
/lib/*"

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