What does the bash "rm * ~" command do?

Does the bash rm *~ command only delete files ending in a tilde, or is there a more advanced bash or gnu make pattern here? Google does not seem to be able to find this character combination. I found this in makefile clean: target.

Will gnu create files with trailing ~ using only implicit rules?

+6
syntax bash gnu-make
source share
5 answers

The symbol ~ (tilde) has special meaning in the way in two cases:

 ~user # the home directory of user ~/folder # folder inside your home directory 

For the most part, this is it. The command you refer to does exactly what it looks like: it deletes files whose names end with a tilde. Text editors such as emacs back up files under file names ending in tildes.

So, this command is probably used to delete these backups from the current directory (but not subdirectories). One of the reasons you would like to do this is to copy the directory to the web server, as server code (such as PHP files) may contain sensitive information such as passwords.

+6
source share

As you may have guessed, rm *~ simply deletes a file with names ending with a tilde (~). File names ending with a tilde are usually backup files created by editors (in particular, emacs was one of the earlier editors using this convention). After editing the source code, as a rule, several of these files remain. This is why the clean target in the Makefile removes them.

Whether *~ special bash pattern is not suitable for most makefiles, since / bin / sh is used by default to execute make recipes. Only if SHELL is installed in the makefile will another shell be used.

An easy way to see implicit rules is to run make -p in a directory without a makefile. You will receive an error message indicating unspecified targets, but make will also print the implicit rules that it uses. If you select this output for a tilde, you will see that there are no implicit rules that name files with it.

+4
source share

No, just what you said. Deletes files ending in ~ .

Change β†’ the only special value that the ~ character can have is also short for the user's current home directory (like $HOME ), but only at the beginning of the path.

+2
source share

I used this command to delete files ending in "~". I think there is no special escape character associated with the tilde character.

+1
source share

Yes for both


Actually, both of your possibilities are somewhat true.

There is no wildcard syntax or special file name associated with ~ unless this occurs at the beginning of a word.

But a file name template ending in a tilde is automatically created by mv(1) and cp(1) on most Linux distributions if the -b (backup) option is specified and the target file exists. A make rule on such a system may contain the command mv -b ... or cp -b ...


1. But not on Mac or BSD.

+1
source share

All Articles