linux常用基本命令(1) 目录及文件操作

1. pwd

用途:显示当前工作目录的名称

用法:pwd [选项]

选项:-P    显示链接的真实路径    #或-LP

[root@localhost test1]# pwd
/root/test1
[root@localhost test1]# pwd -P            #test1为目录test的软链接
/root/test

2.cd

用途:cd命令的作用是切换当前的工作目录

[root@localhost ~]# cd /usr/src/        #切换目录到/usr/src/
[root@localhost src]# cd ..             #切换目录到当前目录的上一级
[root@localhost usr]# cd -              #切换至上一个操作目录并输出该目录路径
/usr/src
[root@localhost src]# cd                #切换工作目录到当前目录的家目录

3.ls

用途:显示目录与文件的信息

用法:ls [选项] [文件或目录]

选项:-a    显示所有文件与目录(包括隐藏文件与目录)

           -d    显示目录本身的信息而不是目录下的文档信息

           -h    人性化显示信息

           -l     长格式显示文档的详细信息

           -u    显示文件或目录的最后访问时间

           -t     以修改时间排序,ls默认按照文件名排序

[root@localhost etc]# ls                #显示当前目录下的子文件与目录信息

[root@localhost etc]# ls /usr           #显示/usr下的子文件与目录信息

[root@localhost etc]# ls -a             #包括隐藏文件

[root@localhost etc]# ls -l             #详细信息

[root@localhost etc]# ls -lu passwd     #显示文件最后访问时间   
-rw-r--r--. 1 root root 3333 8月  13 09:47 passwd

[root@localhost etc]# ls -lt            #按修改时间排序,从近到远




4. touch

用途:创建或刷新文件时间

[root@localhost test]# touch hello

5.mkdir

用途:创建目录

用法:mkdir [选项] [目录名]

选项:-p    创建多级目录(递归创建)

[root@localhost test]# mkdir 1                #创建目录1

[root@localhost test]# cd 1

[root@localhost 1]# mkdir -p 2/3/4/5/6        #递归创建目录2 3 4 5 6

[root@localhost 1]# cd 2/3/4/5/6

[root@localhost 6]# pwd
/root/test/1/2/3/4/5/6

6.cp

用途:复制文件或目录

用法:cp [选项]  源 目标

选项:-r    递归复制,一般复制目录时使用

          -a    复制时保留源文件的所有属性(包括权限,时间等)

[root@localhost test]# cp hello he        #复制文件并重命名为he

[root@localhost test]# cp -r /var/log/ /tmp #复制目录/var/log 到/tmp

[root@localhost test]# cp -a /etc/passwd /test

7.rm

用途:删除文件或目录

用法:rm -选项  文件或目录

选项:-f   不提示,强制删除

          -i    询问是否删除

          -r    递归删除

[root@localhost test]# rm hello 
rm:是否删除普通空文件 "hello"?

[root@localhost test]# rm -f hello 

[root@localhost test]# rm -r 1/2/3/4/5/6
rm:是否删除目录 "1/2/3/4/5/6"?

[root@localhost test]# rm -rf 1/2/3/4/5/6
[root@localhost test]# 

8.mv

用途:移动(重命名)文件或目录

[root@localhost test]# mv ha hello

[root@localhost test]# mv hello ..    #移动到上级目录

9.find

用途:搜索文件或目录

用法: find -选项 路径 表达式

选项:-empty  查找空白文件或目录

           -group  按组查找

           -name  按文档名查找

           -iname  按文档名查找不区分大小写

           -mtime  按修改时间查找

           -size      按容量大小查找

           -type      按类型 f 文件 d 目录  b,c设备,l  链接,

           -user      按用户名查找

           -exec     对查找文件执行命令

           -a           并且

           -o           或者

[root@localhost ~]# find -name filetest
./test/filetest

[root@localhost ~]#find /root -name "*.log"       #查找/root下所有以.log结尾的

[root@localhost ~]# find -iname FIletest          #不区分大小写
./test/filetest

[root@localhost ~]# find / -empty                 #寻找当前目录下的空文件

[root@localhost ~]# find -mtime -3                #查找三天以内修改过的

[root@localhost ~]# find -mtime +3                #查找4天以前被修改过的

[root@localhost ~]# find -mtime 3                 #查找3天前当天修改的

[root@localhost ~]# find ./ -size +10M            #查找大于10MB的文件
./Python-3.6.1.tgz

[root@localhost ~]# find ./ -size -10M            #查找小于10MB的文件



10.du

用途:计算文件或目录的容量

用法:du -选项 文件或目录

选项:-h    人性化显示容量信息

           -a    查看所有目录以及文件的容量信息

           -s    仅显示总容量

[root@localhost ~]# du /root

[root@localhost ~]# du -sh /root        #查看/root 所占用的磁盘的空间的总和
482M	/root

   

猜你喜欢

转载自blog.csdn.net/weixin_38280090/article/details/81624933