Linux常用操作

查看系统开机耗时

systemd-analyze,例如:

root@jaron:/home/jaron# systemd-analyze
Startup finished in 3.603s (firmware) + 17.617s (loader) + 5.837s (kernel) + 8.428s (userspace) = 35.487s

修改硬件(BIOS)时间

hwclock,例如:

  • hwclock --systohc:将系统时间写入BIOS。
  • hwclock --hctosys:将BIOS时间写入系统。

查看系统启动时间

可以使用当前时间减去启动已运行的时间,如:
date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"%Y-%m-%d %H:%M:%S"

查看当前桌面会话

echo $DESKTOP_SESSION,例如:

root@jaron-VirtualBox:/mnt/D_DRIVE/workspace# echo $DESKTOP_SESSION
ubuntu
root@jaron-VirtualBox:/mnt/D_DRIVE/workspace# echo $DESKTOP_SESSION
Lubuntu

查看当前桌面环境

echo $XDG_CURRENT_DESKTOP,例如:

root@jaron-VirtualBox:/mnt/D_DRIVE/workspace# echo $XDG_CURRENT_DESKTOP
Unity
root@jaron-VirtualBox:/mnt/D_DRIVE/workspace# echo $XDG_CURRENT_DESKTOP
LXDE

查看文件系统磁盘使用情况(df)

df,例如:

root@jaron# df -h
文件系统        容量  已用  可用 已用% 挂载点
udev            1.9G     0  1.9G    0% /dev
tmpfs           395M   16M  379M    5% /run
/dev/sda1        26G  9.6G   15G   40% /
tmpfs           2.0G  6.9M  2.0G    1% /dev/shm
tmpfs           5.0M  4.0K  5.0M    1% /run/lock
tmpfs           2.0G     0  2.0G    0% /sys/fs/cgroup
D_DRIVE         277G  168G  109G   61% /media/sf_D_DRIVE
tmpfs           395M     0  395M    0% /run/user/0
D_DRIVE         277G  168G  109G   61% /mnt/D_DRIVE
root@jaron# 

查看指定目录所在磁盘空间(du)

du -hs 目录,例如:

root@jaron:~# du -hs /data
2.0G    /data

du -s --block-size=1 目录,指定字节单位,例如:

root@jaron:~# du -s --block-size=1 /data
10367533056     /data

修改磁盘自动挂载路径

vi /etc/fstab,例如:
修改UUID04963a1b-2cf0-4a4a-90c7-28c0ccdb6452的数据盘挂载到指定目录/media/jaron/,并赋予其可执行权限exec

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/nvme0n1p2 during installation
UUID=02755bc8-c00f-4271-bd8e-65de5cd64222 /               ext4    errors=remount-ro 0       1
# /backup was on /dev/nvme0n1p3 during installation
UUID=0c1f442d-f74e-4fa2-9500-ecb99d5f2731 /backup         ext4    noauto          0       0
# /boot was on /dev/nvme0n1p1 during installation
UUID=03d4969d-7d15-4c31-992a-2d639a01c21d /boot           ext4    defaults        0       2
# /boot/efi was on /dev/nvme0n1p6 during installation
UUID=8575-AF55  /boot/efi       vfat    umask=0077      0       1
# /data was on /dev/nvme0n1p4 during installation
UUID=e83986ed-bbdc-4aa2-bb76-445730098a97 /data           ext4    rw,user,x-gvfs-show,nosuid,nofail 0       2
# swap was on /dev/nvme0n1p5 during installation
UUID=3d00e718-752a-41d3-9f06-c91c65008f32 none            swap    sw              0       0
UUID=04963a1b-2cf0-4a4a-90c7-28c0ccdb6452  /media/jaron/           ext4    rw,user,x-gvfs-show,exec,nosuid,nofail 0       0

1、关闭移动设备自动挂载

(1)Ubuntu

  • 进入到目录/etc/udev/rules.d,创建文件10-udisk.rules,添加内容:
ACTION=="add|change", SUBSYSTEM=="block", ENV{UDISKS_IGNORE}="1"
  • 保存退出,重启系统

查看文件/套接字被打开情况(fuser)

fuser 文件/套接字,例如:

root@jaron:~# fuser /dev/ttyUSB5
/dev/ttyUSB5:         9367  # 表示/dev/ttyUSB5被进程9367所打开
root@jaron:~#

解锁用户

pam_tally2 --reset --user 需要解锁的账户名
pam_tally2是一个Linux系统下的PAM模块,用于记录用户登录失败的次数。当一个用户登录失败的次数超过了预设的阈值时,pam_tally2会锁定该用户的账户,防止攻击者使用暴力破解的方式破解密码。如果需要解锁用户账户,可以使用上面命令,这个命令会将指定用户的登录失败计数器重置为 0,从而解锁该用户账户。注意:需要以root用户身份运行此命令。

设置开机root用户免密登录

1、lightdm

修改/etc/lightdm/lightdm.conf,若没有该文件则创建,内容为:

[Seat:*]
greeter-session=none # 禁用lightdm-greeter-session(启动时不显示任何登录界面,系统将直接尝试自动登录到指定的用户会话)
autologin-guest=false
autologin-user=root
autologin-user-timeout=0

可能的问题点

  • Ubuntu16.04中使能root用户登录后,会弹出如下所示的对话框:
    在这里插入图片描述AllowGuest=false
    AutomaticLoginEnable=true
    AutomaticLogin=root
    解决方法为:编辑/root/.profile文件,将文件末尾一句mesg n || true更改为:tty -s && mesg n || true,保存退出,重新使用root登录。

2、gdm3

修改/etc/gdm3/custom.conf,若没有该文件则创建,内容为:

[daemon]
AutomaticLoginEnable=true
AutomaticLogin=root

允许被使用root身份进行ssh远程登录

  • 编辑/etc/ssh/sshd_config文件
  • 找到PermitRootLogin,注释掉这一行,添加PermitRootLogin yes,保存,退出
  • 执行:sudo service sshd restart

设置X Window选项

1、xserver

查看选项man xserverhttps://linux.die.net/man/1/xserver。常用选项如下:

  • -bs:disables backing store support on all screens
  • -c:关闭鼠标点击。
  • c:设置鼠标点击音量,值为[0, 100]。
  • -core:当发生致命错误时使服务器生成核心转储。
  • dpms:启动电源管理系统(会自动休眠)。
  • -dpms:关闭电源管理系统。
  • -nocursor:禁止显示鼠标。
  • -s:设置屏保超时时间(单位:分钟),设置为0表示不启动屏保。

配置选项:如果显示管理器使用的是LightDM,则一般要修改配置文件/usr/share/lightdm/lightdm.conf.d/50-xserver-command.conf(Ubuntu)或/etc/lightdm/lightdm.conf(银河麒麟),在其中加入以下配置:

[Seat:*]
xserver-command=X [选项 ...]

例如:设置不显示鼠标、关闭屏保、关闭电源管理系统。

[Seat:*]
xserver-command=X -bs -core -nocursor -s 0 -dpms

2、DISPLAY

在Linux/Unix类操作系统上,DISPLAY用来设置将图形显示到何处。

  • :0:0.0:通常是本地显示器(即当你坐在它前面时计算机的主显示器)。
  • :1:当您启用显示转发并登录到远程计算机时,通常由SSH等服务使用。
  • 其他,例如:localhost:10.0等。

3、xhost

是用来控制X server访问权限。
语法:xhost [ + | - ] [ Name ]
例如:要允许root用户访问您的X服务器,请使用以下命令:

xhost local:root

配置和设置输入设备

查看选项man xinput,常用选项如下:

  • --list:列出当前所有的输入设备。
  • --enable:启动输入设备。
  • --disable:禁用输入设备。

查看程序进程ID

pidof 进程名,例如:

root@jaron:~# pidof sshd
19898 19894 4018 4008 1105
root@jaron:

根据进程名杀死进程,如:kill -9 $(pidof sshd)

查看进程的线程信息

top -Hp pid,例如:

root@jaron:/home/jaron# top -Hp 12904
top - 12:30:17 up 1 day, 18:08,  3 users,  load average: 4.08, 3.85, 3.79
Threads:  15 total,   1 running,  14 sleeping,   0 stopped,   0 zombie
%Cpu(s): 58.6 us, 12.8 sy,  0.0 ni, 27.5 id,  0.0 wa,  0.0 hi,  1.2 si,  0.0 st
KiB Mem :  3928916 total,   379088 free,  1597936 used,  1951892 buff/cache
KiB Swap:   999420 total,   999420 free,        0 used.  1898568 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
12904 root      20   0 1417592 172192  56460 S 10.0  4.4   0:48.08 test_ui
12958 root      20   0 1417592 172192  56460 S  0.3  4.4   0:01.08 http-1
12959 root      20   0 1417592 172192  56460 S  0.3  4.4   0:01.12 http-2
12961 root      20   0 1417592 172192  56460 S  0.3  4.4   0:01.13 http-4
12911 root      20   0 1417592 172192  56460 R  0.0  4.4   0:01.18 QXcbEventQueue
12951 root      20   0 1417592 172192  56460 S  0.0  4.4   0:00.32 worker-1
12952 root      20   0 1417592 172192  56460 S  0.0  4.4   0:00.00 worker-4
12953 root      20   0 1417592 172192  56460 S  0.0  4.4   0:00.00 worker-2
12954 root      20   0 1417592 172192  56460 S  0.0  4.4   0:00.00 worker-3
12955 root      20   0 1417592 172192  56460 S  0.0  4.4   0:00.00 ZMQbg/Reaper
12956 root      20   0 1417592 172192  56460 S  0.0  4.4   0:00.15 ZMQbg/IO/0
12957 root      20   0 1417592 172192  56460 S  0.0  4.4   0:00.06 msg_dispatcher
12960 root      20   0 1417592 172192  56460 S  0.0  4.4   0:01.10 http-3
13018 root      20   0 1417592 172192  56460 S  0.0  4.4   0:00.11 QQmlThread
17787 root      20   0 1417592 172192  56460 S  0.0  4.4   0:00.00 FileInfoThread

查看进程文件路径

ls -l /proc/进程ID/exe | awk '{print $11}'

查看USB设备信息

  • 简要信息:lsusb
  • 详细信息:cat /sys/kernel/debug/usb/devices

查看蓝牙设备信息

bluetoothctl
例如:

  • bluetoothctl list:列出本地蓝牙适配器的信息
  • bluetoothctl show:显示蓝牙设备信息

查看视频设备信息

安装:apt install v4l-utils
查看:v4l2-ctl --list-device

root@kpc:~# v4l2-ctl --list-device
USB3. 0 capture: USB3. 0 captur (usb-0000:06:00.0-1.4.1):
        /dev/video0
        /dev/video1
        /dev/media0

USB3. 0 capture: USB3. 0 captur (usb-0000:06:00.0-1.4.4):
        /dev/video2
        /dev/video3
        /dev/media1

使用journalctl查看systemd日志

journalctl -u 服务名 > /root/服务名.txt

修复文件系统

fsck -a 设备名(例如:/dev/sdb1),用于检测和修复文件系统。

格式化文件系统

1、ext4

Linux系统下的文件系统,单个文件支持超过4GB。
mkfs.ext4 -F -L '标签' 设备节点。例如:mkfs.ext4 -F -L 'MyUdisk' /dev/sdb1

2、vfat

支持Linux、Windows系统,单个文件不超过4GB。
mkfs.vfat -n '标签' 设备节点,例如:mkfs.vfat -n 'MyUdisk' /dev/sdb1

3、exfat

fat32的扩展,支持部分Linux、支持Windows系统,单个文件支持超过4GB。
mkfs.exfat -n '标签' 设备节点,例如:mkfs.exfat -n 'MyUdisk' /dev/sdb1
说明: 由于该格式是Windows开发的文件系统,默认Linux不直接支持exfat,需要安装软件包。

  • 方法一:安装exfat-dkms建议
sudo add-apt-repository ppa:arter97/exfat-linux
sudo apt update
sudo apt upgrade
sudo apt install exfat-dkms
  • 方法二:安装exfat-fuse(不建议)
sudo apt install exfat-utils exfat-fuse

这里选择使用方法一,因为exfat-dkms的文件拷贝性能(速度提示很多)优于exfat-fuse
注意: 如果exfat文件系统的存储设备中含有只读属性文件,则文件无法删除,需要对其赋予写权限(chmod 777 文件名)然后同步下磁盘(sync)才可以。

擦除数据

1、shred

彻底删除文件/分区(填零)
shred -z 文件/分区,选项:

  • -f, --force 当文件不可写时修改权限为可写。
  • -n, --iterations=N 覆盖N次,默认为3次。
  • --random-source=FILE 从指定文件读取随机数据。
  • -s, --size=N 粉碎多大的内容(后缀可以使用K,M,G)。
  • -u, --remove 清空文件内容并且删除文件。
  • -v, --verbose 显示进度。
  • -z, --zero 用0覆盖数据。
  • -version 显示版本信息。

说明: 如果删除文件要加上-u--remove,默认情况下不会删除文件,因为一般情况下都是对一个分区执行操作,分区不应该被删除。当对一个普通文件执行操作时,大部分用户都会加上这个选项。
例如:
彻底清除/dev/sdc4分区(分区需要先取消挂载)的内容,注意: 此种方法很慢,受到分区空间大小的影响。

root@jaron-VirtualBox:~# shred -v -z /dev/sdc4
shred: /dev/sdc4: pass 1/4 (random)...
shred: /dev/sdc4: pass 1/4 (random)...55MiB/29GiB 0%
shred: /dev/sdc4: pass 1/4 (random)...335MiB/29GiB 1%
...
shred: /dev/sdc4: pass 1/4 (random)...9.0GiB/29GiB 31%
shred: /dev/sdc4: pass 1/4 (random)...9.1GiB/29GiB 31%
shred: /dev/sdc4: pass 1/4 (random)...9.2GiB/29GiB 31%
...
shred: /dev/sdc4: pass 2/4 (random)...11GiB/29GiB 38%
shred: /dev/sdc4: pass 2/4 (random)...12GiB/29GiB 41%
shred: /dev/sdc4: pass 2/4 (random)...13GiB/29GiB 45%

另一种方式为,先挂载分区/dev/sdc4到某个目录例如/media/disk1,然后删除目录中的所有文件,此方法速度比较快(推荐)。

root@jaron-VirtualBox:~# shred -zvu -n 3 /media/disk1/*
shred: /media/disk1/libsrtp-2-fit.tar.gz: pass 1/4 (random)...
shred: /media/disk1/libsrtp-2-fit.tar.gz: pass 2/4 (random)...
shred: /media/disk1/libsrtp-2-fit.tar.gz: pass 3/4 (random)...
shred: /media/disk1/libsrtp-2-fit.tar.gz: pass 4/4 (000000)...
shred: /media/disk1/libsrtp-2-fit.tar.gz: removing
shred: /media/disk1/libsrtp-2-fit.tar.gz: renamed to /media/disk1/00000000000000000000
shred: /media/disk1/00000000000000000000: renamed to /media/disk1/0000000000000000000
shred: /media/disk1/0000000000000000000: renamed to /media/disk1/000000000000000000
shred: /media/disk1/000000000000000000: renamed to /media/disk1/00000000000000000
shred: /media/disk1/00000000000000000: renamed to /media/disk1/0000000000000000
shred: /media/disk1/0000000000000000: renamed to /media/disk1/000000000000000
shred: /media/disk1/000000000000000: renamed to /media/disk1/00000000000000
shred: /media/disk1/00000000000000: renamed to /media/disk1/0000000000000
shred: /media/disk1/0000000000000: renamed to /media/disk1/000000000000
shred: /media/disk1/000000000000: renamed to /media/disk1/00000000000
shred: /media/disk1/00000000000: renamed to /media/disk1/0000000000
shred: /media/disk1/0000000000: renamed to /media/disk1/000000000
shred: /media/disk1/000000000: renamed to /media/disk1/00000000
shred: /media/disk1/00000000: renamed to /media/disk1/0000000
shred: /media/disk1/0000000: renamed to /media/disk1/000000
shred: /media/disk1/000000: renamed to /media/disk1/00000
shred: /media/disk1/00000: renamed to /media/disk1/0000
shred: /media/disk1/0000: renamed to /media/disk1/000
shred: /media/disk1/000: renamed to /media/disk1/00
shred: /media/disk1/00: renamed to /media/disk1/0
shred: /media/disk1/libsrtp-2-fit.tar.gz: removed
shred: /media/disk1/openssl-1.1-fit.tar.gz: pass 1/4 (random)...
shred: /media/disk1/openssl-1.1-fit.tar.gz: pass 2/4 (random)...
shred: /media/disk1/openssl-1.1-fit.tar.gz: pass 3/4 (random)...
shred: /media/disk1/openssl-1.1-fit.tar.gz: pass 4/4 (000000)...
shred: /media/disk1/openssl-1.1-fit.tar.gz: removing
shred: /media/disk1/openssl-1.1-fit.tar.gz: renamed to /media/disk1/0000000000000000000000
shred: /media/disk1/0000000000000000000000: renamed to /media/disk1/000000000000000000000
shred: /media/disk1/000000000000000000000: renamed to /media/disk1/00000000000000000000
shred: /media/disk1/00000000000000000000: renamed to /media/disk1/0000000000000000000
shred: /media/disk1/0000000000000000000: renamed to /media/disk1/000000000000000000
shred: /media/disk1/000000000000000000: renamed to /media/disk1/00000000000000000
shred: /media/disk1/00000000000000000: renamed to /media/disk1/0000000000000000
shred: /media/disk1/0000000000000000: renamed to /media/disk1/000000000000000
shred: /media/disk1/000000000000000: renamed to /media/disk1/00000000000000
shred: /media/disk1/00000000000000: renamed to /media/disk1/0000000000000
shred: /media/disk1/0000000000000: renamed to /media/disk1/000000000000
shred: /media/disk1/000000000000: renamed to /media/disk1/00000000000
shred: /media/disk1/00000000000: renamed to /media/disk1/0000000000
shred: /media/disk1/0000000000: renamed to /media/disk1/000000000
shred: /media/disk1/000000000: renamed to /media/disk1/00000000
shred: /media/disk1/00000000: renamed to /media/disk1/0000000
shred: /media/disk1/0000000: renamed to /media/disk1/000000
shred: /media/disk1/000000: renamed to /media/disk1/00000
shred: /media/disk1/00000: renamed to /media/disk1/0000
shred: /media/disk1/0000: renamed to /media/disk1/000
shred: /media/disk1/000: renamed to /media/disk1/00
shred: /media/disk1/00: renamed to /media/disk1/0
shred: /media/disk1/openssl-1.1-fit.tar.gz: removed
shred: /media/disk1/speexdsp-SpeexDSP-1.2.0.tar.gz: pass 1/4 (random)...
shred: /media/disk1/speexdsp-SpeexDSP-1.2.0.tar.gz: pass 2/4 (random)...
shred: /media/disk1/speexdsp-SpeexDSP-1.2.0.tar.gz: pass 3/4 (random)...
shred: /media/disk1/speexdsp-SpeexDSP-1.2.0.tar.gz: pass 4/4 (000000)...
shred: /media/disk1/speexdsp-SpeexDSP-1.2.0.tar.gz: removing
shred: /media/disk1/speexdsp-SpeexDSP-1.2.0.tar.gz: renamed to /media/disk1/000000000000000000000000000000
shred: /media/disk1/000000000000000000000000000000: renamed to /media/disk1/00000000000000000000000000000
shred: /media/disk1/00000000000000000000000000000: renamed to /media/disk1/0000000000000000000000000000
shred: /media/disk1/0000000000000000000000000000: renamed to /media/disk1/000000000000000000000000000
shred: /media/disk1/000000000000000000000000000: renamed to /media/disk1/00000000000000000000000000
shred: /media/disk1/00000000000000000000000000: renamed to /media/disk1/0000000000000000000000000
shred: /media/disk1/0000000000000000000000000: renamed to /media/disk1/000000000000000000000000
shred: /media/disk1/000000000000000000000000: renamed to /media/disk1/00000000000000000000000
shred: /media/disk1/00000000000000000000000: renamed to /media/disk1/0000000000000000000000
shred: /media/disk1/0000000000000000000000: renamed to /media/disk1/000000000000000000000
shred: /media/disk1/000000000000000000000: renamed to /media/disk1/00000000000000000000
shred: /media/disk1/00000000000000000000: renamed to /media/disk1/0000000000000000000
shred: /media/disk1/0000000000000000000: renamed to /media/disk1/000000000000000000
shred: /media/disk1/000000000000000000: renamed to /media/disk1/00000000000000000
shred: /media/disk1/00000000000000000: renamed to /media/disk1/0000000000000000
shred: /media/disk1/0000000000000000: renamed to /media/disk1/000000000000000
shred: /media/disk1/000000000000000: renamed to /media/disk1/00000000000000
shred: /media/disk1/00000000000000: renamed to /media/disk1/0000000000000
shred: /media/disk1/0000000000000: renamed to /media/disk1/000000000000
shred: /media/disk1/000000000000: renamed to /media/disk1/00000000000
shred: /media/disk1/00000000000: renamed to /media/disk1/0000000000
shred: /media/disk1/0000000000: renamed to /media/disk1/000000000
shred: /media/disk1/000000000: renamed to /media/disk1/00000000
shred: /media/disk1/00000000: renamed to /media/disk1/0000000
shred: /media/disk1/0000000: renamed to /media/disk1/000000
shred: /media/disk1/000000: renamed to /media/disk1/00000
shred: /media/disk1/00000: renamed to /media/disk1/0000
shred: /media/disk1/0000: renamed to /media/disk1/000
shred: /media/disk1/000: renamed to /media/disk1/00
shred: /media/disk1/00: renamed to /media/disk1/0
shred: /media/disk1/speexdsp-SpeexDSP-1.2.0.tar.gz: removed
shred: '/media/disk1/System Volume Information': failed to open for writing: Is a directory

2、dd

dd命令用法

3、badblocks

全屏截图

scrot [文件名],例如:

root@jaron-VirtualBox:~/workspace# scrot
root@jaron-VirtualBox:~/workspace# ls | grep png
2021-12-08-094309_1024x600_scrot.png
root@jaron-VirtualBox:~/workspace#
root@jaron-VirtualBox:~/workspace# scrot test.png
root@jaron-VirtualBox:~/workspace# ls | grep png
2021-12-08-094309_1024x600_scrot.png
test.png
root@jaron-VirtualBox:~/workspace#

NFS操作

1、搭建NFS服务器

  • 安装NFS服务:sudo apt-get install nfs-kernel-server
  • 配置共享文件夹:vi /etc/exports
    语法: 文件名 客户端IP(权限)
参数值说明
rwro该目录共享的权限是可读写还是只读,但最终能否读写,还是与文件系统的rwx有关
syncasyncsync代表数据会同步写入到内存与硬盘中,async则代表数据会先暂存于内存当中,而非直接写入硬盘
no_root_squashroot_squash若客户端在共享目录里创建的文件的所属者和所属组是 root 用户和 root 组,那么显示文件的属主和属组时有以下两种情况:no_root_squash表示,文件的所属者和所属组是 root 用户和 root 组;root_squash表示将 root 用户和组映射为匿名用户和组(默认设置)
all_squashno_all_squashall_squash:客户端所有用户创建文件时,客户端会将文件的用户和组映射为匿名用户和组;no_all_squash:客户端普通用户创建的文件的 UID 和 GID 是多少,服务端就显示为多少(默认设置)
anonuid=anongid=将文件的用户和组映射为指定的 UID 和 GID ,若不指定默认为 65534(nfsnobody)

例如:

/opt/test *(subtree_check,rw,no_root_squash,async)
  • 重启服务:systemctl restart nfs-server

2、查看NFS服务器挂载点

showmount -e 服务器地址,例如:

root@jaron:~# showmount -e 192.168.1.111
Export list for 192.168.1.111:
/nfs1   *
/nfs2   *
root@jaron:~#

3、挂载/卸载NFS服务器

mount -t nfs -o 选项 NFS服务器挂载点 本机挂载点,例如:

root@jaron:~# mount -t nfs -o nfsvers=2,tcp,nolock 192.168.3.111:/nfs1/ /root/workspace/nfs1/
root@jaron:~# umount /root/workspace/nfs1

把进程绑定到特定CPU核上运行

  • 查看当前CPU核数:cat /proc/cpuinfo | grep "processor" | wc -l。例如:表示当前4核。
root@jaron:~# cat /proc/cpuinfo | grep "processor" | wc -l
4
  • 绑定进程ID到CPU核:taskset -cp 核索引 进程ID。例如:当前4核,则核索引范围为[0, 3],把进程21654绑定到倒数第2个核。
root@jaron:~# taskset -cp 2 21654
pid 21654's current affinity list: 2
pid 21654's new affinity list: 2
  • 查看进程运行的核:taskset -p 进程ID
root@jaron:~# taskset -p 21654
pid 21654's current affinity mask: 4

4的二进制值为0100,则表示进程运行在倒数第2个核上。执行top命令可以看到倒数第2个核处于满负载状态
在这里插入图片描述

以编程方式断开和重新连接USB设备

cd到驱动目录:/sys/bus/usb/drivers/

  • cp210x串口设备在目录:/sys/bus/usb/drivers/cp210x/
root@jaron:~# cd /sys/bus/usb/drivers/cp210x/
root@jaron:/sys/bus/usb/drivers/cp210x# ls
1-1.2.6:1.0  1-1.2.6:1.1  1-1.2.6:1.2  1-1.2.6:1.3  1-1.2.7:1.0  bind  module  uevent  unbind

找到USB设备标识1-1.2.6:1.0进行断开和重新连接:
断开:echo -n "1-1.2.6:1.0" > /sys/bus/usb/drivers/cp210x/unbind
重连:echo -n "1-1.2.6:1.0" > /sys/bus/usb/drivers/cp210x/bind

  • USB存储设备目录:/sys/bus/usb/drivers/usb-storage/
root@jaron:/sys/bus/usb/drivers/cp210x# cd /sys/bus/usb/drivers/usb-storage/
root@jaron:/sys/bus/usb/drivers/usb-storage# ls
1-1.2.5:1.0  bind  module  new_id  remove_id  uevent  unbind

升级程序

1、Ubuntu

  • apt list --upgradable,列出可升级的程序包列表。
  • apt install --only-upgrade 程序包名

打开设置界面

1、Ubuntu

gnome-control-center

修改键盘和鼠标映射

可以利用xmodmap对按键和鼠标进行修改。

  • xmodmap -pke,查看当前映射,例如:
    在这里插入图片描述

  • xmodmap -e 表达式,修改映射,例如:xmodmap -e 'keycode 64 = '表示禁用左Alt键。或者加载整个文件,例如:xmodmap -e '/root/xmodmap_test.txt'

创建基于内存的临时目录

mount -t tmpfs tmpfs 挂载点 -o size=最大分配空间,如果不添加选项-o size=最大分配空间,则系统自动分配(一般是物理内存的一半)。
例如:
mount -t tmpfs tmpfs /root/temp1mount -t tmpfs tmpfs /root/temp2 -o size=128Mmount -t tmpfs tmpfs /root/temp3 -o size=2G

光驱/光盘相关操作

1、查看光驱功能

方法一
cat /proc/sys/dev/cdrom/info,如:

root@kylin:/# cat /proc/sys/dev/cdrom/info
CD-ROM information, Id: cdrom.c 3.20 2003/12/17

drive name:             sr0
drive speed:            24
drive # of slots:       1
Can close tray:         1
Can open tray:          1
Can lock tray:          1
Can change speed:       1
Can select disk:        0
Can read multisession:  1
Can read MCN:           1
Reports media changed:  1
Can play audio:         1
Can write CD-R:         1
Can write CD-RW:        1
Can read DVD:           1
Can write DVD-R:        1
Can write DVD-RAM:      1
Can read MRW:           1
Can write MRW:          1
Can write RAM:          1

方法二
wodim -prcap,如:

root@kylin:/# wodim -prcap
Device was not specified. Trying to find an appropriate drive...
Detected CD-R drive: /dev/cdrw
Using /dev/cdrom of unknown capabilities
Device type    : Removable CD-ROM
Version        : 0
Response Format: 2
Capabilities   :
Vendor_info    : 'Slimtype'
Identification : 'DVD A  DS-8A8SH '
Revision       : 'KPB1'
Device seems to be: Generic mmc2 DVD-R/DVD-RW.

Drive capabilities, per MMC-3 page 2A:

  Does read CD-R media
  Does write CD-R media
  Does read CD-RW media
  Does write CD-RW media
  Does read DVD-ROM media
  Does read DVD-R media
  Does write DVD-R media
  Does read DVD-RAM media
  Does write DVD-RAM media
  Does support test writing

  Does read Mode 2 Form 1 blocks
  Does read Mode 2 Form 2 blocks
  Does read digital audio blocks
  Does restart non-streamed digital audio reads accurately
  Does support Buffer-Underrun-Free recording
  Does read multi-session CDs
  Does read fixed-packet CD media using Method 2
  Does not read CD bar code
  Does read R-W subcode information
  Does not return R-W subcode de-interleaved and error-corrected
  Does read raw P-W subcode data from lead in
  Does return CD media catalog number
  Does return CD ISRC information
  Does support C2 error pointers
  Does not deliver composite A/V data

  Does play audio CDs
  Number of volume control levels: 256
  Does support individual volume control setting for each channel
  Does support independent mute setting for each channel
  Does not support digital output on port 1
  Does not support digital output on port 2

  Loading mechanism type: tray
  Does support ejection of CD via START/STOP command
  Does not lock media on power up via prevent jumper
  Does allow media to be locked in the drive via PREVENT/ALLOW command
  Is currently in a media-locked state
  Does not support changing side of disk
  Does not have load-empty-slot-in-changer feature
  Does not support Individual Disk Present feature

  Maximum read  speed: 11080 kB/s (CD  62x, DVD  8x)
  Current read  speed: 11080 kB/s (CD  62x, DVD  8x)
  Maximum write speed:  2770 kB/s (CD  15x, DVD  2x)
  Current write speed:  2770 kB/s (CD  15x, DVD  2x)
  Rotational control selected: CLV/PCAV
  Buffer size in KB: 1024
  Copy management revision supported: 1
  Number of supported write speeds: 1
  Write speed # 0:  2770 kB/s CLV/PCAV (CD  15x, DVD  2x)

Supported CD-RW media types according to MMC-4 feature 0x37:
  Does write multi speed       CD-RW media
  Does write high  speed       CD-RW media
  Does write ultra high speed  CD-RW media
  Does write ultra high speed+ CD-RW media

2、擦除光盘数据

wodim -v dev=光驱设备名 blank=fast,如:

root@kylin:/# wodim -v dev=/dev/sr0 blank=fast
TOC Type: 1 = CD-ROM
scsidev: '/dev/sr0'
devname: '/dev/sr0'
scsibus: -2 target: -2 lun: -2
Linux sg driver version: 3.5.27
Wodim version: 1.1.11
SCSI buffer size: 64512
Device type    : Removable CD-ROM
Version        : 0
Response Format: 2
Capabilities   :
Vendor_info    : 'Slimtype'
Identification : 'DVD A  DS-8A8SH '
Revision       : 'KPB1'
Device seems to be: Generic mmc2 DVD-R/DVD-RW.
Current: 0x0013 (DVD-RW restricted overwrite)
Profile: 0x002B (DVD+R/DL)
Profile: 0x001B (DVD+R)
Profile: 0x001A (DVD+RW)
Profile: 0x0016 (DVD-R/DL layer jump recording)
Profile: 0x0015 (DVD-R/DL sequential recording)
Profile: 0x0014 (DVD-RW sequential recording) (current)
Profile: 0x0013 (DVD-RW restricted overwrite) (current)
Profile: 0x0012 (DVD-RAM)
Profile: 0x0011 (DVD-R sequential recording)
Profile: 0x0010 (DVD-ROM)
Profile: 0x000A (CD-RW)
Profile: 0x0009 (CD-R)
Profile: 0x0008 (CD-ROM)
Profile: 0x0002 (Removable disk)
Using generic SCSI-3/mmc DVD-R(W) driver (mmc_mdvd).
Driver flags   : SWABAUDIO BURNFREE
Supported modes: PACKET SAO
Drive buf size : 686080 = 670 KB
Beginning DMA speed test. Set CDR_NODMATEST environment variable if device
communication breaks or freezes immediately after that.
Current Secsize: 2048
HINT: use dvd+rw-mediainfo from dvd+rw-tools for information extraction.
Speed set to 2770 KB/s
Starting to write CD/DVD at speed   2.0 in real BLANK mode for single session.
Last chance to quit, starting real write in    0 seconds. Operation starts.
Performing OPC...
Blanking PMA, TOC, pregap
Errno: 5 (Input/output error), blank unit scsi sendcmd: no error
CDB:  A1 01 00 00 00 00 00 00 00 00 00 00
status: 0x2 (CHECK CONDITION)
Sense Bytes: 71 00 03 00 00 00 00 0A 00 00 00 00 73 04 00 00
Sense Key: 0x3 Medium Error, deferred error, Segment 0
Sense Code: 0x73 Qual 0x04 (program memory area update failure) Fru 0x0
Sense flags: Blk 0 (not valid)
cmd finished after 23.347s timeout 9600s
wodim: Cannot blank disk, aborting.
wodim: Some drives do not support all blank types.
wodim: Try again with wodim blank=all.

3、制作ISO镜像文件

genisoimage -J -r -o 模板ISO镜像文件 源文件/目录1 源文件/目录2 ...,例如:

root@kylin:/# genisoimage -J -r -o /root/tmp.iso /tmp
I: -input-charset not specified, using utf-8 (detected in locale settings)
Using QTSIN000.;1 for  /qtsingleapp-ukuime-f360-0:0 (qtsingleapp-kylind-31a5-0)
Using QTSIN001.;1 for  /qtsingleapp-kylind-31a5-0 (qtsingleapp-kylind-31a5-0-lockfile)
Using QTSIN002.;1 for  /qtsingleapp-kylind-31a5-0-lockfile (qtsingleapp-ukuivo-eba6-0)
Using QTSIN003.;1 for  /qtsingleapp-ukuivo-eba6-0 (qtsingleapp-ukuivo-eba6-0-lockfile)
Using QTSIN004.;1 for  /qtsingleapp-ukuivo-eba6-0-lockfile (qtsingleapp-ukuime-f360-0:0-lockfile)
Using QTSIN005.;1 for  /qtsingleapp-ukuime-f360-0:0-lockfile (qtsingleapp-profil-1ed0-0)
Using QTSIN006.;1 for  /qtsingleapp-profil-1ed0-0 (qtsingleapp-profil-1ed0-0-lockfile)
Using QTSIN007.;1 for  /qtsingleapp-profil-1ed0-0-lockfile (qtsingleapp-blueto-252d-0)
Using QTSIN008.;1 for  /qtsingleapp-blueto-252d-0 (qtsingleapp-blueto-252d-0-lockfile)
Using QTSIN009.;1 for  /qtsingleapp-blueto-252d-0-lockfile (qtsingleapp-peonyq-9673-0)
Using QTSIN00A.;1 for  /qtsingleapp-peonyq-9673-0 (qtsingleapp-peonyq-9673-0-lockfile)
Using SYSTE000.SER for  /systemd-private-42b982775d054b9faa845784f8d63ea1-upower.service-RYLXng (systemd-private-42b982775d054b9faa845784f8d63ea1-systemd-logind.service-tLvMqi)
Using SYSTE001.SER for  /systemd-private-42b982775d054b9faa845784f8d63ea1-systemd-logind.service-tLvMqi (systemd-private-42b982775d054b9faa845784f8d63ea1-systemd-resolved.service-0HRO8f)
Total translation table size: 0
Total rockridge attributes bytes: 5255
Total directory bytes: 28672
Path table size(bytes): 236
Max brk space used 1b000
2336 extents written (4 MB)

4、刻录ISO镜像文件

wodim -v dev=光驱设备名 ISO镜像文件,如:

root@kylin:/# wodim -v dev=/dev/sr0 /home/bin.iso
wodim: No write mode specified.
wodim: Assuming -tao mode.
wodim: Future versions of wodim may have different drive dependent defaults.
TOC Type: 1 = CD-ROM
scsidev: '/dev/sr0'
devname: '/dev/sr0'
scsibus: -2 target: -2 lun: -2
Linux sg driver version: 3.5.27
Wodim version: 1.1.11
SCSI buffer size: 64512
Device type    : Removable CD-ROM
Version        : 0
Response Format: 2
Capabilities   :
Vendor_info    : 'Slimtype'
Identification : 'DVD A  DS-8A8SH '
Revision       : 'KPB1'
Device seems to be: Generic mmc2 DVD-R/DVD-RW.
Current: 0x0014 (DVD-RW sequential recording)
Profile: 0x002B (DVD+R/DL)
Profile: 0x001B (DVD+R)
Profile: 0x001A (DVD+RW)
Profile: 0x0016 (DVD-R/DL layer jump recording)
Profile: 0x0015 (DVD-R/DL sequential recording)
Profile: 0x0014 (DVD-RW sequential recording) (current)
Profile: 0x0013 (DVD-RW restricted overwrite) (current)
Profile: 0x0012 (DVD-RAM)
Profile: 0x0011 (DVD-R sequential recording)
Profile: 0x0010 (DVD-ROM)
Profile: 0x000A (CD-RW)
Profile: 0x0009 (CD-R)
Profile: 0x0008 (CD-ROM)
Profile: 0x0002 (Removable disk)
Using generic SCSI-3/mmc DVD-R(W) driver (mmc_mdvd).
Driver flags   : SWABAUDIO BURNFREE
Supported modes: PACKET SAO
Drive buf size : 686080 = 670 KB
Beginning DMA speed test. Set CDR_NODMATEST environment variable if device
communication breaks or freezes immediately after that.
FIFO size      : 12582912 = 12288 KB
Track 01: data   172 MB
Total size:      197 MB (19:36.73) = 88255 sectors
Lout start:      198 MB (19:38/55) = 88255 sectors
Current Secsize: 2048
HINT: use dvd+rw-mediainfo from dvd+rw-tools for information extraction.
Blocks total: 2298496 Blocks current: 2298496 Blocks remaining: 2210241
Speed set to 2770 KB/s
Starting to write CD/DVD at speed   2.0 in real unknown mode for single session.
Last chance to quit, starting real write in    0 seconds. Operation starts.
Waiting for reader process to fill input buffer ... input buffer ready.
Performing OPC...
Starting new track at sector: 0
Track 01:  172 of  172 MB written (fifo 100%) [buf  11%]   0.4x.
Track 01: Total bytes read/written: 180746240/180746240 (88255 sectors).
Writing  time:  302.463s
Average write speed   0.4x.
Min drive buffer fill was 9%
Fixating...
Errno: 5 (Input/output error), flush cache scsi sendcmd: cmd timeout after 120.842 (120) s
CDB:  35 00 00 00 00 00 00 00 00 00
cmd finished after 120.842s timeout 120s
Trouble flushing the cache
wodim: Cannot fixate disk.
Fixating time:  120.842s
Errno: 5 (Input/output error), prevent/allow medium removal scsi sendcmd: cmd timeout after 40.959 (40) s
CDB:  1E 00 00 00 00 00
cmd finished after 40.959s timeout 40s
wodim: fifo had 2847 puts and 2847 gets.
wodim: fifo was 0 times empty and 2655 times full, min fill was 99%.

屏幕亮屏/熄屏控制

亮屏:xset dpms force on
熄屏:xset dpms force off,它的作用是立即将显示器置于节能状态,也就是关闭显示器。执行该命令后,显示器将会立即关闭。要唤醒显示器,只需移动鼠标或按下键盘上的任意按键即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值