Tag Info

Hot answers tagged

139

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 ...


76

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). ...


40

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 ...


32

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 ...


31

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 ...


25

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" ...


25

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

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': ...


25

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 ...


23

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 ...


23

In case apt-get or dpkg needs rm and without rm a reinstallation is not posssible, then you can emulate rm with perl: cat > /bin/rm << "EOF" #!/usr/bin/perl foreach (@ARGV) { unlink $_ or warn "$@:$!"; } EOF chmod +x /bin/rm


19

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 ...


19

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 ...


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

(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 ...


17

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 ...


17

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 ...


17

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 ...


17

You can find the answers in the The FreeDesktop.org Trash specification: Some excerpts: $topdir/.Trash-$uid directory is to be used as the user's trash directory for this device/partition. $uid is the user's numeric identifier. The $trash/files directory contains the files and directories that were trashed. The $trash/info directory contains ...


17

rm -i reads its answer from standard input, which it inherits from the while loop. So a line of text from list.txt is being used as the answer to the "really remove?" question. To fix, you'll need to separate the two sources of input. The easiest way is to have read take its input from a separate file descriptor: while IFS= read <&3 -r i; do rm -i ...


17

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 ...


17

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 ...


16

It isn't deleting them because it recognises the filenames as arguments (unquoted, in this situation * expands to -f -i ize). To delete these files, either do rm -- *, or rm ./*. -- signifies the end of arguments, ./ uses the link to the current directory to circumvent rm's argument detection. Generally ./* is preferable, as some programs do not accept -- ...


16

If you start at the very top, it's possible that you'll wipe out something that rm (or some other critical part of the system) needs to continue, and the evilness will be left incomplete. These commands will make sure that at least the cwd and the user's home directory are gone before going nuclear.


15

This command does nothing, at least on the OS I use (Solaris) with which this security feature was first implemented: # rm -rf / rm of / is not allowed On other *nix, especially the Linux family, if a recent enough Gnu rm is provided, you would need to add the --no-preserve-root option to enable the command to complete (or at least start). How far would ...


14

You are removing a file with an & character in the name, and the rm command is being put in the background. (For the record, the 1 is the job number, and the 12345 is the process ID) It is important to quote or escape any filenames that contain special characters. A good rule of thumb is: if you think something might be a special character, it can't ...


13

To avoid a mistaken rm -rf, do not type rm -rf. If you need to delete a directory tree, I recommend the following workflow: If necessary, change to the parent of the directory you want to delete. mv directory-to-delete DELETE Explore DELETE and check that it is indeed what you wanted to delete rm -rf DELETE Never call rm -rf with an argument other than ...


12

The answers of Vegar Nilsen and edfuh are very good and the proper solutions to a problem like this. I do want to add a general response to this question that allows you to delete any file with a difficult file name. First its inode number is obtained using ls -i or some form of stat and then the file is removed by searching for files in the current ...


12

It is possible, its just going to be a hassle. UPDATE: before you try this method, please have a look at Steven's answer You're going to need the testdisk package, a lot of disk space and a lot of time. PhotoRec, a part of TestDisk, can recover files from almost any disc. PhotoRec does support finding .tex files First, install testdisk by running ...



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