官术网_书友最值得收藏!

  • Bash Cookbook
  • Ron Brash Ganesh Naik
  • 193字
  • 2021-07-23 19:17:42

How to do it...

  1. Open a terminal and run the following commands in order to understand the locate command:
$ locate stdio.h
$ sudo touch /usr/filethatlocatedoesntknow.txt /usr/filethatlocatedoesntknow2.txt
$ sudo sh -c 'echo "My dear Watson ol\'boy" > /usr/filethatlocatedoesntknow.txt'
$ locate filethatlocatedoes
$ sudo updatedb
$ locate filethatlocatedoesntknow
  1. Next, run the following commands to demonstrate some of the power of find:
$ sudo find ${HOME} -name ".*" -ls
$ sudo find / -type d -name ".git"
$ find ${HOME} -type f \( -name "*.sh" -o -name "*.txt" \)
  1. Next, we can chain the find commands together with && and ultimately perform an exec instead of piping the output to another process, command, or script. Try the following:
$ find . -type d -name ".git" && find . -name ".gitignore" && find . -name ".gitmodules"
$ sudo find / -type f -exec grep -Hi 'My dear Watson ol boy' {} +
  1. Finally, one of the most common uses of find is to delete files using either the built-in -delete flag or by using exec combined with rm -rf:
$ find ~/emptydir -type d -empty -delete
$ find
Linux-Device-Drivers-Development -name ".git*" -exec rm -rf {} \;
主站蜘蛛池模板: 哈密市| 南充市| 鄂托克旗| 三原县| 闽清县| 柘荣县| 漯河市| 永泰县| 迭部县| 大竹县| 称多县| 珠海市| 清河县| 三穗县| 库伦旗| 晴隆县| 哈尔滨市| 鄂温| 金乡县| 武川县| 宣汉县| 兰州市| 大丰市| 渭南市| 灵山县| 扎鲁特旗| 凤山县| 东城区| 涟水县| 洪江市| 敦煌市| 马公市| 师宗县| 昌江| 久治县| 和平区| 棋牌| 辽阳县| 定南县| 惠东县| 浠水县|