我有一个包含文件列表的目录。所有这些文件的名称中都有空格。
我想为每个文件创建一个目录,文件名除了扩展名(对于所有文件都是 .doc)。
例如:
我的目录内容
first file.doc
second file.doc
third file.doc
Run Code Online (Sandbox Code Playgroud)
预期结果
first file/first file.doc
second file/second file.doc
third file/third file.doc
Run Code Online (Sandbox Code Playgroud)
我有这个命令来知道我必须创建的目录名:
find . -maxdepth 1 -name "*.doc" | awk -F ".doc" '{print $1}'
Run Code Online (Sandbox Code Playgroud)
有了这个,结果是:
first file
second file
third file
Run Code Online (Sandbox Code Playgroud)
我知道需要为每个条目创建一个目录。
我尝试了以下方法但没有成功:
find . -maxdepth 1 -name "*.doc" | awk -F ".doc" '{print $1}' -exec mkdir '{}' \;
#error with awk: it cannot open the file -exec because it does not exist
mkdir `find . -maxdepth 1 -name "*.doc" …
Run Code Online (Sandbox Code Playgroud)