文件查找
- 在$HOME目录及其子目录中,查找天前被更改过的文件
[root@localhost test]# find $HOME -ctime +2
- 在/etc/目录下寻找以host开头的文件
[root@localhost ~]# ls /etc/ | grep host
host.conf
hostname
hosts
- 在/test/下面查找目录文件
[root@localhost test]# find /root/test -type d
/root/test
/root/test/mashaoke
/root/test/guosichi
- 在/test/目录及子目录中,查找超过2KB的文件
[root@localhost test]# find /root/test -size +2
打包压缩
- 将/test目录下的所有文件和文件夹全部压缩成mylife.zip文件
[root@localhost test]# zip mylife.zip /root/test -r
adding: root/test/ (stored 0%)
adding: root/test/mashaoke/ (stored 0%)
adding: root/test/guosichi/ (stored 0%)
- 把myfile.zip文件夹解压到/opt
[root@localhost test]# unzip mylife.zip -d /opt
Archive: mylife.zip
creating: /opt/root/test/
creating: /opt/root/test/mashaoke/
creating: /opt/root/test/guosichi/
- 将/opt目录下的文件和文件夹全部压缩成/test/newfile.tar.gz
[root@localhost test]# tar -zcvf /test/newfile.tar.gz /opt/
tar: Removing leading `/' from member names
/opt/
/opt/root/
/opt/root/test/
/opt/root/test/mashaoke/
/opt/root/test/guosichi/
tar (child): /test/newfile.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
- 查看/test/newfile.tar.gz文件中有哪些文件?
[root@localhost test]# tar -tf /test/newfile.tar.gz
- 在/test目录内,备份/etc下的所有文件并保留权限
[root@localhost test]# tar -cvpf test.tar /test/test/
别名
- 当前用户永久生效的命令别名
(1)写一个命令为hello,实现功能为每输入一次hello命令,就有hello,everone写入文件/file.txt中。
vim ~/.bashrc
添加alias shuaxin='touch /file.txt' 后保存退出
(2)写一个命令别名为shuaxin,实现的功能为每输入一次该命令,file.txt文件的时间就更新为当前时间。
vim /etc/bashrc
添加alias hh='touch ~/file1' 后保存退出
- 写所有用户生效的别名
写一个所有用户都生效的命令别名为hh,每一个用户输入这个命令之后可以在该用户家目录下创建一个file1文件。
用户管理
- 新建一个名为sarah的用户,不属于adminuser组,并将其shell设置为不可登录shell
[root@localhost test]# useradd sarah -s/sbin/nologin
- 创建alex用户,使alex用户满足以下要求:用户id为3456,描述名为alian,密码为glegunge
[root@localhost test]# useradd alex -u3456 -calian
[root@localhost test]# echo glegunge | passwd --stdin alex
Changing password for user alex.
passwd: all authentication tokens updated successfully.