1.创建目录
mkdir /demo
/ :表示在根目录下创建目录
2.在/demo下创建文件test.txt
cd /demo
touch test.txttouch:如果文件不存在,就建立新文件,如果存在,就改变文件的访问时间atimc等时间戳信息。
3.给test.txt 添加文本内容,如 this is a test file
第一种方式
vi test.txt
输入内容完成后,按Esc退出编辑(INSERT)模式:
输入:wq退出并保存文件:
- 第二种方式,单行文本插入
echo “this is a test file” > test.txt
“>” : 重定向,覆盖原来的内容
“>>” : 追加内容,不覆盖
- 第三种方式,追加多行
cat >> /data/test.txt << EOF
this is a test file.
test input.
EOF
4.复制文件或者目录
cp /demo/test.txt /tmp/
cp默认只能拷贝文件cp -a /etc/ /tmp
拷贝目录
5.把/demo目录移动到/root下
mv /demo/root/
6.进入root目录下的demo目录,删除test.txt
cd /root/demo/
rm test.txtrm -f 强制删除文件 -r递归删除 删除文件或目录
-fr删除指定的目录和文件
7.grep 过滤
7.1 生成数据
cat >> test.txt << EOF
test
file
demo
EOF
7.2 -v排除
grep -v demo test.txt
结果: