座右铭:长风破浪会有时,直挂云帆济沧海。

linux一般查看文件或者目录有几种方法。

/查看文件类容--------cat/more/less/head/tail   只能查看文本型(txt)

(1)查看文件较少的类容

cat /etc/fstab

cat -n /etc/fstab

(2)查看未知类容

看未知的类容文件,我们不知道有多大,就用more和less查看比较方便使用

两者相同点:可以 翻页 或者 一行一行查看

       不同点:more只能往下翻页,有的翻过了,就不能翻回去了

                     less可以往上往下随意查看翻动

more/less  分页显示类容

more 只能往下翻(空格:翻页   回车:一行一行   q:退出)

less   可以上下翻

less /usr/share/dict/words

(3)head/tail(头部/尾巴)

head

不写-n显示前10行类容

[root@chengfeng ~]# head -n 3 /etc/passwd(显示前三行)

Tail

不写-n显示后10行类容

[root@chengfeng ~]# tail-n 3 /etc/passwd(显示前三行)

(4)查看文件类型

 

[root@chengfeng ~]# file /etc/passwd  (查看文件类型)

 (5)查看命令所在的路径

[root@chengfeng ~]# which ls
alias ls='ls --color=auto'
/usr/bin/ls
[root@chengfeng ~]# which cd
/usr/bin/cd

(6)|  :管道符  连接命令  前面的命令给后面命令当参数

[root@chengfeng ~]# head -n 5 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[root@chengfeng ~]# head -n 5 /etc/passwd | tail -n 1(显示passwd第5行的类容)
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

 显示前4个最大文件

root@chengfeng ~]# ls -lhS /etc/ | head -n 5
总用量 1.4M
-rw-r--r--. 1 root root 655K 6月 7 2013 services
-rw-r--r-- 1 root root 92K 1月 7 14:35 ld.so.cache
-rw-r--r-- 1 root root 51K 5月 15 2013 mime.types
-rw-r--r-- 1 root root 15K 10月 31 08:17 autofs.conf

 显示最近修改的文件

[root@chengfeng ~]# ls -lt /etc/ |head -n 11
总用量 1396
drwxr-xr-x 5 root lp 304 1月 7 19:01 cups
-rw-r--r-- 1 root root 57 1月 7 19:01 resolv.conf
-rw-r--r-- 1 root root 1992 1月 7 14:51 passwd
---------- 1 root root 1138 1月 7 14:50 shadow
---------- 1 root root 690 1月 7 14:50 gshadow
-rw-r--r-- 1 root root 862 1月 7 14:50 group
-rw-r--r--. 1 root root 850 1月 7 14:49 group-
----------. 1 root root 682 1月 7 14:49 gshadow-

(7)查找文件或目录

# find 路径 查找方式

按文件名称查找

[root@chengfeng ~]# find /etc/ -name "*.conf"
/etc/resolv.conf
/etc/pki/ca-trust/ca-legacy.conf
/etc/yum/pluginconf.d/fastestmirror.conf

统计查找的文件个数

[root@chengfeng ~]# find /etc/ -name "*.conf" |wc -l
352

 

按文件大小查找

查找大于1M的文件

[root@chengfeng ~]# find /etc/ -size +1M
/etc/udev/hwdb.bin
/etc/selinux/targeted/contexts/files/file_contexts.bin
/etc/selinux/targeted/policy/policy.31
/etc/selinux/targeted/active/policy.kern
/etc/selinux/targeted/active/policy.linked

 按文件的修改时间查找

查找7前修改的文件

[root@chengfeng ~]# find / -mtime +7

查找7内修改的文件

[root@chengfeng ~]# find / -mtime -7

 按文件的类型查找

[root@chengfeng ~]# find /dev/ -type b
/dev/dm-1
/dev/dm-0
/dev/sda2
/dev/sda1
/dev/sda
/dev/sr0
[root@chengfeng ~]# find /dev/ -type l

复合条件查文件

[root@chengfeng ~]# find / -mtime +7 -a -size +100k(a:and并列)

Find /bj/ -name “*.txt”  -exec rm -rf {}\;  删除

# Find /bj/ -name “*.txt”  -exec cp {} /root \;复制

Linux命令查找文件目录的更多相关文章

  1. linux命令---查找文件中的内容

    linux命令---查找文件中的内容   [yang@localhost ~]$ cat 1.txt |egrep '123456789|second'-------匹配123456789或者seco ...

  2. linux命令_文件目录操作命令

    # linux命令--文件和目录操作命令 pwd "print working directory" 打印工作目录的绝对路径 范例: 在bash命令行显示当前用户的完整路径 系统B ...

  3. Linux系统查找文件目录的命令

    查找目录名autobackup,并且列出路径:find -name 'autobackup'-type d find -name 'directoryname'-type d  

  4. linux命令--查找与帮助

    一.搜寻命令 1.whereis命令 whereis是搜索系统命令的命令,也就是说,whereis 命令不能搜索普通文件, 而只能搜索系统命令. 命令名称:whereis 英文原意:locate th ...

  5. 【Linux命令】文件目录管理命令7个(touch、mkdir、cp、mv、rm、dd、file)

    目录 touch创建空白文档或设置文件时间 mkdir创建空白目录 cp复制文件或目录 mv剪切文件或重命名文件 rm删除文件或目录 dd按照指定大小和个数的数据库来复制文件或转换文件 file查看文 ...

  6. Linux - 命令 - 查找命令总结

    关于查找文件的几个命令 一.find命令 find是最常用也是最强大的查找命令,可以查找任何类型的文件 find命令的一般格式: find <指定目录><指定条件><指定 ...

  7. linux命令-查找所有文件中包含某个字符串

    查找目录下的所有文件中是否含有某个字符串 find .|xargs grep -ri "IBM" 查找目录下的所有文件中是否含有某个字符串,并且只打印出文件名 find .|xar ...

  8. Linux 命令:文件目录操作与实例

    来源: http://blog.51cto.com/yuanzhitang/2056994 本文介绍基础的文件操作:创建,移动,编辑,删除 文件和文件夹   命令与案例:   mkdir 创建目录 - ...

  9. 常用Linux命令笔记

    任何脱离业务的架构都是耍流氓 只记录实际常用的Linux命令 常用Linux命令 查找安装路径: whereis nginx 查询nginx进程: ps aux|grep nginx 查看 CentO ...

随机推荐

  1. [LeetCode] 922. Sort Array By Parity II 按奇偶排序数组之二

    Given an array A of non-negative integers, half of the integers in A are odd, and half of the intege ...

  2. [LeetCode] 148. Sort List 链表排序

    Sort a linked list in O(n log n) time using constant space complexity. Example 1: Input: 4->2-> ...

  3. shell之startup

    #!/bin/sh # # # # PROJECT=$ APPWORK_DIR=~/apps/$PROJECT LOGPATH=~/logs/$ LOGFILE=~/logs/$PROJECT/${P ...

  4. js中的require、define、export、import【转】

    原文链接:https://www.cnblogs.com/libin-1/p/7127481.html 为什么有模块概念 理想情况下,开发者只需要实现核心的业务逻辑,其他都可以加载别人已经写好的模块. ...

  5. 面试官:”准备用HashMap存1w条数据,构造时传10000会触发扩容吗?“

    通常在初始化 HashMap 时,初始容量都是根据业务来的,而不会是一个固定值,为此我们需要有一个特殊处理的方式,就是将预期的初始容量,再除以 HashMap 的装载因子,默认时就是除以 0.75. ...

  6. Centos.安装Goaccess1.2

    下载 wget http://tar.goaccess.io/goaccess-1.2.tar.gz 解压 tar -xzvf goaccess-1.2.tar.gz 安装支持库GeoIP-devel ...

  7. Debug 路漫漫-11:Python: TypeError: 'generator' object is not subscriptable

    调试程序,出现以下错误: Python: TypeError: 'generator' object is not subscriptable “在Python中,这种一边循环一边计算的机制,称为生成 ...

  8. Linux内核定时器struct timer_list

    1.前言 Linux内核中的定时器是一个很常用的功能,某些需要周期性处理的工作都需要用到定时器.在Linux内核中,使用定时器功能比较简单,需要提供定时器的超时时间和超时后需要执行的处理函数. 2.常 ...

  9. JavaIO学习:缓冲流

    缓冲流 1.缓冲流涉及到的类 BufferedInputStream BufferedOutputStream BufferedReader BufferedWriter 2.作用 提升流的读取.写入 ...

  10. .net 中访问config的一些方式

    人所缺乏的不是才干而是志向,不是成功的能力而是勤劳的意志. 哎!好久没有写博客了,今天就分享一些比较常用的对config文件的访问一些方式. 首先 引用 using System.Configurat ...