日期:2014-05-16  浏览次数:20597 次

Linux学习笔记(二)目录文件

[root@localhost ~]#ls      列出当前目录文件(不包括隐含文件)
[root@localhost ~]#ls -a   列出当前目录文件(包括隐含文件)
[root@localhost ~]#ls -l   列出当前目录下文件的详细信息

[root@localhost ~]#pwd     显示用户当前的工作路径
[root@localhost ~]#cd ..   回当前目录的上一级目录
[root@localhost ~]#cd -    回上一次所在的目录
[root@localhost ~]#cd ~    或 cd 回当前用户的宿主目录

[root@localhost ~]#mkdir   目录名 创建一个目录
[root@localhost ~]#rmdir   空目录名 删除一个空目录
[root@localhost ~]#rm      文件名 文件名 删除一个文件或多个文件
[root@localhost ~]#rm -rf  非空目录名 删除一个非空目录下的一切
[root@localhost ~]#rm  -i  系统会询问我们是否要删除test 文件敲了y/n 确认是否要删除test 文件

[root@localhost ~]# touch  a.txt  创建文件


[root@localhost ~]# cat file1.txt              显示 file1.txt 文件的内容
[root@localhost ~]# cat file1.txt file2.txt    显示 file1.txt 和file2.txt 文件的内容
[root@localhost ~]# cat -n file1.txt           显示 file1.txt 文件的内容同时显示行号
[root@localhost ~]# cat file1 file2>file3      把file1,file2 的内容结合起来再重定向>到file3 文件中

[root@localhost ~]# mv  a.txt b.txt            改名
[root@localhost ~]# mv /tmp/xxx.tar /root      移动
[root@localhost ~]# cp  a.txt b.txt            复制                 
[root@localhost ~]# cp -R                      删除文件夹带文件  cp -r
[root@localhost ~]# less  a.txt                按页显示
[root@localhost ~]# more  a.txt                分页显示

[root@localhost ~]#head example.txt            显示文件 example.txt 的前十行
[root@localhost ~]#head -n 20 example.txt      显示文件 example.txt 的前二十行
[root@localhost ~]#tail example.txt            显示文件 example.txt 的后十行
[root@localhost ~]#tail -n 20 example.txt      显示文件 example.txt 的后二十行
[root@localhost ~]#tail -f example.txt         动态显示文件内容多用于实时监控log

[root@localhost ~]# diff  a.txt b.txt          比较2个文件差异
[root@localhost ~]#file  a.txt                 显示下文件类型