2

I, by mistake, have created a new project directory with cargo new communicator --bin, instead of cargo new communicator --lib.

Then, I tried to remove the entire directory with rmdir --ignore-fail-on-non-empty communicator. This command doesn't generate an error in the next line, but when I look to see if it's removed it's still there!

I wonder why I cannot remove a project directory in this fashion.

I tried both on Atom's Terminal Window and MX Linux Xfce Terminal, but the same result... Also, just in case I performed the same rmdir command as a root, but in vain.

Am I fundamentally doing something wrong here?

Ishan Jain
  • 665
  • 6
  • 20
Julia O
  • 221
  • 2
  • 13
  • Cargo does not do anything special when creating a directory. It’s just a regular Git (by default) repository with a `Cargo.toml` file. – mcarton Mar 12 '19 at 08:37

2 Answers2

3

The flag --ignore-fail-on-non-empty doesn't mean that rmdir goes ahead and removes the directory. It simply silences the error. Instead, you can use rm -r communicator.

SCappella
  • 9,534
  • 1
  • 26
  • 35
2

Cargo doesn't do anything "special" with the project folder. If you accidentally created a --bin project instead of a library, You can

  1. Delete the communicator bin project with rm -rf communicator where r is for recursive and f is to force remove(in case folder is not empty).

  2. Delete communicator/src/main.rs and create communicator/src/lib.rs.

The second option has the same effect as deleting the --bin project and creating a library.

Ishan Jain
  • 665
  • 6
  • 20
  • 3
    You don't need `-f` and you should not use it! This is very error prone and can delete important files in a unfortunate circumstances. – hellow Mar 15 '19 at 12:30