Have You Ever found a need to find a file for a particular pattern and then edit the same ??
Here is an easiest way....
At the UNIX prompt, Just type:
vi `find . -name "*" -exec grep -l "pattern" {} \; -print`
Where "pattern" is the string to be searched.
Renameing files with the find command
I am attempting to rename files in a directory tree, using the find
command:
find . -name "file-src*" -exec mv {} file-tgt \;
however, this only moves the file to the current dir: I have also
tried:
mv 'find . -name file-src' file-tar
find . -name "file-src*" -exec mv {file-tgt} \;
etc, but to no avail.
There might be better ways to do this.
for i in `find your_dir -type f -name '*'`
do
mv $i $i.mv
done
I've tried this statement, however I still get the syntax error for the move command; when I replace the mv with echo $i; it writes out the find argument.
e.g. with the move cmd:
for i in 'find . -type f -name "file*" '
do
mv $i $i.bak
done
Output is:
$mv: invalid option
and the echo $i
for i in 'find . -type f -name "file*" '
do
echo $i
done
'find . -type f -name "file*"
Are you using single quotes, or backticks? ' or `
Backticks will do what you want. (It's the ` character on the upper-left
corner of a standard PC keyboard, usually with the ~ )
If you're using a shell like bash or ksh, you could do it like this:
[...] for each in $(find . -name blah) [...]
But most shells will recognize:
[...] for each in `find . -name blah` [...]
Dont use ' (single quote). Use ` (dont know what it is called but it
is left to the '1' key on the key board and above 'TAB')
Good stuff -that works fine. Yah I've had some problems using the ' and ` with commands in the past ....
Return to : Unix System Administration
Hints and Tips