Hello,
I want to use the find command inside a directory which has user1, user2, user3 and user4 in the group to either look for files owned by user1 or user2 or user3
or
find files not owned by user4.
The -user option allows me only one name. I tried spaces, comas between user_names but the syntax is returned invalid. I can't find the not_owned option either. The -nouser option is for users not in the /etc/passwd file which is not my case. Checked out google too but cannot find any possibility for multi-user options in the same line. Even tried -user user1 -user user2 -user user3 together but not working. If I can write one 'find' line for all the users, I don't have to repeat it per user.
Any tips or tricks?
On 07/24/2010 01:18 AM, Rony wrote:
Hello,
I want to use the find command inside a directory which has user1, user2, user3 and user4 in the group to either look for files owned by user1 or user2 or user3
or
find files not owned by user4.
The -user option allows me only one name. I tried spaces, comas between user_names but the syntax is returned invalid. I can't find the not_owned option either. The -nouser option is for users not in the /etc/passwd file which is not my case. Checked out google too but cannot find any possibility for multi-user options in the same line. Even tried -user user1 -user user2 -user user3 together but not working. If I can write one 'find' line for all the users, I don't have to repeat it per user.
Any tips or tricks?
find /path/to/dir -user user1 -o -group user2 -not -user user3
this above command with find all files owner by user1 or group owned by user2 but not owned by user3. Because ...
-user matches the owner of the file -group matches the group owner of the file -o is the 'or' operator -not is the 'not' operator
The info pages (I personally prefer using 'pinfo' to browse the info pages) for find are pretty nicely organized. Take a look.
cheers, - steve
On Saturday 24 July 2010 02:18 AM, steve wrote:
find /path/to/dir -user user1 -o -group user2 -not -user user3
this above command with find all files owner by user1 or group owned by user2 but not owned by user3. Because ...
-user matches the owner of the file -group matches the group owner of the file -o is the 'or' operator -not is the 'not' operator
The info pages (I personally prefer using 'pinfo' to browse the info pages) for find are pretty nicely organized. Take a look.
Thanks to all who responded. I had completely overlooked the operator part in man pages. The -not -user uname works just fantastic for my job. The options are fantastic.
What I am doing is that users belonging to the group that owns a folder get write permissions to it but after 10 minutes, the file and sub dir ownership changes to the one user who has write permissions and others from the group get read only with sticky bits and SGID depending on file or dir. Now the data is read only. It is an imitation of the 'paste but not delete' option in NTFS partitions. The find command looks only for files/dirs that are not owned by the main user and changes ownership and permissions accordingly.
On Saturday 24 July 2010 02:18 AM, steve wrote:
find /path/to/dir -user user1 -o -group user2 -not -user user3
this above command with find all files owner by user1 or group owned by user2 but not owned by user3. Because ...
I tried the combination of 2 expressions with ' or' and their combination with a third 'and' for my specific requirement but I did not get the desired search result. Every combination I could think of was tried....first this then that etc. Then on the net I found a delimiter and brackets combination similar to my needs and that query gave accurate results.
find /path -expr1 /( -expr2 -o expr3 /) -exec {}..........
expr1's query is 'anded' with the result of the 'oring' of expr2 and expr3. logically it is 'expr1 and (expr2 or expr3)'.
This delimiter or escape sign '' is a funny thing. In file names with spaces as well as commands, it makes the line continue further but in the find command it is called the escape or delimiter.
On Monday 26 Jul 2010, Rony wrote:
[snip] find /path -expr1 /( -expr2 -o expr3 /) -exec {}..........
This delimiter or escape sign '' is a funny thing. In file names with spaces as well as commands, it makes the line continue further but in the find command it is called the escape or delimiter.
The \ is used to escape characters special to the shell. Space, newline and the open and close brackets all are special. If you use \ to escape a space or a newline, it "extends" the command line (or argument). ( and ) are also special, so you need to escape them too.
The function of \ remains unchanged whichever shell command you're using.
Regards,
-- Raju
On Sat, Jul 24, 2010 at 1:18 AM, Rony gnulinuxist@gmail.com wrote:
Hello,
I want to use the find command inside a directory which has user1, user2, user3 and user4 in the group to either look for files owned by user1 or user2 or user3
or
find files not owned by user4.
The -user option allows me only one name. I tried spaces, comas between user_names but the syntax is returned invalid. I can't find the not_owned option either. The -nouser option is for users not in the /etc/passwd file which is not my case. Checked out google too but cannot find any possibility for multi-user options in the same line. Even tried -user user1 -user user2 -user user3 together but not working. If I can write one 'find' line for all the users, I don't have to repeat it per user.
Any tips or tricks?
$ find /path/of/dir -user user1 -o -user user2 -o -user user3 should work just fine.
HTH.
-- Regards,
Rony.
GNU/Linux ! No Viruses No Spyware Only Freedom.
On Sat, Jul 24, 2010 at 01:18:33AM +0530, Rony wrote:
Hello,
I want to use the find command inside a directory which has user1, user2, user3 and user4 in the group to either look for files owned by user1 or user2 or user3
or
find files not owned by user4.
The -user option allows me only one name. I tried spaces, comas between user_names but the syntax is returned invalid. I can't find the not_owned option either. The -nouser option is for users not in the /etc/passwd file which is not my case. Checked out google too but cannot find any possibility for multi-user options in the same line. Even tried -user user1 -user user2 -user user3 together but not working. If I can write one 'find' line for all the users, I don't have to repeat it per user.
Any tips or tricks?
Try if it accepts regex style inputs like - "-user [[user1,user2]]" Not completely sure of this... you would like to read the man page of regex first (that is if you have not done so already :P )