- 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 {} \;
推薦閱讀
- 算法訓(xùn)練營(yíng):入門篇(全彩版)
- Magento 2 Theme Design(Second Edition)
- 微信小程序開發(fā)解析
- 人人都懂設(shè)計(jì)模式:從生活中領(lǐng)悟設(shè)計(jì)模式(Python實(shí)現(xiàn))
- iOS應(yīng)用逆向工程(第2版)
- Mastering Android Development with Kotlin
- 基于ARM Cortex-M4F內(nèi)核的MSP432 MCU開發(fā)實(shí)踐
- C++編程兵書
- QPanda量子計(jì)算編程
- SSH框架企業(yè)級(jí)應(yīng)用實(shí)戰(zhàn)
- Elastix Unified Communications Server Cookbook
- Mastering Magento Theme Design
- 編程風(fēng)格:程序設(shè)計(jì)與系統(tǒng)構(gòu)建的藝術(shù)(原書第2版)
- Mastering React Test:Driven Development
- Mastering Responsive Web Design