How to use the find command
Use find from the command line to locate a specific file by name or extension. The following example searches for *.err files in the /home/username/ directory and all sub-directories:
find /home/username/ -name "*.err"find expressions take the following form:
find options starting/path expression- The
optionsattribute will control the behavior and optimization method of thefindprocess. - The
starting/pathattribute will define the top level directory wherefindbegins filtering. - The
expressionattribute controls the tests that search the directory hierarchy to produce output.
Consider the following example command:
find -O3 -L /var/www/ -name "*.html"This command enables the maximum optimization level (-O3) and allows find to follow symbolic links (-L). find searches the entire directory tree beneath /var/www/ for files that end with .html.
| Command | Description |
|---|---|
find . -name testfile.txt |
Find a file called testfile.txt in current and sub-directories. |
find /home -name \*.jpg |
Find all .jpg files in the /home and sub-directories. |
find . -type f -empty |
Find an empty file within the current directory. |
find /home -user exampleuser -mtime 7 -iname ".db" |
Find all .db files (ignoring text case) modified in the last 7 days by a user named exampleuser. |
How to run a remote script from local
To run a remote script from local you need two scripts:
- one on the source machine,
- another one on the destination machine.
The script on the source machine should be something like:
rsync ... ... ... syncuser@destination:/dest/path
ssh syncuser@destination "sudo /some/path/to/completesync.sh"And on the destination machine, the script /some/path/to/completesync.sh which contains something like this:
#!/bin/sh
php artisan cache:clear
php artisan config:cache
# whatever else you need to run as rootBe careful to have restricted rights on this script:
chown root:root /path/to/completesync.sh && chmod 700 /path/to/completesync.shLast, modify /etc/sudoers on the destination machine so that syncuser can run both rsync and your script as root:
syncuser ALL=NOPASSWD: /usr/bin/rsync, /path/to/completesync.shNow running the script on the source machine should complete the whole process in one operation.
How to create a symlink
Here is the basic syntax for creating a symlink to a file in your terminal.
ln -s existing_source_file optional_symbolic_linkYou use the ln command to create the links for the files and the -s option to specify that this will be a symbolic link. If you omit the -s option, then a hard link will be created instead.
- The
existing_source_filerepresents the file you want to create the symbolic link for. - The
optional_symbolic_linkparameter is the name of the symbolic link you want to create. If omitted, then the system will create a new link for you in the current directory you are in.