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 ...
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 ...
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 ...
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 ...
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 ...
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 "{}"
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 ...
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....
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 ...
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 ...
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 ...
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
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 ...
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 ...
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 ...
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 [...
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....
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 ...
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 ...
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 ...
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 ...
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 ...
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:
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
rm × 841files × 149
bash × 133
linux × 132
find × 123
directory × 102
shell × 82
permissions × 67
shell-script × 60
command-line × 60
filenames × 37
wildcards × 34
delete × 33
macos × 32
filesystems × 29
data-recovery × 23
symlink × 21
ubuntu × 20
date × 19
grep × 18
recursive × 18
mv × 15
ls × 14
xargs × 13
command × 12