Using the standard Linux command
rm to delete multiple files on a Lustre filesystem is not recommended. The
rm command will generate a
stat() operation on for each file it removes, meaning all of the attributes of a file (filetype, owner, permission, modification time, etc.) will be returned from the metadata server. A large number of
stat() operations can place an increased load on the metadata server, resulting in lower performance and instabilities with the filesystem.
munlink, a Lustre-specific command that will simply delete a file without performing a stat() operation. Below is an example of how to remove files using our recommended approach which consists of two steps.
The first step deletes all the files and soft links within a directory (and its subdirectories) with the use of
find -P ./processor0 -type f -print0 -o -type l -print0 | xargs -0 munlink
Here is an overview of each step in that command:
is a command that will search the indicated directory (and subdirectories within). The syntax defines a search for files (or and soft links).
restricts the search within the indicated directory tree and forces NO dereference of symbolic links. This warranties that the find command will not look for files within the links.
is the directory to be deletedfrom which the search will start
-type f -print0 -o -type l -print0
The This indicates that the find command will search the directory processor0 and all subdirectories for anything that is a file (
-type f) or (
-o) a soft link (
-type l), therefore omitting to directories (-type d, this is the lower letter
This dictates how the returned list of files is formatted (indicates the format of the result of the "
find" command. This particular format is able to catch strange file names), and ensures that they are in the correct format readable for the next step (
xargs-0). It needs to appear twice due to the "or" command option (
-o) explained in the previous bullet point.
The list of files or links found by the find command is piped to the xargs commandPipe command ( represented by a single pipe line:
|) makes the output of "
find" to serve as input to the next command (
xargsin this case).
xargswill then convert the received list of files, line by line, into an argument for whatever command is specified at the end (in our this case:
-0flag is related to the format of the listed files; if you use
findcommand you must use
deletes each file and soft link in the list without overloading the metadata server
The second step is to remove the empty directories and subdirectories in the tree. Once all of the files are and soft links were deleted, you can remove the empty directories with a similar command:
find ./processor0 -depth -type d -empty -delete
find command will search the directory
processor0 and all subdirectories for any empty directories (
-type d -empty) and delete them. The depth flag instructs find to process each directory's contents before the directory itself, then the most distant branches in the directory tree will be procesed first. The -
delete action also implies
-depth. To process a directory' contents before the directory itself. Please note that the flags passed to
find are evaluated as an expression, so if you pass
find will attempt to delete below your starting directory.NOTE:
We strongly recommend that all OpenFOAM users make use of
|Content by Label|