https://linux.cn/article-8024-1.html#comment


  1. 通过重定向到不存在的事物到文件中

    > a.txt

  2. 使用true命令来重定向到文件

    true > a.txt 或者:>a.txt

    等同于shell,内置命令,true不进行任何操作,即true的输出结果为空重定向到a.txt

  3. dd,cp,cat 命令结合/dev/null

    cp /dev/null a.txt

    dd if=/dev/null of=a.txt

    cat /dev/null > a.txt

  4. 使用echo命令

    echo abc > a.txt 为4个字节,默认会添加个\n

    echo -n  >  a.txt

  5. truncate命令

     truncate -s 0 a.txt