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
閱讀更多 飛哥有料 的文章