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

refs

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

HereDoc

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



©xgqfrms 2012-2025

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

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


posted @   xgqfrms  阅读(521)  评论(1编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-08-09 GitHub Actions
2019-08-09 Chrome 76 & DevTools
2018-08-09 cookie & maxAge & expires
2016-08-09 web性能优化:javascript 实现Async 异步加载js 代码的多种方法汇总!
点击右上角即可分享
微信分享提示