一、实验目的
二、实验内容
1、系统信息类命令
l利用date命令显示系统当前时间,并修改系统的当前时间为2018年8月8日。
[root@centos7-linux ~]# date2021年 03月 26日 星期五 10:23:52 CST[root@centos7-linux ~]# date -d 08/08/20182018年 08月 08日 星期三 00:00:00 CST
l显示当前登录到系统的用户状态。
[root@centos-linux ~]# whoroot :0 2021-03-27 09:27 (:0)root pts/0 2021-03-27 09:28 (:0)root pts/1 2021-03-27 09:28 (192.168.20.1)[root@centos-linux ~]#
l利用free命令显示内存的使用情况。
[root@centos7-linux ~]# freetotal used free shared buff/cache availableMem: 2033552 621092 952048 10436 460412 1218104Swap: 0 0 0
l利用df命令显示系统的硬盘分区及使用状况。
[root@centos7-linux ~]# df文件系统 1K-块 已用 可用 已用% 挂载点/dev/sda2 10475520 71152 10404368 1% /devtmpfs 1002244 0 1002244 0% /devtmpfs 1016776 88 1016688 1% /dev/shmtmpfs 1016776 9184 1007592 1% /runtmpfs 1016776 0 1016776 0% /sys/fs/cgroup/dev/sda6 8378368 3918940 4459428 47% /usr/dev/sda5 8378368 141756 8236612 2% /var/dev/sda3 8378368 37072 8341296 1% /home/dev/sda1 303788 130904 172884 44% /boottmpfs 203356 4 203352 1% /run/user/42tmpfs 203356 16 203340 1% /run/user/0
l显示当前目录下的各级子目录的硬盘占用情况。
[root@centos-linux ~]# du -sh *4.0K 1.txt1.3M 2˳4.docx4.0K 2.txt4.0K 3.txt4.0K anaconda-ks.cfg5.0M core.37510 file1.txt0 user_file.txt0 公共0 模板0 视频0 图片0 文档0 下载0 音乐0 桌面
2、进程管理类命令
(1)使用ps命令查看和控制进程:
显示本用户的进程。
[root@centos7-linux ~]# ps -aPID TTY TIME CMD42501 pts/1 00:00:00 ps
显示所有用户的进程。
[root@centos-linux ~]# ps -e | morePID TTY TIME CMD1 ? 00:00:04 systemd2 ? 00:00:00 kthreadd3 ? 00:00:00 ksoftirqd/05 ? 00:00:00 kworker/0:0H6 ? 00:00:00 kworker/u256:07 ? 00:00:00 migration/08 ? 00:00:00 rcu_bh9 ? 00:00:00 rcuob/010 ? 00:00:00 rcuob/111 ? 00:00:00 rcuob/212 ? 00:00:00 rcuob/313 ? 00:00:00 rcuob/414 ? 00:00:00 rcuob/515 ? 00:00:00 rcuob/616 ? 00:00:00 rcuob/717 ? 00:00:00 rcuob/818 ? 00:00:00 rcuob/919 ? 00:00:00 rcuob/1020 ? 00:00:00 rcuob/1121 ? 00:00:00 rcuob/1222 ? 00:00:00 rcuob/13--More--
在后台运行cat命令。
[root@centos-linux ~]# cat /etc/profile | more&[1] 8289
查看进程cat。
[root@centos-linux ~]# ps -ef | grep catcyy 3985 3577 0 06:47 ? 00:00:00 /usr/bin/gnome-software --gapplication-serviceroot 6203 5675 0 06:56 ? 00:00:00 /usr/bin/gnome-software --gapplication-serviceroot 8288 8010 0 07:10 pts/4 00:00:00 cat /etc/profileroot 8387 8010 0 07:10 pts/4 00:00:00 grep --color=auto cat[1]+ 已停止 cat /etc/profile | more
杀死进程cat。
[root@centos-linux ~]# pidof cat8288[root@centos-linux ~]# kill -9 8288
再次查看进程cat,看其是否已被杀死。
[root@centos-linux ~]# ps -ef | grep catcyy 3985 3577 0 06:47 ? 00:00:00 /usr/bin/gnome-software --gapplication-serviceroot 6203 5675 0 06:56 ? 00:00:00 /usr/bin/gnome-software --gapplication-serviceroot 8421 8010 0 07:12 pts/4 00:00:00 grep --color=auto cat
(2)使用top命令查看和控制进程:
用top命令动态显示当前的进程。
[root@centos-linux ~]# toptop - 10:24:52 up 1:05, 3 users, load average: 0.00, 0.01, 0.05Tasks: 446 total, 1 running, 445 sleeping, 0 stopped, 0 zombie%Cpu(s): 0.2 us, 0.2 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 stKiB Mem : 1868688 total, 159608 free, 576136 used, 1132944 buff/cacheKiB Swap: 0 total, 0 free, 0 used. 1082740 avail MemPID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND1 root 20 0 191616 6876 3920 S 0.3 0.4 0:04.61 systemd303 root 20 0 0 0 0 S 0.3 0.0 0:03.75 kworker/0:23332 root 20 0 377552 17920 14296 S 0.3 1.0 0:03.10 vmtoolsd4725 root 20 0 146420 2376 1428 R 0.3 0.1 0:00.04 top2 root 20 0 0 0 0 S 0.0 0.0 0:00.03 kthreadd3 root 20 0 0 0 0 S 0.0 0.0 0:00.09 ksoftirqd/05 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H6 root 20 0 0 0 0 S 0.0 0.0 0:00.25 kworker/u256:07 root rt 0 0 0 0 S 0.0 0.0 0:00.04 migration/08 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/010 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/111 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/212 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/313 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/414 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/515 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/6
(3)挂起和恢复进程:
执行命令cat。
按Ctrl+z组合键,挂起进程cat。
[root@centos-linux ~]# cat /etc/profile | more# /etc/profile# System wide environment and startup programs, for login setup# Functions and aliases go in /etc/bashrc# It's NOT a good idea to change this file unless you know what you# are doing. It's much better to create a custom.sh shell script in# /etc/profile.d/ to make custom changes to your environment, as this# will prevent the need for merging in future updates.pathmunge () {case ":${PATH}:" in*:"$1":*);;*)if [ "$2" = "after" ] ; thenPATH=$PATH:$1elsePATH=$1:$PATHfiesac}if [ -x /usr/bin/id ]; thenif [ -z "$EUID" ]; then# ksh workaroundEUID=`id -u`UID=`id -ru`--More--[1]+ 已停止 cat /etc/profile | more
输入jobs命令,查看作业。
[root@centos-linux ~]# jobs[1]+ 已停止 cat /etc/profile | more[root@centos-linux ~]#
输入bg,把cat切换到后台执行。
[root@centos-linux ~]# bg %1[1]+ cat /etc/profile | more &
Ø输入fg,把cat切换到前台执行。
[1]+ cat /etc/profile | more &[root@centos-linux ~]# fg %1cat /etc/profile | morefi
按Ctrl+c组合键,结束进程cat。
[root@centos-linux ~]# bg %1[1]+ cat /etc/profile | more &[root@centos-linux ~]# fg %1cat /etc/profile | morefiUSER="`id -un`"[root@centos-linux ~]#
(4)find命令的使用:
在/var/lib目录下查找其所有者是games用户的所有文件。
[root@centos-linux ~]# find /var/lib -user games[root@centos-linux ~]#
在/var目录下查找其所有者是root用户的所有文件并用长格式显示。
[root@centos-linux ~]# find /root -user root -exec ls -l {} \;总用量 5100-rw-r--r--. 1 root root 24 3月 20 15:21 1.txt-rw-r--r--. 1 root root 49 3月 20 15:35 2.txt-rw-r--r--. 1 root root 73 3月 20 15:36 3.txt-rw-------. 1 root root 1450 2月 7 15:29 anaconda-ks.cfg-rw-------. 1 root root 5206016 3月 19 09:25 core.3751-rw-r--r--. 1 root root 0 3月 20 15:14 file1.txt-rw-r--r--. 1 root root 0 3月 20 15:15 user_file.txtdrwxr-xr-x. 2 root root 6 3月 18 11:02 公共drwxr-xr-x. 2 root root 6 3月 18 11:02 模板drwxr-xr-x. 2 root root 6 3月 18 11:02 视频drwxr-xr-x. 2 root root 6 3月 18 11:02 图片drwxr-xr-x. 2 root root 6 3月 18 11:02 文档drwxr-xr-x. 2 root root 6 3月 18 11:02 下载
Ø 查找/usr/bin目录下所有大小超过1 000 000 B的文件并用长格式显示。
[root@centos-linux ~]# find /usr/bin -size -1953 -exec ls -l {} \; | more总用量 126032-rwxr-xr-x. 1 root root 41448 11月 20 2015 [-rwxr-xr-x. 1 root root 107824 11月 20 2015 a2p-rwxr-xr-x. 1 root root 11232 12月 1 2015 abrt-action-analyze-backtrace-rwxr-xr-x. 1 root root 15312 12月 1 2015 abrt-action-analyze-c-rwxr-xr-x. 1 root root 1345 12月 1 2015 abrt-action-analyze-ccpp-local-rwxr-xr-x. 1 root root 6821 12月 1 2015 abrt-action-analyze-core-rwxr-xr-x. 1 root root 11208 12月 1 2015 abrt-action-analyze-oops-rwxr-xr-x. 1 root root 11216 12月 1 2015 abrt-action-analyze-python-rwxr-xr-x. 1 root root 2814 12月 1 2015 abrt-action-analyze-vmcore-rwxr-xr-x. 1 root root 1348 12月 1 2015 abrt-action-analyze-vulnerability-rwxr-xr-x. 1 root root 11248 12月 1 2015 abrt-action-analyze-xorg-rwxr-xr-x. 1 root root 5002 12月 1 2015 abrt-action-check-oops-for-hw-error-rwxr-xr-x. 1 root root 11232 12月 1 2015 abrt-action-generate-backtrace-rwxr-xr-x. 1 root root 11224 12月 1 2015 abrt-action-generate-core-backtrace-rwxr-xr-x. 1 root root 8341 12月 1 2015 abrt-action-install-debuginfo-rwxr-xr-x. 1 root root 3207 12月 1 2015 abrt-action-list-dsos-rwxr-xr-x. 1 root root 8958 12月 1 2015 abrt-action-notify-rwxr-xr-x. 1 root root 3535 12月 1 2015 abrt-action-perform-ccpp-analysis-rwxr-xr-x. 1 root root 951 12月 1 2015 abrt-action-save-kernel-data-rwxr-xr-x. 1 root root 19584 12月 1 2015 abrt-action-save-package-data-rwxr-xr-x. 1 root root 15376 12月 1 2015 abrt-action-trim-files-rwxr-xr-x. 1 root root 48608 12月 1 2015 abrt-applet-rwxr-xr-x. 1 root root 27944 12月 1 2015 abrt-cli-rwxr-xr-x. 1 root root 19448 12月 1 2015 abrt-dump-oops-rwxr-xr-x. 1 root root 15344 12月 1 2015 abrt-dump-xorg-rwxr-xr-x. 1 root root 9048 12月 1 2015 abrt-handle-upload-rwxr-xr-x. 1 root root 11248 12月 1 2015 abrt-merge-pstoreoops-rwxr-xr-x. 1 root root 44472 12月 1 2015 abrt-retrace-client--More--
Ø 查找/tmp目录下属于student的所有普通文件,这些文件的修改时间为120 min以前,查询结果用长格式显示。
[root@centos-linux ~]# find /tmp -type f -user root -atime +0.1 -exec ls -l {} \; | more-rw-------. 1 root root 1058607 3月 14 09:05 /tmp/yum_save_tx.2021-03-14.09-05.rrhvmn.yumtx-rw-------. 1 root root 1058607 3月 13 15:37 /tmp/yum_save_tx.2021-03-13.15-37.P1I6Sl.yumtx-rw-------. 1 root root 1058607 3月 18 11:03 /tmp/yum_save_tx.2021-03-18.11-03.IdRQLw.yumtx-r--r--r--. 1 root root 11 3月 22 14:36 /tmp/.X0-lock[root@centos-linux ~]#
Ø 对于查到的上述文件,用-ok选项删除。
[root@centos-linux ~]# find /tmp -type f -user root -atime +0.1 -ok rm * {} \; | more< rm ... /tmp/yum_save_tx.2021-03-14.09-05.rrhvmn.yumtx > ?
三、实验作业
1、 查看/etc/httpd/conf/httpd.conf文件的前10行和后10行;
[root@centos-linux ~]# head -n 10 /etc/profile# /etc/profile# System wide environment and startup programs, for login setup# Functions and aliases go in /etc/bashrc# It's NOT a good idea to change this file unless you know what you# are doing. It's much better to create a custom.sh shell script in# /etc/profile.d/ to make custom changes to your environment, as this# will prevent the need for merging in future updates.[root@centos-linux ~]# tail -n 10 /etc/profileif [ "${-#*i}" != "$-" ]; then. "$i"else. "$i" >/dev/nullfifidoneunset iunset -f pathmunge[root@centos-linux ~]#
2、 实时查看最新日志文件;
[root@centos-linux ~]# tail -f /var/log/messagesMar 28 07:10:01 centos-linux systemd: Started Session 13 of user root.Mar 28 07:10:01 centos-linux systemd: Starting Session 13 of user root.Mar 28 07:20:01 centos-linux systemd: Started Session 14 of user root.Mar 28 07:20:01 centos-linux systemd: Starting Session 14 of user root.Mar 28 07:30:01 centos-linux systemd: Started Session 15 of user root.Mar 28 07:30:01 centos-linux systemd: Starting Session 15 of user root.
3、 查看ls命令所在位置和命令简介;
[root@centos-linux ~]# locate ls |more/boot/grub2/i386-pc/blscfg.mod/boot/grub2/i386-pc/cbls.mod/boot/grub2/i386-pc/command.lst/boot/grub2/i386-pc/crypto.lst/boot/grub2/i386-pc/fs.lst/boot/grub2/i386-pc/ls.mod/boot/grub2/i386-pc/lsacpi.mod/boot/grub2/i386-pc/lsapm.mod/boot/grub2/i386-pc/lsmmap.mod/boot/grub2/i386-pc/lspci.mod/boot/grub2/i386-pc/moddep.lst/boot/grub2/i386-pc/partmap.lst/boot/grub2/i386-pc/parttool.lst/boot/grub2/i386-pc/terminal.lst/boot/grub2/i386-pc/video.lst/etc/alsa/etc/cifs-utils/etc/lsm/etc/mtools.conf/etc/protocols/etc/pulse/etc/shells/etc/smartmontools/etc/vmware-tools/etc/alsa/alsactl.conf/etc/alsa/state-daemon.conf/etc/bash_completion.d/iprutils/etc/bash_completion.d/yum-utils.bash/etc/brltty/brl-bm-wheels.kti--More--[root@centos-linux ~]# man lsLS(1) User Commands LS(1)NAMEls - list directory contentsSYNOPSISls [OPTION]... [FILE]...DESCRIPTIONList information about the FILEs (the current directory by default). Sort entries alphabetically ifnone of -cftuvSUX nor --sort is specified.Mandatory arguments to long options are mandatory for short options too.-a, --alldo not ignore entries starting with .-A, --almost-alldo not list implied . and ..--authorwith -l, print the author of each file
4、 查看系统的信息;
[root@centos-linux ~]# uname -aLinux centos-linux 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
5、 查看系统的内存使用情况
[root@centos-linux ~]# freetotal used free shared buff/cache availableMem: 1868688 951940 379080 12040 537668 693264Swap: 0 0 0[root@centos-linux ~]#
6、 显示2019年10月日历;
[root@centos-linux ~]# cal 10 2019十月 2019日 一 二 三 四 五 六1 2 3 4 56 7 8 9 10 11 1213 14 15 16 17 18 1920 21 22 23 24 25 2627 28 29 30 31
7、查看系统正在运行的进程;
[root@centos-linux ~]# ps -aux | moreUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.0 0.3 191616 6868 ? Ss 06:20 0:03 /usr/lib/systemd/systemd --switched-root --system --deserialize 21root 2 0.0 0.0 0 0 ? S 06:20 0:00 [kthreadd]root 3 0.0 0.0 0 0 ? S 06:20 0:00 [ksoftirqd/0]root 5 0.0 0.0 0 0 ? S< 06:20 0:00 [kworker/0:0H]root 6 0.0 0.0 0 0 ? S 06:20 0:00 [kworker/u256:0]root 7 0.0 0.0 0 0 ? S 06:20 0:00 [migration/0]root 8 0.0 0.0 0 0 ? S 06:20 0:00 [rcu_bh]root 9 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/0]root 10 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/1]root 11 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/2]root 12 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/3]root 13 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/4]root 14 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/5]root 15 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/6]root 16 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/7]root 17 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/8]root 18 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/9]root 19 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/10]root 20 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/11]root 21 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/12]root 22 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/13]root 23 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/14]root 24 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/15]root 25 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/16]root 26 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/17]root 27 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/18]root 28 0.0 0.0 0 0 ? S 06:20 0:00 [rcuob/19]--More--
8、通过find命令在/路径下查找L开头的文件
[root@centos-linux ~]# find / -name L* | morefind: ‘/run/user/1000/gvfs’: 权限不够/run/media/cyy/CentOS 7 x86_64/LiveOS/run/media/cyy/CentOS 7 x86_64/Packages/LibRaw-0.14.8-5.el7.20120830git98d925.x86_64.rpm/sys/bus/acpi/devices/LNXCPU:00/sys/bus/acpi/devices/LNXCPU:01/sys/bus/acpi/devices/LNXCPU:02/sys/bus/acpi/devices/LNXCPU:03/sys/bus/acpi/devices/LNXCPU:04/sys/bus/acpi/devices/LNXCPU:05/sys/bus/acpi/devices/LNXCPU:06/sys/bus/acpi/devices/LNXCPU:07/sys/bus/acpi/devices/LNXCPU:08/sys/bus/acpi/devices/LNXCPU:09/sys/bus/acpi/devices/LNXCPU:10/sys/bus/acpi/devices/LNXCPU:11/sys/bus/acpi/devices/LNXCPU:12/sys/bus/acpi/devices/LNXCPU:13/sys/bus/acpi/devices/LNXCPU:14/sys/bus/acpi/devices/LNXCPU:15/sys/bus/acpi/devices/LNXCPU:16/sys/bus/acpi/devices/LNXCPU:17/sys/bus/acpi/devices/LNXCPU:18/sys/bus/acpi/devices/LNXCPU:19/sys/bus/acpi/devices/LNXCPU:20/sys/bus/acpi/devices/LNXCPU:21/sys/bus/acpi/devices/LNXCPU:22/sys/bus/acpi/devices/LNXCPU:23/sys/bus/acpi/devices/LNXCPU:24/sys/bus/acpi/devices/LNXCPU:25/sys/bus/acpi/devices/LNXCPU:26--More--
9、查看在后台运行的进程;
[root@centos-linux ~]# jobs[1]+ 已停止 cat /etc/profile | more
10、列出命令shutdown的帮助手册;
[root@centos-linux ~]# man shutdownSHUTDOWN(8) shutdown SHUTDOWN(8)NAMEshutdown - Halt, power-off or reboot the machineSYNOPSISshutdown [OPTIONS...] [TIME] [WALL...]
11、查看系统中已定义的别名,设置ifconfig命令的别名为ipconfig;
[root@centos-linux ~]# alias ipconfig=ifconfig[root@centos-linux ~]# aliasalias cp='cp -i'alias egrep='egrep --color=auto'alias fgrep='fgrep --color=auto'alias grep='grep --color=auto'alias ipconfig='ifconfig'alias l.='ls -d .* --color=auto'alias ll='ls -l --color=auto'alias ls='ls --color=auto'alias mv='mv -i'alias rm='rm -i'alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
12、取消ipconfig别名的设置;
[root@centos-linux ~]# unalias ipconfig[root@centos-linux ~]# ipconfigbash: ipconfig: 未找到命令...
