Hot answers tagged


If you have rm from GNU coreutils (most probably if it's a regular Linux distro), rm -rf / will be refused by the built-in protection (according to manpage and Wikipedia, haven't tried that). You can override this protection with --no-preserve-root. rm will then remove everything it possibly can, without stopping after having attempted to remove every ...


To rm all but u,p in bash just type: rm !(u|p) This requires the following option to be set: shopt -s extglob See more: glob - Greg's Wiki


In general there is no easy way back. You could restore from your daily backup.


The -f option is definitely what you want to be using. The confirmation about file permissions it refers to is this: $ touch myfile $ chmod 400 myfile $ rm myfile rm: remove write-protected regular empty file `myfile'? So rm will warn you if you try to delete a file you don't have write permissions on. This is allowed if you have write ...


What I do in those cases is to type rm * Then I press Ctrl+X,* to expand * into all visible file names. Then I can just remove the two files I like to keep from the list and finally execute the command line.


Others (such as @RiMMER, @Adam, and @James T) have mentioned that, for most filesystems, it's possible to recover most or all of your data (perhaps without filenames), because the data is not actually zeroed out, only removed from the file-table. This is not just true of Linux - the same is true of Windows and Mac. However, no one has mentioned the most ...


You can use find find . ! -name u ! -name p -maxdepth 1 -type f -delete ! negates the next expression -name specifies a filename -maxdepth 1 will make find process the specified directory only (find by default traverses directories) -type f will process only files (and not for example directories) -delete will delete the files You can then tune the ...


There is no way to a totally bulletproof a system. And adding "Are you sure?" prompts to things is both counterproductive and leads to "Of course I'm sure." kneejerk reactions. A trick I picked up from a book in years past is to first do ls -R blah* then, do rm -fr blah* if and only if the listing that ls turned up hit what I wanted hit. It's easy ...


Use rm \\ (escape the backslash with another backslash). Note that this also works similarily, for directories named \ (using either rmdir, or rm with the -r flag). Example: >mkdir demo >cd demo >touch \\ >ls -l total 0 -rw------- 1 hennes users 0 Jul 29 20:25 \ >rm \\ >ls -l total 0


I'm way late to the party, but I use this all the time. In a makefile, add - to the beginning of a line to ignore the return value of that line. Like so: -rm interpparse.mli


rm -- -d -- means "end of options". Anything further on the command line following this is interpreted as an argument (i.e. the file name in your case), and not an option.


Simple: mv the files you want in a upper directory, rm the directory and then mv them back.


For those who like to do stuff like this visually while listening to techno music. Running rm- rf on Linux (video) Bonus points if you can name the processes as they start dying.


The following are generic steps to recover text files. First use wall command to tell user that system is going down in a single user mode: # wall System is going down to .... please save your work. Press CTRL+D to send message. Next use init 1 command to take system to a single user mode: # init 1 Using grep (traditional UNIX way) to recover files ...


To remove one file you need write permission on the directory that contains¹ this file. Here the permissions are dr-xr-xr-x 3 rayell pg1083760 4096 2010-10-10 10:00 . So nobody (other than root) can remove files inside this directory. The owner must use chmod first. — 1. There are pretty good reasons for that. By ‘removing’ a file with rm, you are in fact ...


The commands you ran do the following things, none of which is even remotely connected to creating a swap partition: Switch to root (su) Delete everything in the /boot folder (rm -rf /boot). This is where all the files needed to boot your OS are kept. Including the kernel. Remove all the basic system commands (rm -rf /bin). Now things like bash,rm,ls,mkdir,...


Quicker is not necessarily what you want. You may want to actually run slower, so the deletion chews up fewer resources while it's running. Use nice(1) to lower the priority of a command. nice find . -name "*.gif" -delete For I/O-bound processes nice(1) might not be sufficient. The Linux scheduler does take I/O into account, not just CPU, but you may ...


A DEBUG trap could be written to cancel commands that look suspicious. The following, or code similar to it, can be added to your ~/.bashrc: shopt -s extdebug checkcommand() { if [[ $BASH_COMMAND = 'rm -r'*' *' ]]; then echo "Suppressing rm -r command ending in a wildcard" >&2 return 1 fi # check for other commands here, if you like ...


To directly answer your question, "no - you can't do what you describe with rm". You can, however, do it you combine it with find. Here's one of many ways you could do that: # search for everything in this tree, search for the file pattern, pipe to rm find . | grep <pattern> | xargs rm For example, if you want to nuke all *~ files, you could so ...


Example 1: Deleting a directory containing a soft link to another directory. susam@nifty:~/so$ mkdir foo bar susam@nifty:~/so$ touch bar/a.txt susam@nifty:~/so$ ln -s /home/susam/so/bar/ foo/baz susam@nifty:~/so$ tree . ├── bar │   └── a.txt └── foo └── baz -> /home/susam/so/bar/ 3 directories, 1 file susam@nifty:~/so$ rm -r foo susam@nifty:~/so$ ...


You're right. It's bad because you get used to it. If you're on a system that doesn't have it, and you rm, it immediately starts deleting and you're wondering what's going on. Many users are used to SSH'ing into different systems; so using lots of different systems, sometimes without personalized user accounts (including aliases) set up, is rather common. ...


rm ./-d is the answer to your question.


On ubuntu or similar: $ sudo apt-get install trash-cli $ alias rm=trash Then put that alias in .bashrc or the appropriate login script for your shell of choice. The trash-cli package is a command-line interface to the same trash can that GNOME and KDE and other use. So anything you delete via the trash command can be restored by GNOME/KDE and vice-versa. ...


If you want a customized rm, don't call it rm but a name of yours, myrm, delete or whatever. The rm='rm -i' alias is an horror because after a while using it, you will expect rm to prompt you by default before removing files. Of course, one day you'll run it with an account that hasn't that alias set and before you understand what's going on, it is too late....


Another solution is this one: Just add an OR-statement after your command: rm -rf my/dir || true This way, when statement #1 fails (throws error), run statement #2, which is simply true.


Set up a VM and try for fun? It'll go quite far... if you're using a gui you might have fun noticing things degrade more visibly. (icons on menus stop loading etc.) If you let it go, the OS will pretty much be beyond recovery though you may be able to get some data back easily. Either way, you'll be wanting to do a reinstall of the OS.


Or using find: find your-directory/ -name 'A*[0-9][0-9]' -delete This solution will deal with weird file names.


ls * | grep -v dont_delete_this_file | xargs rm -rf Example : mkdir test && cd test touch test1 touch test2 touch test3 touch test4 touch test5 To remove all files except 'test2' : ls * | grep -v test2 | xargs rm -rf Then 'ls' output is : test2 EDIT: Thanks for the comment. If the directory contains some files with spaces : mkdir test &...


Short version: rm *\([1-9]\)* Do not pipe ls to xargs. Instead, pipe find ... -print0 to xargs -0, in order to avoid such problems. find . -maxdepth 1 -name '*([1-9])*' -print0 | xargs -0 rm ...which can be written as: find . -maxdepth 1 -name '*([1-9])*' -exec rm {} \; and: find . -maxdepth 1 -name '*([1-9])*' -delete which can further be ...

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