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

  • 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 {} \;
主站蜘蛛池模板: 辽阳市| 大连市| 大埔县| 东乌| 佛山市| 石楼县| 兴仁县| 惠州市| 黑龙江省| 延安市| 西乌珠穆沁旗| 来安县| 页游| 湘潭县| 右玉县| 梁平县| 汝南县| 西宁市| 巴塘县| 塔城市| 泌阳县| 龙口市| 镇雄县| 苏尼特左旗| 涞水县| 睢宁县| 大兴区| 乌拉特前旗| 汕尾市| 上栗县| 西吉县| 福安市| 延寿县| 怀集县| 曲周县| 天全县| 扶余县| 武川县| 咸宁市| 酉阳| 屯昌县|