2

Rocky基础练习题1

 2 years ago
source link: https://blog.51cto.com/dayu/5449018
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Rocky基础练习题1

原创
基础入门练习题1
1-1、显示当前时间

格式:2016-06-18 10:20:30

[root@rocky8 ~]#date +'%F %T'
2022-06-30 19:56:01
1-2、显示前天是星期几
[root@rocky8 ~]#date -d '-2 day' +%u
2
1-3、设置当前日期为2019-08-07 06:05:10
[root@rocky8 ~]#date 0807060519.10
Wed Aug 7 06:05:10 CST 2019
[root@rocky8 ~]#date +'%F %T'
2019-08-07 06:05:12

[root@rocky8-1 ~]#date -s '22-07-04 08:52:00' #设置当前日期为2022-07-04 08:52:00
Mon Jul 4 08:52:00 CST 2022

注:date修改时间格式:date 月日时分年**.**秒

date -s 修改时间格式:年-月-日 时:分:秒

1-4、在本机字符终端登录时

除显示原有信息外,再显示当前登录终端号,主机名和当前时间

[root@rocky8 ~]#cat /etc/issue
\S
Kernel \r on an \m
TTY is \l
HOSTNAME is \n
DATE is \d
TIME is \t

注:issue 内的各代码意义

\d 本地端时间的日期;

\l 显示第几个终端机介面;

\m 显示硬体的等级 (i386/i486/i586/i686...);

\n 显示主机的网路名称;

\O 显示 domain name;

\r 作业系统的版本 (相当于 uname -r)

\t 显示本地端时间的时间;

\S 作业系统的名称;

\v 作业系统的版本。

1-5、今天20:30自动关机,并提示用户
[root@rocky8 ~]#shutdown -h 20:30
Shutdown scheduled for Thu 2022-06-30 20:30:00 CST, use 'shutdown -c' to cancel.

注:shutdown -c 取消设置的20:30关机计划

1-6、显示/etc目录下所有以l开头,以一个小写字母结尾,且中间出现至少一位数字的文件或目录列表
[root@rocky8 ~]#ls /etc/l*[0-9]*[a-z]
/etc/l98df98b
1-7、显示/etc目录下以任意一位数字开头,且以非数字结尾的文件或目录列表
[root@rocky8 ~]# ls /etc/[0-9]*[^0-9]
/etc/0ilksajf
1-8、显示/etc/目录下以非字母开头,后面跟了一个字母及其它任意长度任意字符的文件或目录列表
[root@rocky8 ~]# ls /etc/[^[:alpha:]][[:alpha:]]*
/etc/0ilksajf
1-9、显示/etc/目录下所有以rc开头,并后面是0-6之间的数字,其它为任意字符的文件或目录列表
[root@rocky8 ~]# ls /etc/rc[0-6]*
/etc/rc0.d:

/etc/rc1.d:

/etc/rc2.d:

/etc/rc3.d:

/etc/rc4.d:

/etc/rc5.d:

/etc/rc6.d:
1-10、显示/etc目录下,所有.conf结尾,且以m,n,r,p开头的文件或目录列表
[root@rocky8 ~]# ls /etc/[mnrp]*.conf
/etc/man_db.conf /etc/nsswitch.conf /etc/rsyslog.conf
/etc/mke2fs.conf /etc/resolv.conf
1-11、只显示/root下的隐藏文件和目录列表
[root@rocky8-1 ~]#ls /root/.[^.]* -d
/root/.bash_history /root/.cache /root/.lesshst
/root/.bash_logout /root/.config /root/.tcshrc
/root/.bash_profile /root/.cshrc /root/.viminfo
/root/.bashrc /root/.dbus
1-12、只显示/etc下的非隐藏目录列表
[root@rocky8 ~]##ls -d /etc/*/
1-13、每天将/etc/目录下所有文件,备份到data独立的子目录下,并要求子目录格式为 backupYYYY-mm-dd,备份过程可见
[root@rocky8 ~]#mkdir -p data/backup$(date +%F);cp -av /etc/* data/backup$(date +%F)
[root@rocky8 data]# ls
backup2022-07-02
1-14、创建/data/rootdir目录,并复制/root下所有文件到该目录内,要求保留原有权限
[root@rocky8-1 ~]#mkdir -p /data/rootdir
[root@rocky8-1 ~]#cp -a /root/{*,.[^.]*} /data/rootdir/
1-15、如何创建/test/dir/x, /test/dir/y, /test/dir/x/a, /test/dir/x/b, /test/dir/y/a, /test/dir/y/
[root@rocky8-1 ~]#mkdir -p test/dir/{x,y}/{a,b}
[root@rocky8-1 ~]#ls
anaconda-ks.cfg initial-setup-ks.cfg test
[root@rocky8-1 ~]#tree test
test
└── dir
├── x
│ ├── a
│ └── b
└── y
├── a
└── b

7 directories, 0 files
1-16、如何创建/test/dir/x, /test/dir/y, /test/dir/x/a, /test/dir/x/b
[root@rocky8-1 ~]#mkdir -p test/dir/x/{a,b} test/dir/y
[root@rocky8-1 ~]#tree
.
├── anaconda-ks.cfg
├── initial-setup-ks.cfg
└── test
└── dir
├── x
│ ├── a
│ └── b
└── y

[root@rocky8-1 ~]#mkdir -p test/dir/{x/{a,b},y}
[root@rocky8-1 ~]#ls
anaconda-ks.cfg initial-setup-ks.cfg test
[root@rocky8-1 ~]#tree test
test
└── dir
├── x
│ ├── a
│ └── b
└── y
1-17、如何创建/test/dir3, /test/dir4, /test/dir5, /test/dir5/dir6, /test/dir5/dir7
[root@rocky8-1 ~]#mkdir -p test/dir{3,4,5} test/dir5/dir{6,7}
[root@rocky8-1 ~]#ls
anaconda-ks.cfg initial-setup-ks.cfg test
[root@rocky8-1 ~]#tree test
test
├── dir3
├── dir4
└── dir5
├── dir6
└── dir7
[root@rocky8-1 ~]#mkdir -p test/dir{3,4,5/dir{6,7}}
[root@rocky8-1 ~]#tree test
test
├── dir
│ ├── x
│ │ ├── a
│ │ └── b
│ └── y
├── dir3
├── dir4
└── dir5
├── dir6
└── dir7

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK