Linux 上 删除多个文件

1、rm -f 2018-10-*.log 2018-09-*.log
2、ls | xargs -n 10 rm -rf (10个1组,分批删除,可删除大量文件)
演示如下:

root@root:/b# ls
eclipse rar
eclipse-jee-mars-2-linux-gtk-x86_64.tar.gz rarlinux-x64-5.7.1.tar.gz
gns3-server_2.1.21_xenial2_amd64.deb redis-5.0.5
ippbx_db.sql redis-5.0.5.tar.gz
jdk-8u211-linux-x64-demos.tar.gz sublime_text_3
jre-8u211-linux-x64.tar.gz sublime_text_3_build_3207_x32.tar.bz2
lost+found sublime_text_3_build_3207_x64.tar.bz2
mariadb-server_5.5.36 uex
MX500-zycoo_db.rar uex_18.00.0.66_amd64.deb
MySQL uex-18.00.0.66_amd64.tar.gz
mysql-8.0.16-community uex-18.00.0.66_i386.tar.gz
mysql-server_8.0.15-1debian9 VMware-Workstation-Full-15.1.0-13591040.x86_64.bundle
mysql-workbench-community-8.0.16-src.tar.gz zycoo_coovox.sql
MySQL.zip zycoo_u20_db.rar
'Packet Tracer 7.2.1 for Linux 64 bit.tar.gz'
root@root:/b# rm -f ./*.sql
root@root:/b# ls
eclipse rar
eclipse-jee-mars-2-linux-gtk-x86_64.tar.gz rarlinux-x64-5.7.1.tar.gz
gns3-server_2.1.21_xenial2_amd64.deb redis-5.0.5
jdk-8u211-linux-x64-demos.tar.gz redis-5.0.5.tar.gz
jre-8u211-linux-x64.tar.gz sublime_text_3
lost+found sublime_text_3_build_3207_x32.tar.bz2
mariadb-server_5.5.36 sublime_text_3_build_3207_x64.tar.bz2
MX500-zycoo_db.rar uex
MySQL uex_18.00.0.66_amd64.deb
mysql-8.0.16-community uex-18.00.0.66_amd64.tar.gz
mysql-server_8.0.15-1debian9 uex-18.00.0.66_i386.tar.gz
mysql-workbench-community-8.0.16-src.tar.gz VMware-Workstation-Full-15.1.0-13591040.x86_64.bundle
MySQL.zip zycoo_u20_db.rar
'Packet Tracer 7.2.1 for Linux 64 bit.tar.gz'

root@root:/b# ls | grep ".*sql$"
ippbx_db.sql
zycoo_coovox.sql
root@root:/b# ls | grep ".*sql$" | xargs rm -f
root@root:/b# ls
eclipse rar
eclipse-jee-mars-2-linux-gtk-x86_64.tar.gz rarlinux-x64-5.7.1.tar.gz
gns3-server_2.1.21_xenial2_amd64.deb redis-5.0.5
jdk-8u211-linux-x64-demos.tar.gz redis-5.0.5.tar.gz
jre-8u211-linux-x64.tar.gz sublime_text_3
lost+found sublime_text_3_build_3207_x32.tar.bz2
mariadb-server_5.5.36 sublime_text_3_build_3207_x64.tar.bz2
MX500-zycoo_db.rar uex
MySQL uex_18.00.0.66_amd64.deb
mysql-8.0.16-community uex-18.00.0.66_amd64.tar.gz
mysql-server_8.0.15-1debian9 uex-18.00.0.66_i386.tar.gz
mysql-workbench-community-8.0.16-src.tar.gz VMware-Workstation-Full-15.1.0-13591040.x86_64.bundle
MySQL.zip zycoo_u20_db.rar
'Packet Tracer 7.2.1 for Linux 64 bit.tar.gz'

root@root:/b# find /b -name "*sql";
/b/zycoo_coovox.sql
/b/ippbx_db.sql
root@root:/b# find /b -name "*sql" | xargs sudo rm -f
root@root:/b# ls
eclipse rar
eclipse-jee-mars-2-linux-gtk-x86_64.tar.gz rarlinux-x64-5.7.1.tar.gz
gns3-server_2.1.21_xenial2_amd64.deb redis-5.0.5
jdk-8u211-linux-x64-demos.tar.gz redis-5.0.5.tar.gz
jre-8u211-linux-x64.tar.gz sublime_text_3
lost+found sublime_text_3_build_3207_x32.tar.bz2
mariadb-server_5.5.36 sublime_text_3_build_3207_x64.tar.bz2
MX500-zycoo_db.rar uex
MySQL uex_18.00.0.66_amd64.deb
mysql-8.0.16-community uex-18.00.0.66_amd64.tar.gz
mysql-server_8.0.15-1debian9 uex-18.00.0.66_i386.tar.gz
mysql-workbench-community-8.0.16-src.tar.gz VMware-Workstation-Full-15.1.0-13591040.x86_64.bundle
MySQL.zip zycoo_u20_db.rar
'Packet Tracer 7.2.1 for Linux 64 bit.tar.gz'

PS:-f选项表示强制删除,不用确认,-r选项表示递归删除,将会查找给出路径的子目录,如果匹配,也将删除文件。

转载于:https://www.cnblogs.com/xhai/p/11222105.html

你可能感兴趣的:(Linux 上 删除多个文件)