http://crybit.com/find-command-usage-with-example-unixlinux/

find command is one of the best search tool under UNIX/LINUX. Here I’m discussing some common switches of find command with detailed example. Like the name find, the “find” command is using for search files under a directory hierarchy. One simle example is shown below,
find / name linux ;
here the second part that means “/” has an important role in the find command syntax. This is the path for searching the file having name linux. This command will return the file linux if it is exist under “/” .

Numeric arguments

+n >> for greater than n,
-n >> for less than n,
n  >> for exactly n.

Switchs and usage:

1. -name pattern ==> Find the matched name pattern.

1.1 -iname pattern ==> Like -name, but the match is case insensitive.
Examples;

# find / -name test123.txt
/home/***/crybit/test123.txt# find / -iname TeSt123.txt
/home/***/crybit/test123.txt# find / -iname TeSt***.txt
/home/***/crybit/test123.txt# find / -name te**.txt
/home/***/crybit/test123.txt

2. -path pattern ==> It will list out the exact path if it is exist.

Examples,

# find / -path "/e**wd"
/etc/pam.d/chpasswd
/etc/pam.d/passwd
/etc/cron.daily/passwd
/etc/passwd
/etc/security/opasswd
............
# find / -path "/us**.conf"
/usr/share/onboard/onboard-defaults.conf
/usr/share/popularity-contest/default.conf
/usr/share/base-files/nsswitch.conf
/usr/share/samba/smb.conf
............
# find / -path "/us**.sh"
/usr/share/onboard/scripts/changekbd.sh
/usr/share/alsa-base/alsa-info.sh
/usr/share/libreoffice/shell-lib-extensions.sh
/usr/share/debconf/confmodule.sh
............

3. -perm mode ==> File’s permission bits are exactly mode (octal or symbolic).

Example;
# ll
total 8
drwxrwxr-x 2 root root 4096 Sep 5 20:37 ./
drwxr-xr-x 34 root root 4096 Sep 5 19:52 ../
-rwxrwxrwx 1 root eclinux 0 Sep 5 20:37 test1234.txt*
-rwx–x–x 1 root root 0 Sep 5 20:37 test1235.txt*
-rw-rw-r– 1 root root 0 Sep 5 20:38 test123.txt

# find ./ -perm 664
./test123.txt
{./ is the path for searching(current directory). This will find out the file having permission 664}

3.1 -readable >> Matches files which are readable.
3.2 -writable >> Matches files which are writable.
3.3 -executable >> Matches files which are executable.

Example;

# find ./ -executable
./
./test1235.txt
./test1234.txt

4. -gid & -uid

4.1 -gid n >> File's numeric group ID is n.
4.2 -group gname >> File belongs to group gname (numeric group ID allowed).
4.3 uid n >> File's numeric user ID is n.
4.4 -user name >> File belongs to user name (numeric user ID allowed).

Examples;

# ll
total 8
drwxrwxr-x 2 root root 4096 Sep 5 20:37 ./
drwxr-xr-x 34 root root 4096 Sep 5 19:52 ../
-rwxrwxrwx 1 root eclinux 0 Sep 5 20:37 test1234.txt*
-rwx--x--x 1 root root 0 Sep 5 20:37 test1235.txt*
-rw-rw-r-- 1 root root 0 Sep 5 20:38 test123.txt# find ./ -gid 1003
./test1234.txt
# find ./ -group eclinux
./test1234.txt

Similarly we can use -uid & -user.

5. -empty : this will find all files having empty content.

Example;

# find ./ -empty
./test1235.txt
./test1234.txt
./test123.txt

6. -size n[cwbkMG] ==> File uses n units of space. The following suffixes can be used:

'b' for 512-byte blocks (this is the default if no suffix is used)
'c' for bytes
'w' for two-byte words
'k' for Kilobytes (units of 1024 bytes)
'M' for Megabytes (units of 1048576 bytes)
'G' for Gigabytes (units of 1073741824 bytes)

7. -type ==> Specify the file type.

b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link
s socket
D door (Solaris)

Example;

# find ./ -type f
./test1235.txt
./test1234.txt
./test123.txt

8. Switches related to modification time

8.1 -amin n >> File was last accessed n minutes ago.
8.2 -atime n >> File was last accessed n*24 hours ago.
8.3 -cmin n >> File's status was last changed n minutes ago.
8.4 -ctime n >> File's status was last changed n*24 hours ago.
8.5 -mmin n >> File's data was last modified n minutes ago.
8.6 -mtime n >> File's data was last modified n*24 hours ago.

Example;

# find ./ -mmin +1
./test1235.txt
./test1234.txt

9. inode & links

9.1 -inum n >> File has inode number n.
9.2 -samefile name >> File refers to the same inode as name.
9.3 -links n >> File has n links.

Example;

ls -i to find out the inode number.
# ls -i test123.txt
1316256 test123.txt
# find ./ -inum 1316256
./test123.txt# ll
total 8
drwxrwxr-x 2 root root 4096 Sep 5 20:37 ./
drwxr-xr-x 34 root root 4096 Sep 5 19:52 ../
-rwxrwxrwx 1 root eclinux 0 Sep 5 20:37 test1234.txt*
-rwx--x--x 1 root root 0 Sep 5 20:37 test1235.txt*
-rw-rw-r-- 1 root root 0 Sep 5 20:38 test123.txt

# find ./ -links 1
./test1235.txt
./test1234.txt
./test123.txt

All three files having single links.

10. -delete & -exec operations

10.1 -delete : This switch is use to remove a particular that already specified in the find command. Use this switch with extra care.

Example;

# find ./ -inum 1316256
./test123.txt
# find ./ -inum 1316256 -delete
# find ./ -inum 1316256

In this case, -delete switch remove the file test123.txt . Similarly we can remove anything that found by find command.

10.2 -exec : This will execute commands on the find syntax.

Example;

# ll
total 8
drwxrwxr-x 2 root root 4096 Sep 5 20:37 ./
drwxr-xr-x 34 root root 4096 Sep 5 19:52 ../
-rwxrwxrwx 1 root eclinux 0 Sep 5 20:37 test1234.txt*
-rwx--x--x 1 root root 0 Sep 5 20:37 test1235.txt*
-rw-rw-r-- 1 root root 0 Sep 5 20:38 test123.txt

Run the command to change the permission.

# find ./ -type f -exec chmod 777 {} \;
# ll
total 8
drwxrwxr-x 2 root root 4096 Sep 5 20:37 ./
drwxr-xr-x 34 root root 4096 Sep 5 19:52 ../
-rwxrwxrwx 1 root eclinux 0 Sep 5 20:37 test1234.txt*
-rwxrwxrwx 1 root root 0 Sep 5 20:37 test1235.txt*
-rwxrwxrwx 1 root root 0 Sep 5 20:38 test123.txt*

the chmod command after -exec in find command change the file permission to 777.

# find ./ -type f -exec rm -rf {} \;

This will remove all files in the current working directory.

I think this article gave some ideas about the usages of find command under UNIX/LINUX to you.
Thank you for your time.

More:
groupdel, groupmems, groupmod, useradd , usermod , chgrp, chown, ls, head, tail, top, ps, find,crontab

转载于:https://www.cnblogs.com/davidwang456/p/3595614.html

10+ commonly using find command switches with example Unix/Linux相关推荐

  1. mac启动选项找不到linux,Mac升级10.10后开机引导不见了,无法进入Linux

    Mac升级10.10后开机引导不见了,无法进入Linux 因为工作需要,电脑是mac和Linux双系统,最近mac升级了10.10,但是升级完发现引导不见了,用磁盘工具看,Linux分区显示的挂载,但 ...

  2. mac 更新10.11后,出现command not found的解决办法

    更新新系统后,需要使用cocoapods,使用pod update时,出现command not found,在终端内运行如下名利即可: sudo gem install -n /usr/local/ ...

  3. 15+ tar command usages with examples – Unix/Linux--reference

    reference :http://crybit.com/tar-command-usages-with-examples/ The 'tar' saves many files together i ...

  4. Deploy Oracle 10.2.0.5 DataGuard on Red Hat Enterprise Linux 6.4

    系统:Red Hat Enterprise Linux 6.4 数据库:Oracle 10.2.0.5.0 Patch Set 4 主机:10dg1 192.168.1.91 10dg2192.168 ...

  5. linux pipe函数 重定向,I/O重定向和管道——《Unix/Linux编程实践教程》读书笔记(第10章)...

    1.I/O重定向的概念与原因 及 标准输入.输出的标准错误的定义 所以的Unix I/O重定向都基于标准数据流的原理.三个数据了分别如下: 1)标准输入--需要处理的数据流 2)标准输出--结果数据流 ...

  6. Veritas NetBackup 10.0 (Unix, Linux, Windows)

    请访问原文链接:https://sysin.org/blog/veritas-netbackup-10/,查看最新版.原创作品,转载请保留出处. 作者主页:www.sysin.org 一流的企业备份和 ...

  7. nc: command not found完美解决(linux配置nc命令)

    [hadoop@hadoop001 conf]$ nc -lk 9999 -bash: nc: command not found nc: command not found出现该情况有两种可能: ( ...

  8. 200 PORT command successful. Consider using PASV / Linux 部署vsftp不能正常访问

    Linux部署vsftp不能正常访问问题 1. 问题描述 2. 问题现象 3. 解决问题 以下问题为内网部署ftp遇到的问题,仅供参考 200 PORT command successful. Con ...

  9. 2020年10月linux内核,Windows 10 May 2020现已提供更新,内置Linux内核和Cortana

    微软今天发布其Windows 10 May 2020更新.它是Windows 10的最新"主要"更新,其主要功能包括Linux 2的Windows子系统和Cortana更新.微软上 ...

最新文章

  1. ORACLE的直方图的一些试验
  2. Linux 操作系统原理 — 内存 — 基于 MMU 硬件单元的虚/实地址映射技术
  3. windows10 64位 Tensorflow安装--CUDA 9.1+cuDNN7.1.1+python3.6.4+tf1.6+vs2017
  4. Android --- This project contains Java compilation errors,which can cause rendering failures for
  5. 英语语法---主语详解
  6. 前端学HTTP之字符集
  7. CSS做个Switch开关
  8. 【DP】字串距离(luogu 1279)
  9. 多环境切换---SpringBoot
  10. 大型网站服务器 pdf,大型网站服务器容量规划[PDF][145.25MB]
  11. java knn分类_返回2个或更多最近邻居的KNN算法
  12. mysql 太多字段 排除某一列_Atitit 数据库排除某一列 字段 显示
  13. JS函数,数组,日期
  14. 平衡二叉树删除_自平衡二叉树实现及时间复杂度分析
  15. hdu 2295(DLX+二分)
  16. python中os关于目录创建和文件移动操作
  17. 痞子衡嵌入式:MCUXpresso Config Tools初体验(Pins, Clocks, Peripherals)
  18. 给惠普735g5 装Win10+Ubuntu 16.04双系统
  19. Hive 算两时间差
  20. 自定义结构体及初始化

热门文章

  1. 安卓按键精灵_[按键精灵教程]学了这个你也能做出稳定的脚本
  2. aes sample java,python-AES加密java解密
  3. java spring上传_SpringMVC上传文件的三种方式
  4. ue4小白人骨骼定义_UE4角色骨架创建流程_资源库
  5. 文本编辑器实现拖放功能
  6. Qt中的QMainWindow
  7. SQLServer数据的基本操作:简单的增、删、改、查
  8. 三星手机Android9和10的区别,三星开始在Galaxy Note 9上测试Android 10
  9. 为安卓应用添加手势密码功能,遇到的一些问题以及解决方法
  10. ORB_SLAM安装问题error: ‘std::chrono::monotonic_clock’ has not been declared