0

I want to remove the files those are listed by locate command.
Is there a way to use a single command to do so?

I am using 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:~$

Edit:

@αғsнιη answer worked. But some files have some permissions problem.. I accept the risk with permissions, Finally I want all the files to be removed those are listed with locate command.

this command worked.

locate -0 grub | xargs -0 rm -rf -- but still some files are not removed, i think some permissions problem.

enter image description here

  • 1
    I think you are going to wipe your system! – αғsнιη Apr 29 '19 at 10:55
  • no, i only want all the files to be removed those are related to grub, i have run sudo apt purge grub* sudo apt purge plymouth* – PRATAP Apr 29 '19 at 10:59
  • DO NOT PARSE LS OR LOCATE. Use find with the -delete action. sudo locate -0 grub | xargs ... runs locate as root, not xargs (or rm). The other files could not be deleted because they are located in a read-only file system. Those are part of the core snap. If you don't use snap, you can uninstall snapd via apt. They are not related to the grub you purged. Generally when using locate, remember to run sudo updatedb if any files/folders changed. – danzel Apr 30 '19 at 14:42
  • thank you for nice comment.. i will go through it.. please note that i accept the risk.. but i want to delete all those..Ok i will try with your find command and then try to locate grub if any left.. – PRATAP Apr 30 '19 at 15:06
-1

Try piping the output to xargs, like so:

locate grub | xargs rm
| improve this answer | |
  • Paths with whitespace characters will be treated as multiple arguments. This is one of many reasons why you don't parse ls or locate (or any other command that prints file names). – danzel Apr 30 '19 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.