Find the user with less number of files in the system


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find the user with less number of files in the system
# 1  
Old 06-18-2010
Find the user with less number of files in the system

Good morning everybody,

I'm using Minix and I want to find the user with less number of files in the system
I have tried this solution:

Code:
#! /bin/sh

indice=0
listaCut=$(cut -f 3 -d : /etc/passwd)
for USER in $listaCut; do
    cont[$[{indice}]=0
    listaFind=$(find / -user "${USER}" -type -f)
    indiceTemp=0
    for FILE in listaFind; do
       cont[${indice}]=$(expr ${indiceTemp} + 1)
    done
    cat /etc/passwd | grep "$USER"
    echo "--------"
    echo "$cont[${indice}]"
    indice=$(expr ${indice} + 1)
done

I wanted to order after because I wanted before to check if it is correct.

Minix shell output is:

Code:
cont[0]=0: no such file  or directory
./primo.sh: Out of space

What is wrong? Smilie
# 2  
Old 06-18-2010
Have a read of this how to assign values to array elements:

Korn Shell Arrays - Assigning and Accessing Values - Part I

Regards
# 3  
Old 06-18-2010
Hi, there were a number of problems with your script. Here it is after a bit of a brush up. You can compare the differences...
Code:
#! /bin/bash
indice=0
listaCut=$(cut -f 3 -d : /etc/passwd)
for USER in $listaCut; do
    cont[indice]=$(find / -user "${USER}" -type f | wc -l)
    grep "^[^:]*:[^:]*:$USER:" /etc/passwd
    echo "--------"
    echo "${cont[indice]}"
    indice=$((indice + 1))
done

# 4  
Old 06-18-2010
MySQL Solved

Solved!!! SmilieSmilieSmilie

My best solution:

Code:
#! /bin/sh

if ls toOrder; then rm toOrder; fi 
if ls listaCut; then rm listaCut; fi
cut -f 1,3 -d : /etc/passwd >> listaCut
echo "Calcolo in corso..."

for USER in $(cut -f 2 -d : ./listaCut); do 
   N=$(find / -user $USER -type f | wc -l)
   echo "User $(grep $USER ./listaCut | head -1): $N files" >> toOrder
done

sort +2 -nr -t: ./toOrder | head -1

# 5  
Old 06-18-2010
It may or may not be of importance to your situation, but be aware that files could be owned by users that do not exist in /etc/passwd; priviliged users can chown a file to any uid regardless of its presence in /etc/passwd.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find all .sh files in file system and need to replace the string inside .sh files

Hi All, I need to write a script to find all "*.sh" files in /home file system and if any string find "*.sh" files with the name vijay@gmail.com need to replace with vijay.bhaskar@gmail.com. I just understood about the find the command to search .sh files. Please help me on this. find / -name... (3 Replies)
Discussion started by: bhas85
3 Replies

2. UNIX for Beginners Questions & Answers

Find number of ACTIVE SSH putty sessions, excluding where the user hopped on to a diff server

Hi - If iam logged on to server A, on 4 putty windows using SSH ... and out of these 4 logged-in sessions, in one of the sessions if i did SSH from server A to server B; i would now have 4 putty windows sessions ... of which 3 are actively logged on to Server A while 1 putty window is actively... (2 Replies)
Discussion started by: i4ismail
2 Replies

3. Shell Programming and Scripting

Counting the number of files within a directory input by the user

So I have a loop that stated if a directory exists or not. If it does it prints the number of files within that directory. I use this code... result=`(ls -l . | egrep -c '^-')` However, no matter which directory I input, it outputs the number "2" What is wrong here? (4 Replies)
Discussion started by: itech4814
4 Replies

4. HP-UX

How to find number of CPU in system

$ uname -a HP-UX chd007d B.11.23 U 9000/800 3154283600 unlimited-user license Thanks (7 Replies)
Discussion started by: Maddy123
7 Replies

5. Shell Programming and Scripting

find a user on the system

i am prompting for a name to search. read user if then however, i get this error: please enter a username on the system: fool menu_script2.sh: line 123: (4 Replies)
Discussion started by: icelated
4 Replies

6. Shell Programming and Scripting

Find user owner of the most recently file in the system

Good evening everybody, I have to find the user owner of the most recently file in the system How can I do? :confused: (5 Replies)
Discussion started by: Guccio
5 Replies

7. Solaris

A strange user appears in my quotas and I can't find it in my system

Hello, I am running a Solaris 8 system. I Have encountered that each time I ask the system to report to me the users who have or are about to exceed their quota limit for disk usage, a strange number appears in a user name, it does not appear in my /etc/group or in my /etc/passwd files The user... (13 Replies)
Discussion started by: lzcool
13 Replies

8. Shell Programming and Scripting

How to do a find number of files in awk

Hi, How can i able to do a similar operation to "find" number of files in a folder in an awk? In bash, we could do easily using "find" command. But currently, I am having an awk block and i wanted to extract these information. Please advise. Thanks. (2 Replies)
Discussion started by: ahjiefreak
2 Replies

9. UNIX for Dummies Questions & Answers

how to find the number of files

hi, 1) I want to find from the current directory the number of files (count) with two or more particular extentions in another directory. For ex: If I am in a/b/c directory... I want to find the count of the files with .txt and .dat extention in a/d/e directory. I have tried using the below... (5 Replies)
Discussion started by: harish409
5 Replies

10. UNIX for Dummies Questions & Answers

Limit number of user accessing to SCO UNIX System

Hi, In my company, we are using SCO UNIX system and Informix database. Recently, there have been a lot of users accessing to server and sometimes it has made server run very slow. So, I intend to limit number of users of 30 only. Although I have tried to search on the Internet for several days,... (1 Reply)
Discussion started by: trinhnguyen
1 Replies
Login or Register to Ask a Question