02 Linux入门-详解alias rm=mv...
详解alias rm=mv...
[root@centos7-kevin306 ~]#
[root@centos7-kevin306 ~]# cd /data/
[root@centos7-kevin306 data]# ls
[root@centos7-kevin306 data]# mkdir /delfiles
mkdir: cannot create directory ‘/delfiles’: File exists
[root@centos7-kevin306 data]# mkdir -p /delfiles
[root@centos7-kevin306 data]# cd ~
[root@centos7-kevin306 ~]# ls
[root@centos7-kevin306 ~]# cd /data/
[root@centos7-kevin306 data]# ls
delfiles
[root@centos7-kevin306 data]# cd /de
delfiles/ dev/
[root@centos7-kevin306 data]# cd /delfiles
[root@centos7-kevin306 delfiles]# ls
[root@centos7-kevin306 delfiles]# ls
[root@centos7-kevin306 delfiles]#
[root@centos7-kevin306 delfiles]#
[root@centos7-kevin306 delfiles]# cd ~
[root@centos7-kevin306 ~]# ls
2.txt 3.txt 4.txt 5.txt anaconda-ks.cfg reset_centos-kevin01.sh
[root@centos7-kevin306 ~]# rm 2.txt
[root@centos7-kevin306 ~]# ls
3.txt 4.txt 5.txt anaconda-ks.cfg reset_centos-kevin01.sh
[root@centos7-kevin306 ~]# cd /data/
[root@centos7-kevin306 data]# ls
delfiles
[root@centos7-kevin306 data]# cd /delfiles/
[root@centos7-kevin306 delfiles]# ls
[root@centos7-kevin306 delfiles]#
[root@centos7-kevin306 delfiles]# cd ~
[root@centos7-kevin306 ~]# ls
3.txt 4.txt 5.txt anaconda-ks.cfg reset_centos-kevin01.sh
[root@centos7-kevin306 ~]#
[root@centos7-kevin306 ~]# alias rm='DIR=/data/delfiles/backup`date +%F%T`;mkdir -p $DIR;mv -t $DIR;echo "$(pwd)" > $DIR/pwd.txt'
[root@centos7-kevin306 ~]# ls
3.txt 4.txt 5.txt anaconda-ks.cfg reset_centos-kevin01.sh
[root@centos7-kevin306 ~]# rm 3.txt
mv: missing file operand
Try 'mv --help' for more information.
[root@centos7-kevin306 ~]# mv 3.txt
mv: missing destination file operand after ‘3.txt’
Try 'mv --help' for more information.
[root@centos7-kevin306 ~]# cd /delfiles/
[root@centos7-kevin306 delfiles]# ls
[root@centos7-kevin306 delfiles]# cd ~
[root@centos7-kevin306 ~]# tree /data
/data
└── delfiles
├── backup2021-08-2421:12:51
│ ├── 123
│ └── pwd.txt
├── backup2021-08-2421:13:09
│ ├── 1.txt
│ └── pwd.txt
├── backup2021-08-2421:13:54
│ ├── 2.txt
│ └── pwd.txt
└── backup2021-08-2421:22:31
└── pwd.txt
5 directories, 7 files
[root@centos7-kevin306 ~]# cd /data/delfiles/
[root@centos7-kevin306 delfiles]# ls
backup2021-08-2421:12:51 backup2021-08-2421:13:09 backup2021-08-2421:13:54 backup2021-08-2421:22:31
[root@centos7-kevin306 delfiles]# cd /data/delfiles/
[root@centos7-kevin306 delfiles]# cd /data/delfiles/backup2021-08-2421\:12:51
[root@centos7-kevin306 backup2021-08-2421:12:51]# ls
123 pwd.txt
[root@centos7-kevin306 backup2021-08-2421:12:51]# cat pwd
cat: pwd: No such file or directory
[root@centos7-kevin306 backup2021-08-2421:12:51]# cat pwd.txt
/root
[root@centos7-kevin306 backup2021-08-2421:12:51]#
浙公网安备 33010602011771号