Linux指令:cp 以及ln -s使用情境與注意事項

icelandcheng

--

在使用linux指令時,常會用到cp來複製檔案,若今天想一次將檔案複製並命命名為特定名稱,例如要將readme.txt重新命名為new_readme.txt,可以使用以下指令

cp readme.txt new_readme.txt

另外,可能常會用到ln -s建立捷徑,例如要在個人資料夾建立readme.txt的捷徑readme_link,readme.txt是存放在test資料夾底上,那麼使用的指令會像下面這樣

ln -s ~/test/readme.txt readme_link.txt

要注意檔案的路徑~/test/,一定要在資料夾前面加上~/才行,這樣才會指導完整的路徑,也才找得到捷徑對應的網站,如果沒有加~,像下面這樣,可以看到readme_link.txt對應的捷徑是指向test/readme.txt,根本找不到檔案,用cat指令去查看內容也會顯示沒有這個檔案

在test前面加上~/後,像下面這樣,可以看到readme_link.txt不是紅色了,它有指到一個完整的路徑,也有找到對應的檔案,所以使用cat的時候,可以印出readme.txt的內容。

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

icelandcheng
icelandcheng

Written by icelandcheng

Programming Skill learner and Sharer | Ruby on Rails | Golang | Vue.js | Web Map API

No responses yet

Write a response