一些常用的命令
Published by powerfulyang on Feb 27, 2022
DNS
刷新 DNS 缓存
- Windows
ipconfig /flushdns
- 其余的暂时还没用到 macOS, CentOS
Docker
- 清空无用的 images
docker image prune -a
网络
netstat
下面的命令仅测试过 linux
netstat -tunlp
- -t (tcp) 仅显示tcp相关选项
- -u (udp) 仅显示udp相关选项
- -n 拒绝显示别名,能显示数字的全部转化为数字
- -l 仅列出在Listen(监听)的服务状态
- -p 显示建立相关链接的程序名
traceroute 简单用法
也是只在 linux 使用
traceroute [-n] -T -p [$Port] [$Host]
- -n:直接使用IP地址而非主机名称(禁用DNS反查)。
- -T:通过TCP探测。
- -p:设置探测的端口号。
- [$Port]:需要探测的端口号,比如80。
- [$Host]:需要探测的目标服务器地址,比如
10.10.1.1
。
相关 Windows 下使用 tracecert
route 命令
- Windows,
route print
- Linux,
route -n
文件查看搜索
查看日志
-
可以使用head(查看前几行)、tail(查看末尾几行)两个命令。
查看/etc/profile的前10行内容,应该是:head -n 10 /etc/profile
查看/etc/profile的最后5行内容,应该是:tail -n 5 /etc/profile
注意:tail -n 1000
显示最后1000行tail -n +1000
从1000行开始显示,显示1000行以后的head -n 1000
显示前面1000行
-
sed 命令
sed -n '5,10p' filename
这样你就可以只查看文件的第5行到第10行。
Disk
显示磁盘空间信息 (df)
- 使用
df -k
命令以千字节为单位显示磁盘空间信息。-k
表示 kb-m
表示 mb-g
表示 gb
1df -k
2Filesystem kbytes used avail capacity Mounted on
3/dev/dsk/c0t3d0s0 192807 40231 133296 24% /
- 其中每列的含义
字段名 说明 kbytes 文件系统中可用空间的总大小 used 已用空间 avail 可用空间 capacity 已用空间百分比 mounted on 挂载点
Understanding Linux File Permissions
example: drwxrwxrwx
第一位代表文件类型,有两个数值:“d”和“-”,“d”代表目录,“-”代表非目录。
后面9位可以拆分为3组来看,分别对应不同用户,2-4位代表所有者 user 的权限说明,5-7位代表组群 group 的权限说明,8-10位代表其他人 other 的权限说明。
r 代表可读权限,w 代表可写权限,x 代表可执行权限。
drwxrwxrwx 表示所有用户都对这个目录有可读可写可执行权限。
Permission Groups
- u 代表所有者 (user)-The Owner permissions apply only the owner of the file or directory, they will not impact the actions of other users.
- g 代表所有者所在的组和群 (group)-The Group permissions apply only to the group that has been assigned to the file or directory, they will not effect the actions of other users.
- o 代表其他人但不是 u 和 g(other)
- a 代表全部人 - The All Users permissions apply to all other users on the system, this is the permission group that you want to watch the most.
Permission Types
- read – The Read permission refers to a user’s capability to read the contents of the file.
- write – The Write permissions refer to a user’s capability to write or modify a file or directory.
- execute – The Execute permission affects a user’s capability to execute a file or view the contents of a directory.
Advanced Permissions
- _ – no special permissions
- d – directory
- l – The file or directory is a symbolic link
- s – This indicated the setuid/setgid permissions. This is not set displayed in the special permission part of the permissions display, but is represented as a s in the read portion of the owner or group permissions.
- t – This indicates the sticky bit permissions. This is not set displayed in the special permission part of the permissions display, but is represented as a t in the executable portion of the all users permissions
r,w,x 可以用数字表示 r=0x100 w=0x10 x=0x1
- rw------- (600) 只有所有者才有读和写的权限
- rw-r–r-- (644) 只有所有者才有读和写的权限,组群和其他人只有读的权限
- rwx------ (700) 只有所有者才有读,写,执行的权限
- rwxr-xr-x (755) 只有所有者才有读,写,执行的权限,组群和其他人只有读和执行的权限
- rwx–x--x (711) 只有所有者才有读,写,执行的权限,组群和其他人只有执行的权限
- rw-rw-rw- (666) 每个人都有读写的权限
Change Permissions
The potential Assignment Operators are + (plus) and – (minus); these are used to tell the system whether to add or remove the specific permissions.
use command chmod
to modify permissions;
- To make this modification you would invoke the command: chmod a-rw file1
- To add the permissions above you would invoke the command: chmod a+rw file1
- You use the chown command to change owner and group assignments, the syntax is simple
chown owner:group filename
, so to change the owner of file1 to user1 and the group to family you would enter chown user1 file1.