- Bash Cookbook
- Ron Brash Ganesh Naik
- 193字
- 2021-07-23 19:17:42
How to do it...
- 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
- 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" \)
- 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' {} +
- 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 {} \;
推薦閱讀
- 多媒體CAI課件設計與制作導論(第二版)
- Learning Java Functional Programming
- FreeSWITCH 1.8
- WebAssembly實戰
- 深入淺出Electron:原理、工程與實踐
- NLTK基礎教程:用NLTK和Python庫構建機器學習應用
- Python高效開發實戰:Django、Tornado、Flask、Twisted(第3版)
- 微信小程序開發解析
- PySide GUI Application Development(Second Edition)
- 名師講壇:Spring實戰開發(Redis+SpringDataJPA+SpringMVC+SpringSecurity)
- 青少年Python編程入門
- Spring Boot進階:原理、實戰與面試題分析
- 一塊面包板玩轉Arduino編程
- SQL 經典實例
- MySQL入門很輕松(微課超值版)