sudo /usr/bin/dscl . -delete "/Users/ali" will remove the user ali from the local Directory Services database.
After login out you won't be able to login with user ali again. The user folder of ali won't be deleted.
To delete the folder /Users/ali and its content an additional command is necessary.
The user ali can be recreated though by booting to single user mode and using the remove .AppleSetupDone file trick in a two-stage process.
- Create a new admin with a different name than ali (e.g. ali2)
- After the configuration is done create a new admin with a different name than ali (e.g. ali3)
- Logout as ali2 and login as ali3
- Modify ali2 (e.g. name/user directory/user id etc.) with Users & Groups PrefPane/Directory Utility.app/command line to restore the previous entries of ali.
This won't work if your main volume is encrypted with FileVault2!
It's absolutely not recommended to test user creation/deletion scripts like this on your production Mac. Download VirtualBox, create a virtual machine running macOS and test your scripts inside there.