LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   how to list system users (http://www.linuxquestions.org/questions/linux-general-1/how-to-list-system-users-474936/)

ygloo 08-17-2006 07:01 PM

how to list system users
 
how to list existing users??
i try to write a bash script to remove thumbnails from $HOME directory...
and i need a way to list users

Ehwaz 08-17-2006 07:14 PM

Logged in users or all users?

Logged in users would be easy, not all users. Still, you could check the /etc/shadow file and retrieve the users from there.

Tinkster 08-17-2006 07:26 PM

Quote:

i try to write a bash script to remove thumbnails from $HOME directory...
Why that complicated?
Code:

find /home -name ".thumbnails" -exec rm -rf {} \;
No need to hunt for names (unless some users have their home
not under home but in some strange location), in which case you
could just go
Code:

awk -F: '$3 > 99 {print $6}' /etc/passwd
to find them ...

Cheers,
Tink

ygloo 08-17-2006 07:34 PM

awk -F: '$3 > 99 {print $6}' /etc/passwd
what is "'$3 > 99" ??

Tinkster 08-17-2006 07:40 PM

Make sure that it only lists users that are "human". In Slackware,
all system users (not people) have a UID < 100 ... may vary for
your system, have a look at /etc/passwd. But if you DON'T have people's
in other directories than home, why bother? :) Just use the find.

Or, even more easy (just thought of that now) :}
Code:

rm -rf /home/*/.thumbnails

Cheers,
Tink

ygloo 08-17-2006 07:46 PM

i like this one -
find /home -name ".thumbnails" -exec rm -rf {} \;

Tinkster 08-17-2006 08:26 PM

I'm curious: why do you prefer the more I/O and CPU intense solution over
the plain one that uses shell globbing?


Cheers,
Tink

ygloo 08-17-2006 08:31 PM

wanna learn commands

Tinkster 08-17-2006 08:34 PM

Good enough reason, I guess. And: good on yah! :)


Cheers,
Tink

ygloo 08-17-2006 08:48 PM

i try to delete files not accessed for 7 or more days

Tinkster 08-17-2006 08:57 PM

Code:

find /home/ -atime +7 -type f -regex ".+\/.thumbnails/.+" -exec rm {} \;

Cheers,
Tink

ygloo 08-17-2006 09:04 PM

+\/.thumbnails/.+" means include path??

Tinkster 08-17-2006 10:23 PM

It's a regular expression against which all found files (including
their path) are matched; you said you only wanted to delete files which
hadn't been accessed in a week from the .thumbnail directory of any user.

What our find does is to search for all files (-type f) under /home that
have the component /.thumbnails/ in their path (.+ means one or more character)
and that have and access time of over a week (-atime +7).

It does NOT search for a path that looks like that.


Cheers,
Tink

ygloo 09-13-2006 06:22 AM

combined these two
rm -rf /home/*/.thumbnails
find /home -name ".thumbnails" -exec rm -rf {} \;

find /home/*/.thumbnails -atime +7 -type f -exec rm -rf {} \;


All times are GMT -5. The time now is 07:10 AM.