Skip to main content
added an explanation about --force being unnecessary
Source Link
Wieland
  • 6.6k
  • 3
  • 29
  • 32

From bash(1):

ALIASES

[... ]The first word of each simple command, if unquoted, is checked to see if it has an alias[...] The characters [...] and any of the shell metacharacters or quoting characters listed above may not appear in an alias name.

So aliases can only be a single word without any quoting characters.

Using both -f and -i in a call to rm also doesn't make much sense because they are somewhat contradictory(rm(1)):

-f, --force ignore nonexistent files and arguments, never prompt

-i prompt before every removal

But here's the good thing - your alias to rm is actually used even when you're calling rm -r, because the first word - rm - has an alias - rm -i, so it gets replaced by that!

$ alias rm
bash: alias: rm: not found
$ alias rm='rm -i'
$ mkdir test
$ rm -r test
rm: remove directory ‘test’?

/edit: Raphael Ahrens also mentioned in the comments that using -f (force) is not neceessary to remove directories (as can be already seen in my example), -r (recursive) enough is alone:

-r, -R, --recursive remove directories and their contents recursively

From bash(1):

ALIASES

[... ]The first word of each simple command, if unquoted, is checked to see if it has an alias[...] The characters [...] and any of the shell metacharacters or quoting characters listed above may not appear in an alias name.

So aliases can only be a single word without any quoting characters.

Using both -f and -i in a call to rm also doesn't make much sense because they are somewhat contradictory(rm(1)):

-f, --force ignore nonexistent files and arguments, never prompt

-i prompt before every removal

But here's the good thing - your alias to rm is actually used even when you're calling rm -r, because the first word - rm - has an alias - rm -i, so it gets replaced by that!

$ alias rm
bash: alias: rm: not found
$ alias rm='rm -i'
$ mkdir test
$ rm -r test
rm: remove directory ‘test’?

From bash(1):

ALIASES

[... ]The first word of each simple command, if unquoted, is checked to see if it has an alias[...] The characters [...] and any of the shell metacharacters or quoting characters listed above may not appear in an alias name.

So aliases can only be a single word without any quoting characters.

Using both -f and -i in a call to rm also doesn't make much sense because they are somewhat contradictory(rm(1)):

-f, --force ignore nonexistent files and arguments, never prompt

-i prompt before every removal

But here's the good thing - your alias to rm is actually used even when you're calling rm -r, because the first word - rm - has an alias - rm -i, so it gets replaced by that!

$ alias rm
bash: alias: rm: not found
$ alias rm='rm -i'
$ mkdir test
$ rm -r test
rm: remove directory ‘test’?

/edit: Raphael Ahrens also mentioned in the comments that using -f (force) is not neceessary to remove directories (as can be already seen in my example), -r (recursive) enough is alone:

-r, -R, --recursive remove directories and their contents recursively

Source Link
Wieland
  • 6.6k
  • 3
  • 29
  • 32

From bash(1):

ALIASES

[... ]The first word of each simple command, if unquoted, is checked to see if it has an alias[...] The characters [...] and any of the shell metacharacters or quoting characters listed above may not appear in an alias name.

So aliases can only be a single word without any quoting characters.

Using both -f and -i in a call to rm also doesn't make much sense because they are somewhat contradictory(rm(1)):

-f, --force ignore nonexistent files and arguments, never prompt

-i prompt before every removal

But here's the good thing - your alias to rm is actually used even when you're calling rm -r, because the first word - rm - has an alias - rm -i, so it gets replaced by that!

$ alias rm
bash: alias: rm: not found
$ alias rm='rm -i'
$ mkdir test
$ rm -r test
rm: remove directory ‘test’?