LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   To find it out (https://www.linuxquestions.org/questions/linux-software-2/to-find-it-out-926820/)

Huamin 01-31-2012 09:56 PM

To find it out
 
Good day all,
I want to find out one log file within “/opt/teamviewer”. How?

[root@localhost 5]# find / -user vivek -name "*.log"
find: invalid argument `vivek' to `-user'

Regards,

catkin 01-31-2012 10:09 PM

Does user vivek exist? You can check by
Code:

grep '^vivek:' /etc/passwd

Huamin 01-31-2012 10:59 PM

Good day,
thanks. Does this mean there is no .log file inside “/opt/teamviewer”?
[root@localhost teamviewer]# find /opt/teamviewer -user root -name "*.log"
[root@localhost teamviewer]#

Regards,

Nominal Animal 01-31-2012 11:12 PM

Catkin, actually that grep will not work when LDAP is used.

The correct way to find out if a user exists is to run
Code:

id -un username
If the user exists, it will output the username (same!). If the user does not exist, it will report an error.

(There is no group equivalent of id although the C libraries do provide the getgrnam() interface that provides the correct information, so checking if a group exists is trickier in a shell script. The way I'd do it, is create a temporary directory (with no access to anybody, mode 0). Then, if env LANG=C LC_ALL=C chgrp 'group' dir 2>&1 returns something that contains invalid group, then the group does not exist. It may return either nothing or an error, depending on whether the user is a member of that group or not. The directory is obviously removed immediately afterwards, and you do need to do this in a directory where you have write access, of course.)

catkin 02-01-2012 12:06 AM

Quote:

Originally Posted by Nominal Animal (Post 4589998)
Catkin, actually that grep will not work when LDAP is used.

Thanks for pointing it out :)

Huamin 02-01-2012 12:12 AM

Thanks. Does the output from find above show no log file in that?

Nominal Animal 02-01-2012 03:06 AM

If user vivek exists, then yes, find / -user vivek will report all files owned by user vivek (whose paths are visible to the current user).

If user vivek does not exist, you get an error message, either something like find: `vivek' is not the name of a known user or find: invalid argument `vivek' to `-user' depending on the find implementation (and locale, of course).

In your case, there is no user named vivek on the system you ran the command on.


All times are GMT -5. The time now is 11:09 AM.