Sending file name via |

L

Lukasz

Guest
Hi,

I have a problem with a chmod command.

I want to find a file in my home directory that contains "o" as second character with find command and then change its permission for 222.

I've tried using:
find /home/lukasz -type f -name "?o*"|chmod 222
But I've received error that chmod didn't get file name.

How can I forward file name from find to chmod?

Lukasz
 


R

ryanvade

Guest
The CHMOD command works with the file being listed last by default..
Code:
chmod [OPTION]... MODE[,MODE]... FILE...
 
M

MikeyD

Guest
You can do it all with one find command:

Code:
find /home/dir -name "?o*" -exec chmod 222 '{}' \;
This however will apply chmod to ALL files the find command finds so beware. Often by default find will look recursively within all folders in the base directory.
 
L

Lukasz

Guest
Thank you guys. Both commands worked as I've wanted. I completely forgot about -exec option. :) It was an exercise that our teacher gave us before test and I also think this exercise is senseless because it changes all found files, just as MikeyD wrote, but who understands teachers? :)
 


Members online


Latest posts

Top