xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Linux shell command create file methods All In One

Linux shell command create file methods All In One

touch, cat, echo, EOF

touch

$ touch file.py

$ touch file1.txt file2.txt file3.txt

$ > empty_file.md

cat

$ cat > file.md

HereDoc

EOF 多行注释

# EOF 多行注释
$ cat << EOF > file1.txt
Some line
Some other line
EOF

linux shell block comments / linux shell multi lines comments

https://stackoverflow.com/a/76127090/5934465

Here documents & Here strings

https://bash.cyberciti.biz/guide/Here_documents

https://bash.cyberciti.biz/guide/Here_strings

echo

$ echo "Some lines" > file.md

$ echo file.md

EOF

$ cat > test.py <<EOF
# coding: utf8

__author__ = 'xgqfrms'
__editor__ = 'vscode'
__version__ = '1.0.1'
__copyright__ = """
  Copyright (c) 2012-2050, xgqfrms; mailto:xgqfrms@xgqfrms.xyz
"""
EOF

image

$ cat <<'EOF' >> brightup.sh
#!/bin/bash
curr=`cat /sys/class/backlight/intel_backlight/actual_brightness`
if [ $curr -lt 4477 ]; then
   curr=$((curr+406));
   echo $curr  > /sys/class/backlight/intel_backlight/brightness;
fi
EOF

https://stackoverflow.com/questions/22697688/how-to-cat-eof-a-file-containing-code/22698106#22698106

https://stackoverflow.com/questions/22697688/how-to-cat-eof-a-file-containing-code/76127396#76127396

echo \n 换行 & EOF 多行注释 All In One


#!/bin/bash

# echo \n ❌
# echo "sed test\n"

# echo -e \n ✅
echo -e "sed test\n"

# echo $"双引号 ❌"
# echo $"sed test\n"

# echo $'单引号 ✅'
echo $'sed test\n'

printf "sed test\nabc xyz\n\n"

printf "sed test\nabc xyz"
# sed test
# abc xyz%
# printf % bug ❓zsh bug

# multi lines comments `<<EOF` & `EOF`

# multi_lines_comments = <<EOF

<<EOF

The \`%\` is not printed by \`printf\`, it's printed by \`zsh\` as part of its command prompt.

Bash uses \`$\` or something more complicated instead, that's why it looks different with bash.

\`printf\` prints the same thing both times, and following that the shell prints it's command prompt.

This command prompt looks different in \`zsh\` than in \`bash/sh\`.

https://stackoverflow.com/questions/8467424/echo-newline-in-bash-prints-literal-n

EOF

# echo "$multi_lines_comments"

dd

$ dd if=/dev/zero of=1G.test bs=1 count=0 seek=1G

fallocate

$ fallocate -l 1G 1G.test

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs

https://linuxize.com/post/create-a-file-in-linux/

HereDoc

https://phoenixnap.com/kb/bash-heredoc



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2020-08-09 12:42  xgqfrms  阅读(490)  评论(1编辑  收藏  举报