Synopsis edit
- file delete ?-force? ?--? pathname ?pathname ...?
Description edit
file delete removes the file or directory specified by each pathname. With -force, even non-empty directories are removed. When pathname is a symbolic link, that symbolic link is removed rather than the file it refers to. If pathname is a non-existent file, nothing is done and it is not an error. Arguments are processed in the order specified, halting at the first error, if any. -- marks the end of options; each subsequent argument is treated as a pathname, even if it begins with -.If pathname is a file for which the user does not have write permissions, and the filesystem permits deleting it, it is deleted even if -force is not specified.If pathname is a directory and -force is specified, permissions on the directory are changed to allow deletion of its contents, and if needed, current directory is changed out of the directory. For example, to delete the current directory:file delete -force [pwd]
To delete all files in the current directory ending in orig:
file delete {*}[glob *.orig]Since TIP #323: Do Nothing Gracefully, file delete accepts no arguments and in that case does nothing. To delete any files in the current directory ending in .orig, allowing for the possibility that no such files might exist:
file delete {*}[glob -nocomplain -*.orig]
Deleting a Directory That Isn't Empty edit
To delete a directory, but only if it is empty:file delete $pathnameTo delete a directory along with everything in that directory, recursively:
file delete -force -- $pathname