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

  • 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 {} \;
主站蜘蛛池模板: 十堰市| 岐山县| 仁怀市| 楚雄市| 苍梧县| 梧州市| 尚义县| 安泽县| 天全县| 太仓市| 嘉黎县| 进贤县| 西乌| 电白县| 临漳县| 轮台县| 鄄城县| 武定县| 昭觉县| 清苑县| 育儿| 长子县| 青州市| 荆州市| 南平市| 綦江县| 昌都县| 林周县| 潼南县| 吴堡县| 聂荣县| 玉林市| 虹口区| 铁岭市| 深水埗区| 贵南县| 岐山县| 全南县| 邯郸市| 礼泉县| 闽清县|