Skip to main content
115 votes

How to get rid of "No match found" when running "rm *"

This behaviour is controlled by several of Zsh's globbing options. By default, if a command line contains a globbing expression which doesn't match anything, Zsh will print the error message you're ...
Stephen Kitt's user avatar
108 votes
Accepted

Deleting billions of files from a directory while seeing the progress as well

You can use rm -v to have rm print one line per file deleted. This way you can see that rm is indeed working to delete files. But if you have billions of files then all you will see is that rm is ...
Lesmana's user avatar
  • 27.7k
77 votes
Accepted

How can I harden bash scripts against causing harm when changed in the future?

set -u or set -o nounset This would make the current shell treat expansions of unset variables as an error: $ unset build $ set -u $ rm -rf "$build"/* bash: build: unbound variable set -u and set ...
Kusalananda's user avatar
  • 341k
75 votes

What is the difference between 'rm' and 'unlink'?

POSIX specifies that the unlink utility calls the C library unlink function and nothing else. It takes no option. If you pass a valid path name to something which isn't a directory, and if you have ...
Kaz's user avatar
  • 8,665
70 votes
Accepted

I just deleted everything in my home directory. How? And why are some files still there?

Ouch. You aren't the first victim. What went wrong? Starting in your home directory, e.g. /home/felix, or even in /home/felix/src or /home/felix/Downloads/src. cd ../Dependencies/cpython Failed ...
Gilles 'SO- stop being evil''s user avatar
55 votes

How to quote arguments with xargs

I had a similar requirement and ended up using the -I switch to have a placeholder and I was able to quote it. find . -size +1M | xargs -I {} rm "{}"
dee-see's user avatar
  • 659
51 votes

Accidentally ran sudo rm /* on my Arch Linux installation

Arch Linux has four symbolic links in /: bin -> usr/bin lib -> usr/lib lib64 -> usr/lib sbin -> usr/bin You should be able to recreate them (using a Live-USB or an emergency shell) or by ...
stefan0xC's user avatar
  • 1,568
50 votes
Accepted

Deleting specific files based on filename from terminal

You don't need a loop or extra commands where you have Bash Shell Brace Expansion. rm -f rho_{0..200000..5000}.txt Explanation: {start..end..step}. The -f to ignore prompt on non-existent files. P....
αғsнιη's user avatar
  • 41.6k
48 votes
Accepted

Cannot remove file: "Structure needs cleaning"

That is strongly indicative of file-system corruption. You should unmount, make a sector-level backup of your disk, and then run e2fsck to see what is up. If there is major corruption, you may later ...
DepressedDaniel's user avatar
47 votes
Accepted

Why does rm manual say that we can run it without any argument, when this is not true?

The standard synopsis for the rm utility is specified in the POSIX standard1&2 as rm [-iRr] file... rm -f [-iRr] [file...] In its first form, it does require at least one file operand, but in ...
Kusalananda's user avatar
  • 341k
46 votes
Accepted

How to unlink (remove) the special hardlink "." created for a folder?

It is technically possible to delete ., at least on EXT4 filesystems. If you create a filesystem image in test.img, mount it and create a test folder, then unmount it again, you can edit it using ...
Stephen Kitt's user avatar
40 votes

rm -rf all files and all hidden files without . & .. error

Just realised this is the most convenient way in most Linux distros: ls -A1 | xargs rm -rf where -A = list everything except . and .. -1 = put every item in one line
godzillante's user avatar
40 votes
Accepted

What is :>filename.txt Doing?

As you have discovered, this just empties the file contents (it truncates the file); that is different from rm as rm would actually remove the file altogether. Additionally, :>file.txt will ...
jesse_b's user avatar
  • 38.1k
35 votes

Is `yes | rm -r` safer than `rm -rf`?

Short answer No. However, I really like your creativity of piping commands together. Still, yes|rm -r is a nice example of UUOC (useless use of cat) - an acronym (or better jargon) for command line ...
Lutz Willek's user avatar
35 votes
Accepted

Why doesn't rmdir work recursively?

Unlinking directories was originally a privileged operation: It is also illegal to unlink a directory (except for the super-user). So rmdir was implemented as a small binary which only removed ...
Stephen Kitt's user avatar
32 votes

Make `rm` move to trash

The previous answers mention commands trash-cli and rmtrash. Neither of those are found by default on Ubuntu 18.04, but the command gio is. Commanding gio help trash outputs: Usage: gio trash [...
Teemu Leisti's user avatar
32 votes
Accepted

Since when do the POSIX and GNU rm not delete /?

You can find the HTML version of all the editions of POSIX 2008 online: original: http://pubs.opengroup.org/onlinepubs/9699919799.2008edition/utilities/rm.html TC1 (2013 edition) http://pubs....
Stéphane Chazelas's user avatar
31 votes

Is it possible to determine the progress of an rm command?

I see the question is old. I want to share what it works for me to maybe help some else. I get the progress bar using pv command line Pipe Viewer This is the command rm -rv DIR_OR_FILE_NAME | pv -l ...
Ezequiel's user avatar
  • 311
31 votes
Accepted

Why doesn't find . -delete delete current directory?

The members of findutils aware of it, it's for compatible with *BSD: One of the reasons that we skip deletion of "." is for compatibility with *BSD, where this action originated. The NEWS in ...
林果皞's user avatar
  • 5,236
30 votes
Accepted

How to force creation of a symbolic link?

In GNU's ln, there is ln -n, which would allow re-pointing a symlink: $ mkdir dir1 dir2 $ ln -s dir1 sym # dir1/ # dir2/ # sym -> dir1/ $ ln -nsf dir2 sym # dir1/ # dir2/ # sym -> dir2/ BSD ...
Kenneth B. Jensen's user avatar
30 votes
Accepted

Why doesn't find/rm -iname '*phpmyadmin' delete phpMyAdmin-Version-XYZ.zip?

The problem is that you are matching a file that ends in phpmyadmin (case-insensitively) by using the pattern *phpmyadmin. To get any file that contains the string phpmyadmin (case-insensitively), use ...
heemayl's user avatar
  • 56.8k
29 votes

Deleting billions of files from a directory while seeing the progress as well

Check out lesmana's answer, it's much better than mine — especially the last pv example, which won't take much longer than the original silent rm if you specify /dev/null instead of logfile. Assuming ...
Stephen Kitt's user avatar
28 votes

How to avoid the need to issue "y" several times when removing protected file

rm is hardcoded to ask interactively on write protected files. "interactively" means it will print a question and then wait for user input. there are two methods to prevent rm from asking: ...
Lesmana's user avatar
  • 27.7k
28 votes
Accepted

Debian: cannot remove symlink in /sys/: operation not permitted

The sysfs file system, typically mounted on /sys, just like the /proc file system, isn’t a typical file system, it’s a so called pseudo file system. It’s actually populated by the kernel and you can’t ...
Stephen Kitt's user avatar
27 votes

Unable to remove the $ sign named files using linux?

In alternative to @RomanPerekhrest's answer, this will also work: rm '$commandoutput[0]' as the single quotes will avoid variable expansion. Another way is to start typing rm $ and then hitting ...
dr_'s user avatar
  • 30.4k
27 votes
Accepted

I've copied a directory with `cp -as` and now I'm terrified to `rm -rf` the created directory as it might delete the original

You may remove the directory containing the symbolic links without fear that this would also remove the original files. The POSIX specification for the rm utility says (about what happens when ...
Kusalananda's user avatar
  • 341k
26 votes
Accepted

Is `yes | rm -r` safer than `rm -rf`?

First, as others have already said, yes | rm -r is very similar but not identical to rm -rf. The difference is that the -f option tells rm to continue past various errors. This means that yes | rm -r ...
Dale Hagglund's user avatar
25 votes
Accepted

Is it a good practice to delete all variables at the end of a script?

This is a very bad practice. rm deletes files. It is nothing to do with variables. In any case, the variables themselves will be disposed of when the script ends and the operating system reclaims the ...
Michael Homer's user avatar
24 votes
Accepted

How to exclude some files from filename expansion mechanism in bash?

Since you are using bash: shopt -s extglob echo rm -rf ./!(bin|sbin|usr|...) I recommend to add echo at the beginning of the command line when you are running something what potentially can blow up ...
jimmij's user avatar
  • 47.8k
24 votes

Making alias of rm command

An alias can not take arguments and use $@ to access them like that. Alias expansion in bash is a simple text replacement. If you have alias rm ='something something', then using rm file1 file2 would ...
Kusalananda's user avatar
  • 341k

Only top scored, non community-wiki answers of a minimum length are eligible