简体   繁体   English

在Mac中递归选择文件-需要整理目录中的所有文件

[英]Recursively select file in mac - need to prettier all files in directory

I am following this medium post . 我正在关注这篇中等职位

Running the command prettier --write ./src/**/*.{js,jsx,scss} works perfectly fine on windows machine. 在Windows机器上运行命令prettier --write ./src/**/*.{js,jsx,scss}可以很好地工作。

However, when using Mac machine, this command doesn't go recursively on files that present on sub-folders. 但是,在使用Mac计算机时,该命令不会递归地存在于子文件夹中的文件上。

What is the difference between windows and mac on this? Windows和Mac之间有什么区别?

You could use find with -exec, like so 您可以将find与-exec一起使用,就像这样

find src -iname \*.js -or -iname \*.jsx -exec prettier --write {} \;

The arguments: 参数:

  • src: the directory (be careful to not run on .git, node_modules, etc src:目录(请注意不要在.git,node_modules等上运行
  • -iname: case insensitive name -iname:不区分大小写的名称
  • -or: or, to chain options together, in this case iname -or:或者,将选项链接在一起,在这种情况下为iname
  • -exec: execute the following command for every item found. -exec:对找到的每个项目执行以下命令。 It replaces {} with the item found. 它将{}替换为找到的项目。 Exec needs \\; 执行需要 at the end to know when your command is over. 最后知道命令何时结束。

Before you execute it, you could prepend echo to preview what commands will be running, like so 在执行之前,您可以在echo之前添加预览以预览将要运行的命令,如下所示

find src -iname \*.js -or -iname \*.jsx -exec echo prettier --write {} \;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 递归输出目录中某些类型的所有文件的文件大小? - Output file size for all files of certain type in directory recursively? 如何递归删除目录中所有文件中的插入符号(^)字符? - How to recursively remove the caret (^) character recursively in all files in a directory? 将目录中的所有文件建立符号链接(递归)到其他目录 - Make symlinks for all files in directory (recursively) into other directory 递归列出目录中的所有文件,包括符号链接目录中的文件 - Recursively list all files in a directory including files in symlink directories 递归删除所有文件,每个目录中除特定数目的文件 - Recursively delete all files except a certain number in each directory 如何递归获取目录下所有文件的总大小 - How to get total size of all files recursively under directory 如何从目录中递归找到的所有文件中搜索行匹配 - how to search for a line match from all files recursively found in a directory 将Linux命令递归应用于单一(.sh)类型目录中的所有文件 - Apply Linux command recursively to all files in directory of single (.sh) type 如何按文件类型递归查找文件并将它们复制到目录? - How to find files recursively by file type and copy them to a directory? 递归查找目录中的文件数 - Recursively find the number of files in a directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM