[英]linux cat command with multiple binary files
我正在嘗試熟悉 Linux 中命令 shell 上的cat
命令。 運行以下幾行只會產生意想不到的(至少對我而言)結果:
cp /bin/ls file1
cat file1 file1 file1 > ls3
chmod u+x ls3
./ls3
我預計整個目錄將被打印 3 次,但結果是我只打印了一次整個目錄。 這是什么原因? 我以為linux中的二進制文件和文本文件沒有區別,不知何故文件只寫了一次?
如果有人能為這些基本命令和管道提供有用的資源/指南,我真的很喜歡它,因為基本命令從未像我剛才所做的那樣涵蓋任何內容。
謝謝。
讓我給你一些背景知識為什么這可能 go 錯誤:在幾種編程語言中,整個程序嵌入在main()
function 中,所以ls
可能看起來像:
main(){
<show the listing of the current directory>
}
如果要執行此操作 3 次,您可能需要:
main(){
<show the listing of the current directory>
<show the listing of the current directory>
<show the listing of the current directory>
}
但如果你只是簡單地將所有東西粘在一起,你會得到:
main(){
<show the listing of the current directory>
}
main(){
<show the listing of the current directory>
}
main(){
<show the listing of the current directory>
}
如果你嘗試運行它,計算機會說“這是什么?不止一個main()
function?我不知道該怎么做,所以我什么也不做。
因此,如您所見,粘合二進制文件以多次執行它們是一個壞主意,無論多么好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.