The most complete collection of Linux commands on the Internet

Collection of introductory commands

   \# 基础命令  
   ls:列出目录的内容及其内容属性信息。  
  cd:切换当前工作目录对应的目录  
  cp:复制文件或目录。  
  find:用来在指定目录及目录下查找文件。  
  mkdir:创建目录。  
  mv:移动或重命名文件。  
  pwd:显示当前工作目录的绝对路径。  
  rename:可用字符串替换的方式批量改变文件名。  
  rm:删除一个或多个文件或目录。必须格外小心地使用该命令。  
  rmdir:删除空目录。  
  touch:建立一个新的文件。  
  tree:以树状图列出目录的内容  
  basename:显示文件名  
  dirname:显示给定路径的目录部分。  
  chattr:改变文件的扩展属性。  
  lsattr:显示文件扩展属性。  
  file:用来识别文件类型。  
  md5sum:用于生成和校验文件的md5值。它会逐位对文件的内容进行校验,它常用于检查文件的完整性。  


  #  查看文件及内容处理命令  
  cat:用于连接多个文件并且打印到屏幕输出或重定向到指定文件中,可查看文件内容。  
  tac:文件内容的最后一行先显示,第一行最后显示。  
  more:一页一页的形式显示文件内容  
  less:可以随意浏览文件,而 more 仅能向前移动,却不能向后移动,而且 less 在查看之前不会加载整个文件。  
  head:显示文件的开头的内容。  
  tail:查看文件尾部内容,有一个常用的参数 \-f 常用于查阅正在改变的文件。可以看到最新的文件内容。  
  cut:将文件的每一行按指定分隔符分割并输出。  
  split:分割文件为不同的小片段。  
  paste:用于合并文件的列。paste指令会把每个文件以列对列的方式,一列列地加以合并。  
  sort:将文本文件内容加以排序,sort可针对文本文件的内容,以行为单位来排序。  
  uniq:用于检查及删除文本文件中重复出现的行列。  
  wc:统计文件的行数、单词数或字节数等。  
  iconv:转换文件的编码格式。  
  diff:diff以逐行的方式比较文件的差异。  
  vimdiff:命令行可视化文件比较工具,常用于文本文件。  
  rev:将文件中的每行内容以字符为单位反序输出  
  grep/egrep:可以通过使用指定的通配符/正则表达式来实现文本搜索功能。  
  join:用于将两个文件中,指定栏位内容相同的行连接起来  
  tr:tr命令用于转换或删除文件中的字符  
  vi/vim:vi编辑器是所有Unix及Linux系统下标准的编辑器  
  \# 文件压缩及解压缩命令  
  tar:建立,还原备份文件的工具程序,它可以加入,解开备份文件内的文件。  
  unzip:用于解压缩zip文件。  
  gzip:用于压缩文件  
  zip:用来将文件压缩成为常用的zip格式。

    # 信息显示命令  
  dmesg:用于显示开机信息,诊断系统故障  
  uptime:显示系统运行时间及负载。  
  stat:用于显示文件和文件系统状态属性。  
  du:显示指定的目录或文件所占用的磁盘空间。  
  df:显示目前在Linux系统上的文件系统的磁盘使用情况统计。  
  free:显示Linux系统中空闲的、已用的物理内存及swap内存,及被内核使用的buffer。在Linux系统监控的工具中,free命令是最经常使用的命令之一。  
  date:显示或设定系统的日期与时间,在显示方面,使用者可以设定欲显示的格式。  
  cal:显示公历日历。
  
  \# 搜索文件命令  
  which:查找文件  
  find:从磁盘遍历查找文件或目录。  
  whereis:该指令会在特定目录环境变量PATH路径查找符合条件的文件  
  locate:locate命令用于查找符合条件的文档,他会去保存文档和目录名称的数据库内,查找合乎范本样式条件的文档或目录,locate与find 不同: find 是去硬盘找,locate 只在资料库中找。locate的速度比find快,它并不是真的查找,而是查数据库
  
  \# 用户管理命令  
  useradd:建立用户帐号。  
  usermod:修改系统已经存在的用户属性。  
  userdel:userdel命令用于删除用户帐号  
  groupadd:用于创建一个新的用户工作组。  
  passwd:更改使用者的密码。  
  chage:修改帐号和密码的有效期限。  
  id:显示用户以及所属群组的实际与有效ID。  
  su:变更为其他使用者的身份,除 root 外,需要输入该使用者的密码。  
  visudo:visudo编辑/etc/sudoers文件的专属命令  
  sudo:可以把某些超级用户权限分类有针对性授权给指定的普通用户,并且普通用户不需要知道root密码就可以使用得到的授权
  
  \# 基础网络操作命令  
  telnet:监测端口是否连通  
  ssh:使用SSH加密协议远程登录。  
  scp:用于不同主机之间复制文件。  
  wget:用来从指定的URL下载文件。  
  ping:测试主机之间网络的连通性。  
  route:显示和设置linux系统的路由表。  
  ifconfig:通常需要以root身份登录或使用sudo以便在Linux机器上使用ifconfig工具  
  ifup:启动网卡。  
  ifdown:关闭网卡。  
  netstat:显示网络状态。  
  ss:显示和netstat类似的内容
  
  \# 深入网络操作命令  
  nmap:Linux下的网络扫描和嗅探工具包  
  lsof:列出当前系统打开文件的工具  
  mail:电子邮件发送和接收工具。  
  mutt:邮件管理命令。  
  nslookup:交互式查询互联网DNS服务器的命令。  
  dig:用来测试域名系统工作是否正常。  
  host:用来测试域名系统工作是否正常。  
  traceroute:显示数据包到主机间的路径  
  tcpdump:免费的网络分析工具
  
  \# 有关磁盘与文件系统的命令  
  mount:用于挂载Linux系统外的文件。  
  umount:用于卸除文件系统。  
  fsck:用来检查和维护不一致的文件系统  
  parted:磁盘分区命令,没有磁盘大小限制。针对大于2TB的硬盘,需要采用GPT分区,使用parted命令进行操作 。  
  mkfs:格式化创建Linux文件系统。常见的文件系统有ext2,ext3, ext4 , vfat等。  
  partprobe:从kernel重新读取分区信息。  
  e2fsck:检查ext2/ext3/ext4类型文件系统。  
  mkswap:用于设置交换区(swap area)。mkswap可将磁盘分区或文件设为Linux的交换区。  
  swapon:启用交换分区。  
  swapoff:关闭交换分区。  
  sync:在 linux/unix 系统中,在文件或数据处理过程中一般先放到内存缓冲区中,等到适当的时候再写入磁盘,以提高系统的运行效率  
  resize2fs:调整ext2/ext3/ext4文件系统大小
  
  \# 系统权限及用户授权相关命令  
  chmod:控制文件如何被他人所调用  
  chown:指定文件的拥有者改为指定的用户或组   
  chgrp:变更文件或目录的所属群组。  
  umask:显示或设置权限掩码
  
  \# 查看系统用户登陆信息的命令  
  whoami:显示当前有效的用户名称。  
  who:显示目前登录系统的用户信息。  
  lastlog:显示系统中所有用户最近一次登录信息。  
  users:显示当前登录系统的所有用户的用户列表。  
  finger:显示本地主机现在所有的用户的登陆信息。
  
  \# 内置命令及其它  
  echo:打印变量,或直接输出指定的字符串。  
  printf:将结果格式化输出到标准输出。  
  rpm:管理rpm包的命令。  
  yum:提供了查找、安装、删除某一个、一组甚至全部软件包的命令。  
  watch:周期性的执行给定的命令,并将命令的输出以全屏方式显示。  
  alias:用于设置指令的别名  
  unalias:用于删除别名  
  date:用来显示或设定系统的日期与时间,在显示方面,使用者可以设定欲显示的格式。  
  clear:清除屏幕。  
  history:显示历史记录和执行过的指令命令。  
  eject:弹出光驱。  
  time:用于测量一个命令的运行时间。  
  nc:探测端口,作为客户端连接服务  
  xargs:给命令传递参数的一个过滤器,也是组合多个命令的一个工具。  
  exec:用于调用并执行指令的命令  
  export:设置或者显示环境变量。  
  unset:删除变量或函数。  
  type:用来显示指定命令的类型,判断给出的指令是内部指令还是外部指令。  
  bc:任意精度计算器语言
  
  \# 系统管理与性能监视命令  
  chkconfig:用于检查,设置系统的各种服务  
  vmstat显示Linux系统虚拟内存状态,也可以报告关于进程、内存、I/O等系统整体运行状态  
  mpstat:实时系统监控工具  
  iostat:用于输出CPU和磁盘I/O相关的统计信息。  
  sar:系统性能分析工具之一,可以从多方面对系统的活动进行报告。  
  ipcs:报告linux中进程间通信设施的状态,显示的信息包括消息列表、共享内存和信号量的信息。  
  ipcrm:删除一个或更多的消息队列、信号量集或者共享内存标识。  
  strace:用于诊断、调试Linux用户空间跟踪器  
  ltrace:用来跟踪进程调用库函数的情况
  
  \# 关机/重启/注销和查看系统信息的命令  
  shutdown:用来进行关机程序  
  halt:用来关闭正在运行的Linux操作系统。halt命令会先检测系统runlevel,若runlevel为0或6,则关闭系统,否则即调用shutdown来关闭系统。  
  poweroff:用来关闭计算机操作系统并且切断系统电源  
  logout:退出当前登录的Shell。  
  exit:退出当前登录的Shell。  

  
  \# 进程管理相关命令  
  bg:将一个在后台暂停的命令,变成继续执行。  
  fg:将后台中的命令调至前台继续运行。  
  jobs:查看当前有多少在后台运行的命令。  
  kill:用于删除执行中的程序或工作。  
  killall:用于终止某个指定名称的服务所对应的全部进程。  
  pkill:通过进程名终止进程。  
  crontab:用来定期执行程序的命令。  
  ps:列出系统中当前运行的那些进程  
  pstree:将所有行程以树状图显示  
  nice/renice:为未运行命令指定运行时调度优先级的,如果是已运行的命令则需要renice命令。  
  nohup:让后台工作在离开操作终端时,也能够正确地在后台执行。  
  pgrep:用来判断程序是否正在运行。  
  runlevel:查看系统当前运行级别。  
  init:用于切换到指定的运行级别。  
  service:可以启动、停止、重新启动和关闭系统服务

cpu size

 cat /proc/cpuinfo |grep "model name"  && cat /proc/cpuinfo |grep "physical id"

Under Linux, you can see the detailed information of each CPU in /proc/cpuinfo. But for dual-core CPUs, you will see two CPUs in cpuinfo. People often mistake them for two single-core CPUs. In fact, single-core and dual-core should be distinguished by Physical Processor ID. The Physical Processor ID can be found from cpuinfo or dmesg. Flags If there is ht, it indicates that hyper-threading technology is supported. To determine the number of physical CPUs, you can check the physical id value. If it is the same, it means single core.

memory size

cat /proc/meminfo |grep MemTotal

Hard disk size

\[root@k8s-master-node1 ~\]\# fdisk -l |grep Disk  
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors  
Disk label type: dos  
Disk identifier: 0x000a5b7e  
Disk /dev/sdb: 536.9 GB, 536870912000 bytes, 1048576000 sectors  
Disk label type: dos  
Disk identifier: 0x9987fe16  
\[root@k8s-master-node1 ~\]#

Linux system information command to view kernel/operating system/CPU information

\[root@k8s-master-node1 ~\]\# uname -a  
Linux k8s-master-node1 3.10.0-1160.90.1.el7.x86\_64 #1 SMP Thu May 4 15:21:22 UTC 2023 x86\_64 x86\_64 x86\_64 GNU/Linux  
\[root@k8s-master-node1 ~\]#

View operating system hostname

\[root@k8s-master-node1 ~\]\# hostname  
k8s-master-node1  
\[root@k8s-master-node1 ~\]#

list all pci devices

\[root@k8s-master-node1 ~\]\# lspci -tv

List loaded kernel modules

\[root@k8s-master-node1 ~\]\# lsmod

View environment variables

\# env

View memory usage and swap area usage

\[root@k8s-master-node1 ~\]\# free -h  
              total        used        free      shared  buff/cache   available  
Mem:            94G         22G         66G        718M        5.4G         70G  
Swap:            0B          0B          0B  
\[root@k8s-master-node1 ~\]#

Check the usage of each partition

\[root@k8s-master-node1 ~\]\# df -hT  
Filesystem     Type      Size  Used Avail Use% Mounted on  
devtmpfs       devtmpfs   48G     0   48G   0% /dev  
tmpfs          tmpfs      48G     0   48G   0% /dev/shm  
tmpfs          tmpfs      48G  719M   47G   2% /run  
tmpfs          tmpfs      48G     0   48G   0% /sys/fs/cgroup  
/dev/sda1      ext4       48G   28G   18G  62% /  
/dev/sdb1      ext4      493G  377G   91G  81% /data

Check the size of the specified directory

\[root@k8s-master-node1 ~\]\# du -lsh ./\*  
4.0K./1.sh  
4.0K./2.sh  
4.0K./anaconda-ks.cfg  
4.0K./application.yaml  
2.2M./core.14557  
2.6M./gmsm4encriptor\_linux  
2.4M./gmsm4encriptor\_mac  
19G./ivc-full-v2.9.0.tar.gz  
13M./mysql-1.0-SNAPSHOT.jar  
2.1G./mysql\_backup\_20230619  
227M./mysql\_backup\_20230619.tar.gz  
100K./nohup.out  
176K./out.txt  
4.0K./Sm4Util.java  
4.0K./sql.sh  
8.3M./test  
8.0K./tmp.json  
\[root@k8s-master-node1 ~\]#

View total memory

\[root@k8s-master-node1 ~\]\# grep MemTotal /proc/meminfo  
MemTotal:       98817580 kB  
\[root@k8s-master-node1 ~\]#

Check the remaining memory

\[root@k8s-master-node1 ~\]\# grep MemFree /proc/meminfo  
MemFree:        69755204 kB  
\[root@k8s-master-node1 ~\]#  

View system running time, number of users, and load

\[root@k8s-master-node1 ~\]\# uptime  
 10:16:33 up 54 days, 16:49,  1 user,  load average: 0.56, 0.75, 1.22  
\[root@k8s-master-node1 ~\]#

View system load disks and partitions

\[root@k8s-master-node1 ~\]\# cat /proc/loadavg  
0.55 0.74 1.20 12/3934 55075  
\[root@k8s-master-node1 ~\]#

Check the attached partition status

\[root@k8s-master-node1 ~\]\# mount | column -t

View all partitions

\[root@k8s-master-node1 ~\]\# fdisk -l  
  
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors  
...  
Disk identifier: 0x000a5b7e  
  
   Device Boot      Start         End      Blocks   Id  System  
/dev/sda1   \*        2048   100665343    50331648   83  Linux  
/dev/sda2       100665344   104857599     2096128   82  Linux swap / Solaris  
...  
  
   Device Boot      Start         End      Blocks   Id  System  
/dev/sdb1            2048  1048575999   524286976   83  Linux  
\[root@k8s-master-node1 ~\]#

View all swap partitions

\[root@k8s-master-node1 ~\]\# swapon -s

View disk parameters (only for IDE devices

\# hdparm -i /dev/hda

Check the IDE device detection status at startup

\[root@k8s-master-node1 ~\]\# dmesg |grep IDE  
\[    2.093243\] pci 0000:00:07.1: legacy IDE quirk: reg 0x10: \[io  0x01f0-0x01f7\]  
\[    2.093245\] pci 0000:00:07.1: legacy IDE quirk: reg 0x14: \[io  0x03f6\]  
\[    2.093246\] pci 0000:00:07.1: legacy IDE quirk: reg 0x18: \[io  0x0170-0x0177\]  
\[    2.093248\] pci 0000:00:07.1: legacy IDE quirk: reg 0x1c: \[io  0x0376\]  
\[root@k8s-master-node1 ~\]#

View all network interface properties

\# ifconfig

View the properties of all network interfaces

\# iptables -L

View routing table

\[root@k8s-master-node1 ~\]\# route -n  
Kernel IP routing table  
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface  
0.0.0.0         172.16.20.254   0.0.0.0         UG    100    0        0 eth0  
10.48.0.0       0.0.0.0         255.255.255.0   U     0      0        0 cni0  
10.48.1.0       10.48.1.0       255.255.255.0   UG    0      0        0 flannel.1  
10.48.2.0       10.48.2.0       255.255.255.0   UG    0      0        0 flannel.1  
10.126.1.0      0.0.0.0         255.255.255.0   U     0      0        0 docker0  
172.16.20.0     0.0.0.0         255.255.255.0   U     100    0        0 eth0  
172.18.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-abb9352b219e  
\[root@k8s-master-node1 ~\]#  

View all listening ports

\# netstat -tnlp

View all established connections

\# netstat -antp

View network statistics process

netstat \-s 

View all processes

\# ps -ef

Display process status in real time

\# top

View active users

\[root@k8s-master-node1 ~\]\# w  
 10:29:02 up 54 days, 17:01,  1 user,  load average: 0.83, 1.24, 1.24  
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT  
root     pts/0    192.168.128.73   10:03    6.00s  0.24s  0.14s \-bash  
\[root@k8s-master-node1 ~\]#

View specified user information

\[root@k8s-master-node1 ~\]\# id root  
uid\=0(root) gid\=0(root) groups\=0(root),1001(docker)  
\[root@k8s-master-node1 ~\]#

View user login log

\# last

View all users of the system

\[root@k8s-master-node1 ~\]\# cut -d: -f1 /etc/passwd  
root  
bin  
daemon  
adm  
lp  
sync  
shutdown  
halt  
mail  
operator  
games  
ftp  
nobody  
systemd-network  
dbus  
polkitd  
postfix  
sshd  
chrony  
yibot  
jenkins  
\[root@k8s-master-node1 ~\]#

View all groups in the system

\[root@k8s-master-node1 ~\]\# cut -d: -f1 /etc/group

View the current user’s scheduled tasks

\[root@k8s-master-node1 ~\]\# crontab -l  
\# Ntpdate clock synchronization  
\*/30 \* \* \* \* ((/usr/sbin/ntpdate \-u ntp.aliyun.com; hwclock \-w) 2\>&1 &> /dev/null)  
\* \* \* \* \* /usr/local/gse/agent/bin/gsectl watch  
\## ======== Extra monitoring data push to Open-Falcon ========  
\* \* \* \* \* /usr/local/open-falcon/extra\_mons/bin/main.sh >/dev/null 2\>&1  
37 15 \* \* \* sudo sync && sudo echo 3 > /proc/sys/vm/drop\_caches  
  
\[root@k8s-master-node1 ~\]#  

List all system services

\[root@k8s-master-node1 ~\]\# chkconfig  
  
Note: This output shows SysV services only and does not include native  
      systemd services. SysV configuration data might be overridden by native  
      systemd configuration.  
  
      If you want to list systemd services use 'systemctl list-unit-files'.  
      To see services enabled on particular target use  
      'systemctl list-dependencies \[target\]'.  
  
netconsole     0:off1:off2:off3:off4:off5:off6:off  
network        0:off1:off2:on3:on4:on5:on6:off  
\[root@k8s-master-node1 ~\]#

View all installed packages

\# rpm -qa

Sort by CPU utilization from largest to smallest

\# ps -e -o "%C : %p : %z : %a"|sort -nr

View the number of concurrent HTTP requests and its TCP connection status:

\[root@k8s-master-node1 ~\]\# netstat -n | awk '/^tcp/ {++S\[$NF\]} END {for(a in S) print a, S\[a\]}'  
CLOSE\_WAIT 1  
ESTABLISHED 290  
FIN\_WAIT2 1  
SYN\_SENT 2  
TIME\_WAIT 289  
\[root@k8s-master-node1 ~\]#

Allow root login

sed \-i '/Root/s/no/yes/' /etc/ssh/sshd\_config

Show services enabled at level 3

ls /etc/rc3.d/S\* |cut \-c 15\-

CPU load

\[root@k8s-master-node1 ~\]\# cat /proc/loadavg  
0.48 1.00 1.26 1/3934 118801  
\[root@k8s-master-node1 ~\]#  

CPU load

mpstat 1 1  
检查 %idle 是否过低(比如小于5%)。

swap monitoring

vmstat 1 5  
观察 si 和 so 值是否较大

Disk I/O load

iostat \-x 1 2  
检查I/O使用率(%util)是否超过 100%

network load

sar \-n DEV  
检查网络流量(rxbyt/s, txbyt/s)是否过高

Network status, check whether DNS, gateway, etc. can be connected normally

ping traceroute nslookup dig

system time

\# date

Number of open files

lsof | wc \-l 

Clear zombie processes

ps \-eal | awk '{ if ($2 == "Z") {print $4}}' | kill \-9

tcpdump packet capture

tcpdump \-c 10000 \-i eth0 \-n dst port 80 > /root/pkts

`How to learn hacking & network security

As long as you like my article today, my private network security learning materials will be shared with you for free. Come and see what is available.

1. Learning roadmap

There are a lot of things to learn about attack and defense. I have written down the specific things you need to learn in the road map above. If you can complete them, you will have no problem getting a job or taking on a private job.

2. Video tutorial

Although there are many learning resources on the Internet, they are basically incomplete. This is an Internet security video tutorial I recorded myself. I have accompanying video explanations for every knowledge point in the roadmap above.

The content covers the study of network security laws, network security operations and other security assessments, penetration testing basics, detailed explanations of vulnerabilities, basic computer knowledge, etc. They are all must-know learning contents for getting started with network security.

(They are all packaged into one piece and cannot be expanded one by one. There are more than 300 episodes in total)

Due to limited space, only part of the information is displayed. You need to click on the link below to obtain it.

CSDN gift package: "Hacker & Network Security Introduction & Advanced Learning Resource Package" free sharing

3. Technical documents and e-books

I also compiled the technical documents myself, including my experience and technical points in participating in large-scale network security operations, CTF, and digging SRC vulnerabilities. There are more than 200 e-books. Due to the sensitivity of the content, I will not display them one by one.

Due to limited space, only part of the information is displayed. You need to click on the link below to obtain it.

CSDN gift package: "Hacker & Network Security Introduction & Advanced Learning Resource Package" free sharing

4. Toolkit, interview questions and source code

"If you want to do your job well, you must first sharpen your tools." I have summarized dozens of the most popular hacking tools for everyone. The scope of coverage mainly focuses on information collection, Android hacking tools, automation tools, phishing, etc. Interested students should not miss it.

There is also the case source code and corresponding toolkit mentioned in my video, which you can take away if needed.

Due to limited space, only part of the information is displayed. You need to click on the link below to obtain it.

CSDN gift package: "Hacker & Network Security Introduction & Advanced Learning Resource Package" free sharing

Finally, here are the interview questions about network security that I have compiled over the past few years. If you are looking for a job in network security, they will definitely help you a lot.

These questions are often encountered when interviewing Sangfor, Qi Anxin, Tencent or other major companies. If you have good questions or good insights, please share them.

Reference analysis: Sangfor official website, Qi’anxin official website, Freebuf, csdn, etc.

Content features: Clear organization and graphical representation to make it easier to understand.

Summary of content: Including intranet, operating system, protocol, penetration testing, security service, vulnerability, injection, XSS, CSRF, SSRF, file upload, file download, file inclusion, XXE, logical vulnerability, tools, SQLmap, NMAP, BP, MSF…

Due to limited space, only part of the information is displayed. You need to click on the link below to obtain it.

CSDN gift package: "Hacker & Network Security Introduction & Advanced Learning Resource Package" free sharing

Guess you like

Origin blog.csdn.net/Javachichi/article/details/135008212