Linux文件查找、打包压缩、用户别名、用户管理

文件查找

  • 在$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.

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值