Check out this reference, in addition to the man pages for find and grep.
Quick summary:
find .
means search in the current directory
-type f
means look for regular files
-name "*.xml"
means look for files that end with ".xml"
-exec
tells the "find" program to interpret what follows as a command, up to the special \; marker, and executes that command once for each file that was found. During this phase, it substitutes the filename when it encounters {}
2> /dev/null
finally, this sends any "standard error" output to /dev/null, which has the effect of completely silencing any error messages
EDIT: Re-reading this, I realized that you're probably asking more about the mechanics of how this command accomplishes its task, rather than how the "find" command interprets its command-line options. Sorry if this didn't answer the real question...
> 9. I believe that at least two of the three files that were modified were in the /etc/ folder
You can simply run "ls -ltr /etc
" and the most recently changed files will be at the bottom of the listing.
For a recursive search, use something like:
find /etc -mtime 0 -print
See: www.gnu.org/software/findutils/manual/html_node/find_html/Age-Ranges.html#Age-Ranges.
And you might want to look into using something like <code>etckeeper</code> in the future. Good luck!
If you're only going to use a value once, assigning it to a variable seems like overkill. Can you assume BASH? Because then: wiki.bash-hackers.org/syntax/expansion/cmdsubst.
Also, using ls
is problematic for a number of reason, but mostly because it was never intended to produce output suitable for piping into some other utility.
There are better ways to generate a list of files for piping; see www.gnu.org/software/findutils/manual/find.html.
If the action you want is still copying files, I was wondering if you might-could use rsync
to do this, since rsync
recurses directories:
rsync -aPh --include="*/" --include="*.mobi" --exclude="*" --prune-empty-dirs . ~/mobi-files/
Oh, and even though the -exec
action of find
is blocked, the -execdir
action may still be available, since -exec
is less secure than -execdir
. The problem with -execdir
is that find
is particular about paths when using it. See: www.gnu.org/manual/find#Single-File.
http://www.gnu.org/software/findutils/ Hopefully the early-90s UNIX had installed gnutils that weren't invented yet. +1 for gumption tho :)
http://doc.cat-v.org/unix/find-history Find wasn't introduced until v7-ish. Unix was made out of crazy, especially the different variants. Linux was freaking awesome because, finally, standardization omg.
tl;dr IF Linus != helped AND you != way too old AND raptors == 1 THEN self.marinade
You should be able to use <code>find</code> and some parameter-expansion fu to do that.
>what is the proper command to change all files, including in sub folders, to rw-r-r?
For reference: 13.3 <code>chmod</code>: Change access permissions.
But you can't use recursion (chmod -R
) with octal permissions, because, as you found out, you want the files to have different permissions than the directories. So, presumably you need the GNU Find Utilities.
Use -type d
for directories, and -type f
for files.
Anytime you want to operate of files recursively, you probably want to use find
. Re: www.gnu.org/software/findutils/manual/html_node/find_html/Delete-Files.html#Delete-Files
find /path/to/directory -type f -iname "*" -delete
You should check out: GNU Find Utilities. Short answer is:
find ~/ -type f -iname "a" -print
And this is just generally useful, IMO: Core GNU utilities manual.
Nooo... -type f - this will only delete "regular files" as per your quoted scenario.
Directories aren't of this type, but find will recursively scan through them to try to find regular files.
The different types are listed here:
http://www.gnu.org/software/findutils/manual/html_mono/find.html#Type
Note how dot-files (hidden) aren't a differentiated type, they're sort of a meta type that some end-user apps may (ls), or may not (find), obey simply because they start with '.'.
Also, see the info manual for the GNU Findutils: info find.info
Info manuals for GNU software are usually a much better read than the corresponding man pages.
edit: you may prefer other formats if you're unfamiliar with info
.
Do get acquainted with it, though.
It's a great source of online documentation.
it's a security (no race conditions) and efficiency (no forks) thing; there's a nice writeup on deleting files with find in the info
manual to GNU find
. (they also say that -delete
(and -execdir
) come from BSD, so they may be in some non-GNU find
s as well.)