dos2unix

将dos格式的文件转成unix格式

查询脚本的格式

  1. find . -name "*.sh" | xargs file
  2. ./disable_user_log_to_messages_for_centos.sh: Bourne-Again shell script, ASCII text executable
  3. ./distributions/centos/7/after_mdatacenter.sh: Bourne-Again shell script, ASCII text executable, with CRLF line terminators
  4. ./distributions/centos/7/after_xsom.sh: Bourne-Again shell script, ASCII text executable, with CRLF line terminators
  5. ./distributions/centos/7/influx.sh: Bourne-Again shell script, ASCII text executable
  6. ./distributions/centos/7/jdk.sh: Bourne-Again shell script, ASCII text executable
  7. ./distributions/centos/7/mongo.sh: Bourne-Again shell script, ASCII text executable
  8. ./distributions/centos/7/mssql.sh: Bourne-Again shell script, ASCII text executable
  9. ./distributions/kylin/3/after_mdatacenter.sh: Bourne-Again shell script, ASCII text executable, with CRLF line terminators
  10. ./distributions/kylin/3/after_xsom.sh: Bourne-Again shell script, ASCII text executable, with CRLF line terminators
  11. # with CRLF line terminators 表示是dos格式,没有表示是unix

将dos格式转成unix

单个文件

  1. dos2unix file

所有.sh文件

  1. find . -name "*.sh" | xargs dos2unix

指定类型且是dos格式的才转换

  1. find . -name "*.sh" | xargs file | grep CRLF | cut -d":" -f1 | xargs dos2unix

补充:编辑文件直接修改文件的格式

  1. vim file
  2. :set ff=unix

unix2dos

用法和dos2unix一样,是将unix格式转成dos格式