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

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 {} \;
主站蜘蛛池模板: 宁化县| 九台市| 工布江达县| 汤原县| 南阳市| 南宁市| 万源市| 祁连县| 深州市| 宝山区| 灵璧县| 迭部县| 策勒县| 会泽县| 灵武市| 双柏县| 汾阳市| 永登县| 桂平市| 深圳市| 闵行区| 巴青县| 东安县| 崇文区| 阳山县| 临汾市| 三门县| 五台县| 夏河县| 句容市| 易门县| 林西县| 微山县| 贵德县| 辽阳市| 太康县| 花莲市| 济阳县| 绿春县| 塘沽区| 虎林市|