Friday, August 11, 2023

Unix : Most relevant commands

netstat -tonp | grep CLOSE_WAIT   //CLOSE_WAIT means your program is still running, and hasn't closed the socket 

netstat -p  // connections with processId. kill -9 <P_ID> to kill the close_wait connection

sudo lsof -i: <port_number>  | grep <port_number>  // port in use

Running port details: netstat -an 

Get IP: hostname -I 

List of files:  ls -1 | wc -l

Size subdirectories wise: sudo du -hs *

du -h /path/to/directoy | sort -rh

Find file: find . -name searchable_file.txt

sudo find / -name file_to_search | grep part_text

Find text in subdirectories/files grep -rl 'search_text' / or *

change owner to user1/group1 chown user1:group1 file_name

Emptying file: truncate -s 0 file.txt

execute permission chmod u+x file_name

Switching user: sudo su new_user, sudo -s

Processes: top [htop on hypervisor]

Memory: free -g 

Memory usage df -h/m/g

              total        used        free      shared  buff/cache   available

Mem:            --         ---          ---      ---        --        --

Swap:           --           --           --



No comments:

Post a Comment