@@ -1570,29 +1570,7 @@ \subsection{Archives}
15701570
15711571\subsection {Searching}
15721572
1573- \begin {frame}[fragile]{Looking for files and applications}
1574- \begin {bashcode}
1575- apropos keyword # Searches for command descriptions containing keyword
1576- updatedb # Must be regularly launched to get "locate" to work
1577- # It is usually regularly launched by cron task (see further)
1578- locate somename # Searches for files/directories in "locate" database
1579- which # Full path to application (shell command)
1580- whereis # Path to source code, executable and man pages for the command
1581- # Test if executable command exists (good for scripts)
1582- # If "Application" is missing, script ends with error
1583- command -v Application >/dev/null 2 >&1 || { echo >&2 "Application is
1584- required but not installed. Aborting."; exit 1; }
1585- command -v find # Behaves like which, but reliable in scripts
1586- type Application >/dev/null 2 >&1 || { echo >&2 "Application is
1587- required but not installed. Aborting."; exit 1; }
1588- exit 1 # "exit" use to be added (with various numbers) after any error
1589- # to send term signal 1 - for better handling of various errors.
1590- # Every termination has exit status number - 0 is normal exit.
1591- # Exit status 1 and higher number is various error.
1592- \end {bashcode}
1593- \end {frame}
1594-
1595- \begin {frame}[fragile]{Find}
1573+ \begin {frame}[fragile]{Find --- looking for files}
15961574 \begin {bashcode}
15971575 find <where> <what> <what to do> # The most powerful searching tool:
15981576 find /... -type d/f -name XXX -print # Most common usage
@@ -1621,13 +1599,13 @@ \subsection{Searching}
16211599 # stdin and execute command with given arguments, using all CPU threads)
16221600 # Note in the example below -print is not needed as it is default action
16231601 find photos/ -name "*.jpg" | xargs mogrify -resize 1000 x1000
1624- # Find all R scripts in ~/Documents and find in them lines with "DNA"
1625- find ~/Documents -name "*.r" -print | xargs grep -nH DNA # Or
1626- find ~/Documents -name "*.r" -exec grep -nH DNA '{}' \;
16271602 # How many directories are there in the books directory
16281603 find books/ -type d -print | wc -l # wc -l calculates lines
16291604 # Change permissions of all files within "files" directory to 640
16301605 find files/ -type f -exec chmod 640 '{}' \;
1606+ # Find all R scripts in ~/Documents and find in them lines with "DNA"
1607+ find ~/Documents -name "*.r" -print | xargs grep -nH DNA # Or
1608+ find ~/Documents -name "*.r" -exec grep -nH DNA '{}' \;
16311609 \end {bashcode}
16321610\end {frame}
16331611
@@ -1648,7 +1626,29 @@ \subsection{Searching}
16481626 # Find in current directory files from 1 to 100 MB
16491627 find . -type f -size +1 M -size -100 M
16501628 # Search in home dir for files named "*.jpg" or "*.txt" and print them
1651- find ~ -name "*.jpg" -o -name "*.txt"
1629+ find ~ -name "*.jpg" -o -name "*.txt" # '-print' is default, can be omitted
1630+ \end {bashcode}
1631+ \end {frame}
1632+
1633+ \begin {frame}[fragile]{Looking for applications and files}
1634+ \begin {bashcode}
1635+ updatedb # Must be regularly launched to get "locate" to work
1636+ # It is usually regularly launched by cron task (see further)
1637+ locate somename # Searches for files/directories in "locate" database
1638+ apropos keyword # Searches for command descriptions containing keyword
1639+ which app # Full path to application (shell command)
1640+ whereis app # Path to source code, executable and man pages for the command
1641+ # Test if executable command exists (good for scripts)
1642+ # If "Application" is missing, script ends with error
1643+ command -v Application >/dev/null 2 >&1 || { echo >&2 "Application is
1644+ required but not installed. Aborting."; exit 1; }
1645+ type Application >/dev/null 2 >&1 || { echo >&2 "Application is
1646+ required but not installed. Aborting."; exit 1; }
1647+ # More reliable than 'which Application || { echo XXX; exit 1; }'
1648+ exit 1 # "exit" use to be added (with various numbers) after any error
1649+ # to send term signal 1 - for better handling of various errors.
1650+ # Every termination has exit status number - 0 is normal exit.
1651+ # Exit status 1 and higher number is various error.
16521652 \end {bashcode}
16531653\end {frame}
16541654
0 commit comments