Skip to content

Instantly share code, notes, and snippets.

@vyspiansky
Last active November 21, 2023 08:40
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 vyspiansky/d743271b4ad06ff7d41577af21c5c031 to your computer and use it in GitHub Desktop.
Save vyspiansky/d743271b4ad06ff7d41577af21c5c031 to your computer and use it in GitHub Desktop.
Terminal: useful commands

Some Terminal commands

Current user info

whoami

Give me your IP

$ run curl ifconfig.me

Search in file

cat <path> | grab <text to search in file>

Search strings in file

grep -r 'some string' /path/to/file

Which process uses a port (which port is allocated)

Find out the process ID (PID) which is occupying the port number (e.g., 3000)

sudo lsof -i :3000

Kill process by its PID

sudo kill PID

Note: it’s sudo kill -15 PID.

Then if needed

sudo kill -2 PID
sudo kill -1 PID
sudo kill -9 PID

Used ports (a long command)

sudo lsof -PiTCP -sTCP:LISTEN

Find a directory

find / -type d -name 'httpdocs'

Case insensitive and contains the string "Linux"

find /root -type f -iname "*linux*"

Find a file by name case insensitive

find / -type f -iname "file-anme.ext"

Duplicate file permissions

How to duplicate a file's permissions on macOS

chmod `stat -f %A /path/to/source.txt` /path/to/destination.txt

How to duplicate a file's permissions on Linux

chmod --reference=/path/to/source.txt /path/to/destination.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment