linux命令汇总,基于debian

文件/目录操纵

  1. ls //查看当前pwd下文件/目录
  2. ll //同ls -l
  3. pwd //显示当前所在目录
  4. grep //对输出流进行筛选
  5. curl {address} //返回response, html代码
  6. cat {file} //查看文本内容,输出在终端上
  7. less
  8. more
  9. mv {file1} {file2} //重命名/移动文件
  10. cp {file} {dest_file}
  11. watch -n 1 ps //watch命令每秒查询
  12. ln -s {源文件} {目标文件} //相当于windows快捷方式
  13. cut -d: -f1 /etc/passwd //以’:'字符分割,第一个

压缩包操作

  1. tail -n [file] //n为行数,
  2. tar
  3. gzip

系统信息查看

  1. top
  2. htop //可读性更好,需安装
  3. lsb_release -a
  4. ps //查看当前终端执行的进程,-ef查看所有的进程
  5. jobs //
  6. uname -a
Linux iZbp13wljqcqo06186qf2wZ 5.4.0-47-generic #51-Ubuntu SMP Fri Sep 4 19:50:52 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
  1. lscpu //查看cpu信息
  2. lsgpu
  3. lspci
#WSL
0b01:00:00.0 SCSI storage controller: Red Hat, Inc. Virtio filesystem (rev 01)
46ab:00:00.0 SCSI storage controller: Red Hat, Inc. Virtio filesystem (rev 01)
56aa:00:00.0 SCSI storage controller: Red Hat, Inc. Virtio filesystem (rev 01)
5fad:00:00.0 SCSI storage controller: Red Hat, Inc. Virtio filesystem (rev 01)
7fcd:00:00.0 SCSI storage controller: Red Hat, Inc. Virtio console (rev 01)
85b7:00:00.0 System peripheral: Red Hat, Inc. Virtio file system (rev 01)
9fda:00:00.0 SCSI storage controller: Red Hat, Inc. Virtio filesystem (rev 01)
aec1:00:00.0 3D controller: Microsoft Corporation Device 008e
bc9c:00:00.0 SCSI storage controller: Red Hat, Inc. Virtio filesystem (rev 01)
be77:00:00.0 SCSI storage controller: Red Hat, Inc. Virtio filesystem (rev 01)
e2ab:00:00.0 SCSI storage controller: Red Hat, Inc. Virtio filesystem (rev 01)
e6a8:00:00.0 SCSI storage controller: Red Hat, Inc. Virtio filesystem (rev 01)
f0e3:00:00.0 3D controller: Microsoft Corporation Device 008e
#云服务器
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:02.0 VGA compatible controller: Cirrus Logic GD 5446
00:03.0 Communication controller: Red Hat, Inc. Virtio console
00:04.0 SCSI storage controller: Red Hat, Inc. Virtio block device
00:05.0 Ethernet controller: Red Hat, Inc. Virtio network device
00:06.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon
  1. getconf LONG_BIT //
  2. hostname //服务器名称
  3. ifconfig //查看ip等网络信息
  4. ip add //查看ip等网络信息,全称,ip address
  5. lsblk //查看硬盘信息
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda    252:0    0  60G  0 disk 
└─vda1 252:1    0  60G  0 part /
  1. fdisk -l //观察硬盘实体使用情况,fdisk也可对硬盘分区
Disk /dev/vda: 60 GiB, 64424509440 bytes, 125829120 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xecf55593

Device     Boot Start       End   Sectors Size Id Type
/dev/vda1  *     2048 125829086 125827039  60G 83 Linux
  1. df -k //用于显示磁盘分区上的可使用的磁盘空间
Filesystem     1K-blocks     Used Available Use% Mounted on
udev             1891232        0   1891232   0% /dev
tmpfs             383892     1872    382020   1% /run
/dev/vda1       61795304 12005284  47047524  21% /
tmpfs            1919456        0   1919456   0% /dev/shm
tmpfs               5120        0      5120   0% /run/lock
tmpfs            1919456        0   1919456   0% /sys/fs/cgroup
overlay         61795304 12005284  47047524  21% /var/lib/docker/overlay2/434f9e483d1ad260541e52951cc951468e1f5d76fef9795e9d97779e6eb83ba1/merged
overlay         61795304 12005284  47047524  21% /var/lib/docker/overlay2/c19c2daafcbd115885a11703bb8824d9e591fff6e61ae957a7c20b8d386f3a1d/merged
overlay         61795304 12005284  47047524  21% /var/lib/docker/overlay2/97912319a9768ae77605bccbd2f2f4d02cf38ac149f12a26272739f37dea4aa9/merged
overlay         61795304 12005284  47047524  21% /var/lib/docker/overlay2/733c5b8d55b43781795dab82e2e6f55e68720a1f82b4b78c1f58d78547ab10a0/merged
overlay         61795304 12005284  47047524  21% /var/lib/docker/overlay2/45d4227904db50e2f6813cd6ff53c03d2b96673fc7ea15a82de69cde33921e30/merged
overlay         61795304 12005284  47047524  21% /var/lib/docker/overlay2/1bf9a94a249c9e780cde02bae8eefc2178586fb4033115e2e1bc9c22f56e9c6d/merged
overlay         61795304 12005284  47047524  21% /var/lib/docker/overlay2/3f90ed3d8e204d1c82a110e2134d471998c23c2dee318eec64fb63ef23fd556b/merged
overlay         61795304 12005284  47047524  21% /var/lib/docker/overlay2/6539ebd24c7cddb3b7d6e9e099732f0d0593480dee41b6dacc042289f7eb874d/merged
overlay         61795304 12005284  47047524  21% /var/lib/docker/overlay2/70909b79a7dc2e7d492302886525194685e4af128c7d3b3c234c624e66b52043/merged
overlay         61795304 12005284  47047524  21% /var/lib/docker/overlay2/2eaeee319ae30b9a4d0dc631c1ab4632475d298969b8ebf9ac7b964818fb0ba2/merged
overlay         61795304 12005284  47047524  21% /var/lib/docker/overlay2/822ac236fb2a79188807f5f6f008f5ec3383603032540f27c5bae1c59ae87a2a/merged
overlay         61795304 12005284  47047524  21% /var/lib/docker/overlay2/a17fc322441fd1e8089dd62e7617e73949913c189b4bd98dfbc457cd085b30e6/merged
overlay         61795304 12005284  47047524  21% /var/lib/docker/overlay2/456bf4c900748da69f4724d9baf7a3f8c3d3d1d01189ced0ae675b472c53d5c6/merged
overlay         61795304 12005284  47047524  21% /var/lib/docker/overlay2/f29bb0c96ffa19a19b0a97f6ab5fe71e8f395a8eea928c6a14edbfddddcdcf0d/merged
overlay         61795304 12005284  47047524  21% /var/lib/docker/overlay2/d98233283c106b28629f3e642dc82422b01e1851484606f024511d4628286675/merged
overlay         61795304 12005284  47047524  21% /var/lib/docker/overlay2/992ae29786c9ee861ffcc865cdb350a99981bbc68fbcd55a7ffd629ec4b89b86/merged
tmpfs             383888        0    383888   0% /run/user/0
  1. dmesg //
  2. env

服务

  1. crontab //定时任务
#编辑当前用户任务
crontab -e
#查看当前用户创建任务列表
crontab -l
#crontab指定用户创建定时任务
sudo crontab -u root -e
#以其他用户执行脚本
su otheruser -s script.sh
  1. nohup //将脚本置于后台执行
#将xx.sh脚本置于后台执行,关闭终端仍然生效
nohup {/path/{xx.sh}} &
  1. mailutils //发送邮件,不用使用自己的邮箱发送,但是发送的邮件会在垃圾箱里
  2. service //服务控制
// Tip:systemctl是Linux下的服务管理软件,他与 service命令的语法也稍许不同。
#显示linux所有服务
service --status-all 
#重启服务
service {serviceName} restart
#开启服务
service {serviceName} start
#关闭
service {serviceName} stop
  1. systemctl //服务管理
  2. vsftpd //FTP服务器

关键命令

  • 权限不够命令前加 sudo
  1. apt-get update
  2. apt upgrade
  3. sudo apt-get install {package_name}
  4. sudo apt-get install -f //解决:安装时出现依赖问题未能成功安装
  5. sudo add-apt-repository {xxx} //
  6. watch -n 2 sensors //查看cpu温度
  7. shutdown -r now //立即重新启动
  8. source {file} //使修改后的文件生效,没有用就重启
//watch命令配合sensors,每隔2s查看cpu温度
sudo apt install lm-sensors
  1. export PATH=/{DIC}/{xxx}:$PATH //添加脚本文件到PATH,优点:无需./可执行

网络

  1. netstat
  2. iptables

软件的安装

  1. .bundle文件
 sudo chmod +x {.bundle文件}
  1. dpkg(debian ubuntu)

dpkg安装不提供依赖检测,使用以下的命令兼容安装,sudo apt-get install -f

  1. .appimage文件

软件的卸载

  1. List item

常见目录

  1. ubuntu版本
/etc/issue
/profile/version
  1. 开机自启
/etc/rc.local
  1. crontab
#日志文件crontab(需要手动开启)
/var/log/cron.log

#开启日志
sudo vim /etc/rsyslog.d/50-default.conf
#重启系统日志
sudo service rsyslog restart
...
  1. cat /proc/version
Linux version 5.4.0-47-generic (buildd@lcy01-amd64-014) (gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)) #51-Ubuntu SMP Fri Sep 4 19:50:52 UTC 2020
  1. 当前操作系统发行版信息
#仅显示系统版本
cat /etc/issue 

cat /etc/lsb-release
cat /etc/os-release
  1. cpu信息
 cat /proc/cpuinfo
  1. 网卡信息
在这里插入代码片
  1. 系统运行时间

#376926.04为系统开启的时间,后面的应该是现在的时间(未验证)
cat /proc/uptime

376926.04 734590.12

#服务器启动的时间
date -d “$(awk -F. ‘{print $1}’ /proc/uptime) second ago” +“%Y-%m-%d %H:%M:%S”

2022-11-22 13:20:44
  1. 用户,用户组
#用户
/etc/passwd
#用户组
/etc/group
#

用户操作

  1. id {用户}
    id root
uid=0(root) gid=0(root) groups=0(root)
  1. w //查看活动用户

WSL没有输出,云服务器有输出,比较有意思,这个问题先放着。。

#云服务器
 22:23:26 up 4 days,  9:02,  1 user,  load average: 0.01, 0.08, 0.08
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    211.138.116.17   21:35    1.00s  0.10s  0.00s w
#WSL
 22:23:49 up 3 min,  0 users,  load average: 0.01, 0.02, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT

硬盘管理

  1. mount
  2. fdisk
  3. swapon //交换分区信息

额,云服务器貌似没有交换分区,是没有输出的,我用WSL(ubuntu22.04lts)进行实验

swapon

NAME     TYPE      SIZE USED PRIO
/dev/sdb partition   2G   0B   -2

swapon -s

Filename                                Type            Size            Used            Priority
/dev/sdb                                partition       2097152         0               -2
在这里插入代码片

Linux下的优质软件

  • 一些发行版自带的商店源下载会很慢,https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ubuntu-ports/,自行搜索关键字:{镜像商} {linux发行版}资源站,如基于ubuntu的开发的popos可以直接使用ubuntu商店的镜像源。
  1. drawio
  2. joplin
  3. multipass //ubuntu家的类docker的虚拟机貌似
  4. steam

引用:

https://blog.csdn.net/qq_31278903/article/details/83146031

你可能感兴趣的:(linux,运维,服务器)