Loading

linux命令快速入门

文件/文件夹

系统目录结构

重要系统目录

/etc: 上边也提到了,这个是系统中的配置文件,如果你更改了该目录下的某个文件可能会导致系统不能启动。
/bin, /sbin, /usr/bin, /usr/sbin: 这是系统预设的执行文件的放置目录,比如 ls 就是在 /bin/ls 目录下的。
值得提出的是,/bin, /usr/bin 是给系统用户使用的指令(除root外的通用户),而/sbin, /usr/sbin 则是给 root 使用的指令。
/var: 这是一个非常重要的目录,系统上跑了很多程序,那么每个程序都会有相应的日志产生,而这些日志就被记录到这个目录下,具体在 /var/log 目录下,另外 mail 的预设放置也是在这里。

ls 命令

ls 列出所有子目录和文件
ls -a 列出所有文件(包括隐藏文件)
ls -l 列出文件的详细信息(权限,所有者,文件大小(单位为B))

ll

列出所有文件的详细信息(权限,所有者,文件大小)

tar 命令

time tar -jcvf all1.tar.bz *.jpg # 压缩为tar.bz 格式
time tar -cvf all1.tar *.jpg # 压缩为tar格式
time tar -zcvf all1.tar.gz *.jpg # 压缩为tar.gz格式
tar -cvf tesr.tar test1.py test2.py # 压缩多个文件
time tar -jxvf all1.tar.bz # 解压tar.bz 格式文件
time tar -xvf all1.tar # 解压tar格式文件
time tar -zxvf all1.tar.gz # 解压tar.gz格式文件

cd

cd .. # 返回当前目录的上一层目录
cd 文件夹名称 # 进入当前目录的文件夹

文件内容查看

cat 从第一行开始显示文件内容
tac 从最后一行开始显示文件内容
nl 显示行号,空白行没有行号
head -n x 显示前面x行
tail -n x 显示后面x行

nl test.py | head -n 10 | tail -n 5 显示前面10行的最后5行,并显示行号

vi 编辑文档

esc 退出编辑模式
:wq 退出vi

系统信息

top 命令

top 显示进程信息
按1,
按b,
按c, 显示完整命令
按q , 退出

ifconfig # 查看当前服务器ip

df -h # 查看当前服务器硬盘空间

du -sh istest/ # 查看istest/所占的空间

下载安装

wget 命令

wget http://51.istester.com/isTester.png 下载文件
wget -o istest_name.png http://51.istester.com/isTester.png下载文件后重命名
wget -b http://51.istester.com/isTester.png后台下载

apt 命令

sudo apt install package
sudo apt list --installed
sudo apt autoremove
sudo apt remove package
sudo apt update # 查看可安装的包
sudo apt upgrade # 升级安装包

进程管理

systemd

linux 系统启动进程的工具

  1. 检查版本
    systemctl --version
  2. 设置开机启动服务
    sudo systemctl enable httpd
    注意,下次开机才会生效
  3. 启动服务
    sudo systemctl start httpd
  4. 查看启动状态
    sudo systemctl status httpd
  5. 停止服务
    sudo systemctl stop httpd.service
    停止无效,kill
    sudo systemctl kill httpd.service
  6. 重启
    sudo systemctl restart httpd.service
  7. 查看配置文件
    systemctl cat

其他

time 显示耗时

clear # 清空当前终端屏幕

用户权限

切换用户

su 切换到root
su admin 切换到admin用户

网络情况

端口

lsof -i:443
查看指定端口号是否开启,没有输出信息则代表没有开启
firewall-cmd --add-port=443/tcp --permanent
添加指定需要开放的端口
firewall-cmd --query-port=443/tcp
查看端口是否已开
firewall-cmd --reload
重新载入添加的端口

netstat

-r, --route              display routing table 路由信息
-I, --interfaces=<Iface> display interface table for <Iface>
-i, --interfaces         display interface table
-g, --groups             display multicast group memberships
-s, --statistics         display networking statistics (like SNMP)

-v, --verbose            be verbose
-n, --numeric            don't resolve names 不要显示别名
-e, --extend             display other/more information 显示扩展信息
-p, --programs           display PID/Program name for sockets 显示建立连接的程序名
-c, --continuous         continuous listing 每隔一个固定时间,执行该命令

-l, --listening          display listening server sockets 列出所有监听的服务状态
-a, --all                display all sockets (default: connected)

示例:netstat -ntlp
-t 列出tcp端口
-u 列出udp端口
列出所有在监听的tcp端口,并且不要显示别名,显示建立连接的程序名

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name     Timer
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      532/rpcbind          off (0.00/0/0)
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      907/nginx: master p  off (0.00/0/0)
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      967/sshd             off (0.00/0/0)
tcp6       0      0 :::443                  :::*                    LISTEN      2064/./brook_linux_  off (0.00/0/0)
tcp6       0      0 :::111                  :::*                    LISTEN      532/rpcbind          off (0.00/0/0)

防火墙

systemctl status firewalld 查看状态
systemctl start firewalld 打开防火墙
systemctl stop firewalld 关闭防火墙
如果开启失败
systemctl unmask firewalld.service
systemctl start firewalld.service

FQ工具

开启服务 nohup ./brook_linux_amd64 server -l :443 -p h3ll0 &
brook
教程

问题

  1. sudo apt autoremove报错
Use 'sudo apt autoremove' to remove them.
E: Could not read response to hello message from hook [ ! -f /usr/bin/snap ] || /usr/bin/snap advise-snap --from-apt 2>/dev/null || true: Success
E: Could not read response to hello message from hook [ ! -f /usr/bin/snap ] || /usr/bin/snap advise-snap --from-apt 2>/dev/null || true: Success

解决:
sudo rm -rf /etc/apt/apt.conf.d/20snapd.conf

上面的内容,主要还是一些知识点整理和个人的一些思考,权当参考,如有错误或者更好的建议,可以在评论区指正,不胜感激!

posted @ 2021-07-09 17:23  Tester-Dolores  阅读(138)  评论(0编辑  收藏  举报