1、創建文件
1)創建空白文件
# touch file1
# ls
file1
說明:touch一個文件時,如果文件不存在,新建一個空白文件;如果文件已經存在,那麼修改文件的時間戳。
# ll file1
-rw-r--r-- 1 root root 0 Jul 24 15:45 file1
# touch file1
# ll file1
-rw-r--r-- 1 root root 0 Jul 24 15:49 file1
2)vim 不存在的文件名 \\有內容才能創建新文件,寫腳本常用
# vim file2
haha
hehe
3)echo 字符串 > 新文件名
# echo hello world > file3
# cat file3
hello world
4)cat > 文件名
# cat > file4
hello
good
happy
thank you
ctrl + d 結束輸入
# cat file4
hello
good
happy
thank you
2、複製文件
cp 源文件 目的文件或者目標位置
# cp file4 f4 //複製同時重命名
# cp file3 /tmp/
# cp file3 /tmp/ //tmp下已經存在file3文件時,會提示是否覆蓋
cp: overwrite `/tmp/file3'? y
# cp file3 /tmp/f3
3、移動文件
mv 源文件 目標文件或目標位置
# mv file2 /tmp/
# ls /tmp/file2
/tmp/file2
# mv /tmp/file2 /test/f2 //移動的同時改名
# ls
f2 f4 file1 file3 file4
4、刪除文件
# rm /test/f2 //交互式刪除文件
rm: remove regular file `/test/f2'? y
強制刪除文件
# rm -f /test/f4
閱讀更多 飛哥有料 的文章