# Tag Info

## New answers tagged rm

5

Ultimately, no matter what you do, rm has to run unlink on every single file that you want to remove (even if you call rm -r on the parent directory). If there are a lot of files to remove, this can take a long time. There are two particularly time consuming processes when you run rm -r -- readdir, followed by a number of calls to unlink. Finding all the ...

6

Don't forget the possibility that the server being unreachable after the rm command had nothing to do with that. It could be a coincidence! Most likely though, the current working directory was not what you thought, when the command was issued. Were you root when doing this? This is what happens when issuing the command rm -rf *: The shell resolves the ...

-1

I have created a script to make this task easier. The shell script modifies the read/write permission and chattr flag of a given list of folders interactively, without asking root password. You can download the zip file from the link given below. https://drive.google.com/file/d/0B_3UYBZy2FVsMVpBSWdSWnFBYk0/edit?usp=sharing I have also included installation ...

0

First approach is, using -f option for rm command: rm -rf /your/path Second approach is, yes | rm -r /your/path First approach used more for your purpose and second approach used more for copy or moving files.

-1

One way to delete files that don't belong to you is to do it as root. sudo rm -R /path/to/dir This overcomes most permissions that cause the override prompt. There can still be times when permissions are set to prevent root accidentally deleting files at which time preceding the rm command with sudo chmod -R 777 /path/to/dir can be helpful. Remember that ...

0

Use the -f flag to rm rm -rf /path/dir This wont ask you any questions, anything that you can delete will be deleted.

5

You want to traverse a directory tree and see if it contains anything other than a directory. This is beyond rm's capabilities. You need other tools such as find. You can delete the empty directories under a given directory this way (-depth causes parent directories that become empty to be deleted as well): find "$x" -depth -type d -exec rmdir {} + Here ... 0 The rm in most Linux distros, and I think Cygwin as well, comes from GNU Coreutils. In my OS, and probably Cygwin, there is a package simply called coreutils that contains all of these programs. 2 rm is part of coreutils. So re-install that. Cygwin doesn't have a fully-featured package manager, but you should be able to rerun setup*.exe (i.e. the original installer - it remembers your packages) to re-select coreutils. 1 find myfile -depth -exec sh -c 'for f do rm -rf -- "$f" && printf "Removed ‘%s’\n" "$f" done' sh {} + Or: find myfile -depth -exec rm -rf -- {} \; \ -exec printf "Removed ‘%s’\n" {} \; could be a start. If you have access to GNU find, possibly as gfind or as /opt/gnu/bin/find: gfind myfile -delete -printf 'Removed ... 0 The feature you're looking for is autocompletion. Type the first few characters of the file name on the shell command line and press Tab. The file name is automatically completed if the prefix that you typed is unambiguous. If there is an ambiguity, the shell will at least complete up to the point where there are multiple possibilities. For example, if ... 4 That's what shell globs are for (among other things): echo some_file_1* Note that I'm using echo instead of rm deliberately. When you are satisfied your glob has matched exactly the file(s) you wish to remove, you can then replace echo with rm. -2 since @terdon missed the -r flag: #!/bin/bash vrrm(){ for f in "$@"; do if [ -d "$f" ]; then gfind "$f" -type f -print0|tee >(gxargs -0 rm) |gxargs -0 echo -- removing file gfind "$f" -depth -type d -print0|tee >(gxargs -0 rmdir)|gxargs -0 echo -- removing directory else rm "$f" && echo ...

1

Make rm into a function by adding this to your shell's initialization file (assuming Bourne-like syntax): vrm() { for f do rm -- "$f" && printf 'Deleted %s\n' "$f" done } You can then call it as vrm foo bar baz.

0

To delete all files and directories(including the hidden ones) in a directory, you can try the following: delete the folder, then recreate it \rm -rf dir_name && mkdir dir_name in Bash, shopt -s dotglob \rm -rf dir_name/*

Top 50 recent answers are included