unix - 仅从目录中删除文件

too*_*oop -1 unix bash shell perl solaris

用目录结构说,例如:

toplev/
      file2.txt
      file5.txt
      midlev/
            test.txt
            anotherdirec/
                         other.dat
                         myfile.txt
                         furtherdown/
                                    morefiles.txt
                         otherdirec/
                                    myfile4.txt
                                    file7.txt
Run Code Online (Sandbox Code Playgroud)

你会如何从'anotherdirec'中删除所有文件(不是目录而不是递归)?在这个例子中,它将删除2个文件(other.dat,myfile.txt)

我在'midlev'目录中尝试了下面的命令,但是它给出了这个错误(find: bad option -maxdepth find: [-H | -L] path-list predicate-list):

find anotherdirec/ -type f -maxdepth 1
Run Code Online (Sandbox Code Playgroud)

我正在运行SunOS 5.10.

Rob*_*obᵩ 5

rm anotherdirec/*
Run Code Online (Sandbox Code Playgroud)

应该适合你.

  • 不,没有标志的裸`rm`将不会`rmdir`所以尽管glob`alversdirec/*`将匹配`anotherdirec/futherdown`,`rm`将不会删除它. (2认同)