Tag Info

Hot answers tagged

159

sudo touch /bin/rm && sudo chmod +x /bin/rm apt-get download coreutils sudo dpkg --unpack coreutils* And never again. Why didn't you used sudo with apt-get? Because the download command doesn't require it: download download will download the given binary package into the current directory. So, unless you are ...


91

debian and its derivatives (and probably most other distributions) come with busybox which is used in the initramfs. busybox bundles most core command line utilities in a single executable. You can temporarily symlink /bin/rm to /bin/busybox: ln -s busybox /bin/rm To get a working rm (after which you can do your apt-get install --reinstall coreutils). ...


77

Use "--" to make rm stop parsing command line options, like this: rm -- --help


49

All rm needs is write permission on the parent directory. The permissions of the file itself are irrelevant. Here's a reference which explains the permissions model more clearly than I ever could: Any attempt to access a file's data requires read permission. Any attempt to modify a file's data requires write permission. Any attempt to execute a ...


43

The correct syntax in bash is the following: rm /tmp/!(lost+found) As @goldilocks wrote in the comments, the original command makes an expansion on the query (it deletes all the files in the /tmp folder, then goes on, and deletes all the files in the current working folder, in your case the home folder). You can try to check if you can recover some of ...


37

I would advise against immediately installing some utility. Basically your biggest enemy here are disk writes. You want to avoid them at all costs right now. Your best bet is an auto-backup created by your editor--if it exists. If not, I would try the following trick using grep if you remember some unique string in your .tex file: $sudo grep -i -a -B100 ...


34

Nowhere, gone, vanished. Well, more specifically, the file gets unlinked. The data is still sitting there on disk, but the link to it is removed. It used to be possible to retrieve the data, but nowadays the metadata is cleared and nothings recoverable. There is no Trash can for rm, nor should there be. If you need a Trash can, you should use a ...


33

The latest (as of 2013) version of the POSIX spec for the rm utility is here (and the previous one there) and forbids the deletion of . and ... If either of the files dot or dot-dot are specified as the basename portion of an operand (that is, the final pathname component) or if an operand resolves to the root directory, rm shall write a diagnostic ...


32

Ok, according to your comment to ire_and_curses, what you really want to do is make some files immutable. You can do that with the chattr command. For example: e.g. $ cd /tmp $ touch immutable-file $ sudo chattr +i immutable-file $ rm -f immutable-file rm: remove write-protected regular empty file `immutable-file'? y rm: cannot remove `immutable-file': ...


28

Say you want to run: rm *.txt You can just run: echo rm *.txt or even just: echo *.txt to see what files rm would delete, because it's the shell expanding the *.txt, not rm. The only time this won't help you is for rm -r. If you want to remove files and directories recursively, then you could use find instead of rm -r, e.g. find . -name "*.txt" ...


26

rm /* should delete very little. There is no -r flag in there that would recursively delete anything, and without it directories will not be deleted (and even if directories were deleted, only empty ones can be deleted). This answer is predicated on the assumption that you did not run rm -rf /*. The only files in the root filesystem of consequence may be ...


26

The file has a name, but it's made of non-printable characters. If you use bash, you can try to remove it by specifying its non-printable name. First ensure that the name is right with: ls -l $'\177' If it shows the right file, then use rm: rm $'\177' Another (a bit more risky) approach is to use rm -i -- * . With the -i option rm requires confirmation ...


25

Someone on Twitter suggested using -delete instead of -exec rm -f{} \; This has improved the efficiency of the command, it still uses recursion to go through everything though.


25

rm -r works on each of its arguments in turn. If an argument is a directory, it lists the directory (with the opendir and readdir functions or some equivalent method), and operates on each entry in turn. If an entry is a directory, it explores that entry recursively. This is exactly the same method that other applications use to traverse directories ...


25

The !(lost+found) in your rm command was probably the fatal mistake: 1978 rm -rf /tmp/* !(lost+found) 1979 sudo rm -rf /tmp/* !(lost+found) I don't know exactly what bash is doing with that, but this command below prints everything in my /tmp/ and also everything my current directory (which is currently ~): echo /tmp/* !(lost+found)


23

List the directories deeply-nested-first. find . -depth -type d -exec rmdir {} \; 2>/dev/null (Note that the redirection applies to the find command as a whole, not just to rmdir. Redirecting only for rmdir would cause a significant slowdown as you'd need to invoke an intermediate shell.) You can avoid running rmdir on non-empty directories by passing ...


21

(I dislike intruding users' home, I think they should be allowed to do whatever they want to do with they homes… but anyway…) This should work on linux (at least). I'm assuming user is already a member of the group user. A solution is to change ownership of Directory1 and set the sticky bit on the directory: chown root:user Directory1 chmod 1775 Directory1 ...


21

Make the file immutable with the i attribute. chattr +i file.desktop see man chattr for more information.


21

find is very useful for selectively performing actions on a whole tree. find . -type f -name ".Apple*" -delete Here, the -type f makes sure it's a file, not a directory, and may not be exactly what you want since it will also skip symlinks, sockets and other things. You can use ! -type d, which literally means not directories, but then you might also ...


20

It's basically removing backup files. *~ means all files ending in ~. Many Unix/Linux systems programs create backup files that end in ~. For example, the emacs and nano editors automatically save a backup copy of each file you edit. When it saves a file, the old version gets saved using the file name with a tilde (~) added to the end. Vim will do the ...


20

Unless your "friend" is the NSA, tools that do lots of random or pattern overwriting (as DBAN which others are recommending does) are overkill - dd if=/dev/zero of=[your disk... make sure you get it right] bs=10M will erase it so that it can't be recovered without taking the disk apart and scanning the platters with special hardware. If you use /dev/urandom ...


20

You can use the -delete flag of find (first test with -ls) find -not -name "*.c" -delete If you do not want to use find, but only files in the current directory, you could do rm !(*.c) Make sure in bash that with shopt -s extglob the correct globbing is set. Additionally, if you have globstar set (shopt -s globstar), you can act recursively (for bash ...


20

It sounds like you've got a decent grasp on what happened. Yes, because you hard-powered-off the system before your changes were committed to disk, they were there when you booted back up. The system caches all writes before flushing them out to disk. There are several options which control this behavior, all located at /proc/sys/vm/dirty_* [kernel doc]. ...


19

The following command will do it for you. Use caution though. rm -rf directoryname


19

The GNU version of find supports the -empty test: ~$ find . -type d -empty -delete Use -type d to tell find you're interested in directories only (and not files). Perhaps you should run the command without -delete first, so you can check what will be deleted.


19

This is not a part of rm, but a part of your shell. * is a glob which your shell expands and passes to rm in the form of arguments (rm never sees a literal *, unless the glob didn't match anything, in which case a literal * is passed). Standard * globs do not expand to include filenames beginning with a dot, which includes . and ... For example: $ tee foo ...


18

If you need to recover files from the current install, ask your host to help you. Assuming it's a VM, it takes about five minutes of their day to image your disk, reinstall your host from scratch and dump the old disk image in your new filesystem. If you don't need anything, just get them to reinstall. Almost always the faster option when you bone things ...


18

You could use rm -i to be prompted for every single file it will remove. You can pipe no into it repeatedly, (confusingly) using the yes command, to just view prompts (rejecting all of them): yes no | rm -i files/globs/options EDIT in response to comments by @user63051 If you are concerned about dangerous flag combinations, you can specify rm -i -- and ...



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