跳至內容

Linux 文件操作

出自陋室

下面是 Linux 中對文件的常用操作,包含新建、複製、刪除、移動與查看。

新建空白文件

使用 touch 新建文件:

touch hello

可用 ls 查看創建結果。該命令不會覆蓋已有同名文件。

複製

複製文件到指定目錄:

cp hello one/two/

複製目錄需要 -r:

mkdir test
cp -r test one/two

刪除

刪除文件:

rm hello

刪除目錄需要 -r:

rm -r test

移動與重命名

移動文件或目錄:

mv test1 dir1

重命名:

mv test1 test2

查看文件內容

使用 cat 查看內容:

cat passwd

顯示行號:

cat -n passwd