Useful Command
useful tools¶
Memory monitor command¶
Note that Linux likes to use any extra memory to cache hard drive blocks. So you don’t want to look at just the free Mem. You want to look at the free column of the -/+ buffers/cache: row.
This shows how much memory is available to applications. So I just ran free -m and got this:
Reminder: To stop this watch cycle you can just press Ctrl+C.
The watch command can be also used for monitoring other data with time update
Process name(PID)¶
ps listed every process that is running
with pgrep and pidof, it will only return PID of the program name
It can also reach by program itself
c code¶
#include <stdio.h>
#include <unistd.h>
int main() {
pid_t pid = getpid();
printf("The PID of this process is: %d\n", pid);
return 0;
}
python¶
We can write it to a script also.
Process Info in Linux¶
Files located in /proc/[pid]/ provides tons of information about process including kernel content, complete docs can be found here
The directory /proc contains (among other things) one subdirectory for each process running on the system, which is named after the process ID (PID).
if there is any doubt, review the kernel documentation in the directory /usr/src/linux/Documentation.
status¶
overview of process information, such as virtual memory, code and heap…so on
This shows you nearly the same information you would get if you viewed it with the ps command. In fact, ps uses the proc file system to obtain its information. But you get a more detailed view of the process by reading the file /proc/PID/status.
maps¶
further information about memory mapping, address range…so on
The /proc/PID/maps file contains the currently mapped memory regions and their access permissions.
smaps¶
much further information about each memory location of info, RSS(Resident Set Size), PSS(Proportional Set Size)…so on
The /proc/PID/smaps is an extension based on maps, showing the memory consumption for each of the process’s mappings.
Like before, we can also write sript for automation, this time it’s done by using python script
VS Code¶
ctrl+shift+del: clear terminal
ssh¶
scp¶
copy files between ssh server and client
*-r : 複製整個目錄*
-p : 保留檔案時間與權限*
-c : 資料壓縮
git¶
拉遠端的branch, 又想保存本地端修改
修改commit訊息
如果是要修改已經push上去的commit message,需要用rebase的方式修改 Ref
而修改當前訊息,僅需要用--amend修改即可
VIM¶
replace string in current line
replace all matched line
replcae all matched character and line
select and highlight the current bracket, use v+i+w