cat

最後更新: 2022-05-13

目錄

 


用 cat 寫一段字入檔案(HereDoc)

 

"<<"

cat > /etc/apt/sources.list.d/mailscanner.list << EOF
deb http://apt.baruwa.org/debian wheezy main
EOF

"<<" 與 "<<-" 的分別

"<<-" suppresses leading tabs (not spaces)

cat > ~/.vimrc <<-EOL
    set bg=dark
    set modeline
EOL

'EOF'

To prevent the variable from expanding

cat > test.txt <<"EOF"
$var
EOF

 


echo read from stdin

 

i.e.

echo Hello | cat
Hello

 


Show ALL

 

 

-A, --show-all equivalent to -vET

  • -E, --show-ends                   # display $ at end of each line
  • -T, --show-tabs                    # display TAB characters as ^I

-v, --show-nonprinting

Unix endings (\n) show as $

MAC endings (\r) show as ^M (carriage return character(0xD))                # mac2unix

DOS\Windows endings (\r\n) show as ^M$ (less does not appear to show these)

-e     equivalent to -vE

 


cat 的相反

 

tac

 


Combine File

 

cat 1.txt 2.txt 3.txt > result.txt

result.txt

1
2
2

 

 


Output download to stdout

 

# 如果不使用 "-q" 會有 wget 的 info

wget -q server/ip.php -O - | cat

 


 

 

 

 

Creative Commons license icon Creative Commons license icon