如何删除使用“locate”命令列出的文件

如何删除使用“locate”命令列出的文件

我想删除命令列出的文件locate
有没有办法使用单个命令来实现这一点?

我正在使用 Ubuntu 18.04.2

pratap@i7-4770U:~$ locate grub
/boot/grub
/etc/grub.d
/etc/alternatives/default.plymouth.grub
/etc/bash_completion.d/grub
/etc/default/grub
/etc/grub.d/00_header
/etc/grub.d/05_debian_theme
/etc/grub.d/10_linux
/etc/grub.d/20_linux_xen
/etc/grub.d/20_memtest86+
/etc/grub.d/30_os-prober
/etc/grub.d/30_uefi-firmware
/etc/grub.d/40_custom
/etc/grub.d/41_custom
/etc/grub.d/README
/etc/init.d/grub-common
/etc/kernel/postinst.d/zz-update-grub
/etc/kernel/postrm.d/zz-update-grub
/etc/pm/sleep.d/10_grub-common
/etc/rc2.d/S01grub-common
/etc/rc3.d/S01grub-common
/etc/rc4.d/S01grub-common
/etc/rc5.d/S01grub-common
/lib/recovery-mode/options/grub
/snap/core/6350/boot/grub
/snap/core/6350/etc/grub.d
/snap/core/6350/etc/default/grub.d
/snap/core/6350/etc/default/grub.d/50-system-image.cfg
/snap/core/6350/etc/rc2.d/S03grub-common
/snap/core/6350/etc/rc3.d/S03grub-common
/snap/core/6350/etc/rc4.d/S03grub-common
/snap/core/6350/etc/rc5.d/S03grub-common
/snap/core/6350/usr/bin/grub-editenv
/snap/core/6350/usr/lib/grub
/snap/core/6350/usr/lib/grub/grub-mkconfig_lib
/snap/core/6350/usr/lib/python3/dist-packages/cloudinit/config/cc_grub_dpkg.py
/snap/core/6350/usr/lib/python3/dist-packages/cloudinit/config/__pycache__/cc_grub_dpkg.cpython-35.pyc
/snap/core/6350/usr/share/grub
/snap/core/6350/usr/share/bug/grub-common
/snap/core/6350/usr/share/doc/grub-common
/usr/bin/grub-editenv
/usr/bin/grub-file
/usr/bin/grub-fstest
/usr/bin/grub-glue-efi
/usr/bin/grub-kbdcomp
/usr/bin/grub-menulst2cfg
/usr/bin/grub-mkfont
/usr/bin/grub-mkimage
/usr/bin/grub-mklayout
/usr/bin/grub-mknetdir
/usr/bin/grub-mkpasswd-pbkdf2
/usr/bin/grub-mkrelpath
/usr/bin/grub-mkrescue
/usr/bin/grub-mkstandalone
/usr/bin/grub-mount
/usr/bin/grub-ntldr-img
/usr/bin/grub-render-label
/usr/bin/grub-script-check
/usr/bin/grub-syslinux2cfg
/usr/lib/grub
/usr/lib/grub-legacy
/usr/sbin/grub-bios-setup
/usr/sbin/grub-install
/usr/sbin/grub-macbless
/usr/sbin/grub-mkconfig
/usr/sbin/grub-mkdevicemap
/usr/sbin/grub-probe
/usr/sbin/grub-reboot
/usr/sbin/grub-set-default
/usr/sbin/update-grub
/usr/sbin/update-grub-gfxpayload
/usr/sbin/update-grub2
/usr/sbin/upgrade-from-grub-legacy
/usr/share/grub
/usr/share/grub-gfxpayload-lists
/usr/share/apport/package-hooks/source_grub2.py
/usr/share/bug/grub-common
/usr/share/bug/grub-pc
/usr/share/bug/grub-pc-bin
/usr/share/bug/grub2-common
/usr/share/doc/grub-common
/usr/share/doc/grub-gfxpayload-lists
/usr/share/doc/grub-pc
/usr/share/doc/grub-pc-bin
/usr/share/doc/grub2-common
/usr/share/doc/memtest86+/examples/grub-menu.lst
/usr/share/info/grub-dev.info.gz
/usr/share/info/grub.info.gz
/usr/share/lintian/overrides/grub-pc-bin
/usr/share/locale-langpack/en@quot/LC_MESSAGES/grub.mo
/usr/share/locale-langpack/en_AU/LC_MESSAGES/grub.mo
/usr/share/locale-langpack/en_CA/LC_MESSAGES/grub.mo
/usr/share/locale-langpack/en_GB/LC_MESSAGES/grub.mo
/usr/share/man/man1/grub-editenv.1.gz
/usr/share/man/man1/grub-file.1.gz
/usr/share/man/man1/grub-fstest.1.gz
/usr/share/man/man1/grub-glue-efi.1.gz
/usr/share/man/man1/grub-kbdcomp.1.gz
/usr/share/man/man1/grub-menulst2cfg.1.gz
/usr/share/man/man1/grub-mkfont.1.gz
/usr/share/man/man1/grub-mkimage.1.gz
/usr/share/man/man1/grub-mklayout.1.gz
/usr/share/man/man1/grub-mknetdir.1.gz
/usr/share/man/man1/grub-mkpasswd-pbkdf2.1.gz
/usr/share/man/man1/grub-mkrelpath.1.gz
/usr/share/man/man1/grub-mkrescue.1.gz
/usr/share/man/man1/grub-mkstandalone.1.gz
/usr/share/man/man1/grub-mount.1.gz
/usr/share/man/man1/grub-render-label.1.gz
/usr/share/man/man1/grub-script-check.1.gz
/usr/share/man/man1/grub-syslinux2cfg.1.gz
/usr/share/man/man8/grub-bios-setup.8.gz
/usr/share/man/man8/grub-install.8.gz
/usr/share/man/man8/grub-macbless.8.gz
/usr/share/man/man8/grub-mkconfig.8.gz
/usr/share/man/man8/grub-mkdevicemap.8.gz
/usr/share/man/man8/grub-probe.8.gz
/usr/share/man/man8/grub-reboot.8.gz
/usr/share/man/man8/grub-set-default.8.gz
/usr/share/man/man8/update-grub-gfxpayload.8.gz
/usr/share/man/man8/update-grub.8.gz
/usr/share/man/man8/update-grub2.8.gz
/usr/share/plymouth/themes/default.grub
/usr/share/plymouth/themes/ubuntu-logo/ubuntu-logo.grub
/var/lib/dpkg/info/grub-common.conffiles
/var/lib/dpkg/info/grub-common.list
/var/lib/dpkg/info/grub-common.md5sums
/var/lib/dpkg/info/grub-common.postinst
/var/lib/dpkg/info/grub-common.postrm
/var/lib/dpkg/info/grub-common.preinst
/var/lib/dpkg/info/grub-common.prerm
/var/lib/dpkg/info/grub-gfxpayload-lists.list
/var/lib/dpkg/info/grub-gfxpayload-lists.md5sums
/var/lib/dpkg/info/grub-gfxpayload-lists.postinst
/var/lib/dpkg/info/grub-gfxpayload-lists.prerm
/var/lib/dpkg/info/grub-pc-bin.list
/var/lib/dpkg/info/grub-pc-bin.md5sums
/var/lib/dpkg/info/grub-pc.conffiles
/var/lib/dpkg/info/grub-pc.config
/var/lib/dpkg/info/grub-pc.list
/var/lib/dpkg/info/grub-pc.md5sums
/var/lib/dpkg/info/grub-pc.postinst
/var/lib/dpkg/info/grub-pc.postrm
/var/lib/dpkg/info/grub-pc.preinst
/var/lib/dpkg/info/grub-pc.prerm
/var/lib/dpkg/info/grub-pc.templates
/var/lib/dpkg/info/grub2-common.list
/var/lib/dpkg/info/grub2-common.md5sums
/var/lib/ucf/cache/:etc:default:grub
pratap@i7-4770U:~$

编辑:

@αғsнιη 答案有效。但有些文件存在权限问题。我接受权限风险,最后我希望删除所有使用locate命令列出的文件。

该命令有效。

locate -0 grub | xargs -0 rm -rf --但仍然有一些文件没有被删除,我认为是存在权限问题。

在此处输入图片描述

答案1

尝试将输出通过管道传输到 xargs,如下所示:

locate grub | xargs rm

相关内容