Terminal Bash
diff¶
differences of 2 stdout outputs¶
egrep¶
Remove lines before and after some strings in a file¶
remove before somestring, retaining somestring¶
awk '/somestring/,0' <pathtofile> > <pathtodeleted_file>
remove after someotherstring, including someotherstring¶
sed -n '/someotherstring/q;p' <pathtofile > <pathtodeleted_file>
Check which ports are busy and which ports are free¶
sudo netstat -tulpn
sudo netstat -antup
sudo lsof -i -n -P
# You can verify process using port /proc:
ls -l /proc/<PID>/exe
List Open Files For Process¶
First you need to find out PID of process. Simply use any one of the following command to obtain process id:
ps aux | grep {program-name}
OR ps -C {program-name} -o pid=
To list open files for firefox process, enter:
ls -l /proc/<PID>/fd
lsof¶
lsof command list open files under all Linux distributions or UNIX like operating system.
Type the following command to list open file for process ID 351:
lsof -p 351
Empty the content of a file without closing it¶
Calculate total used disk space by files older than 180 days using find¶
From stackoverflow, here an example for space occupied by files older than 5 years (1825 days)