Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Delete directory from ghost owner with awk Post 302548280 by macguy on Thursday 18th of August 2011 05:11:51 AM
Old 08-18-2011
Quote:
Originally Posted by vbe
These ghosts user users as you call them seem to be past defined users removed from the passwd file but where you chose NOt to remove their files... You should be able to extract all defined users and compare with the home directory (what is not in passwd is old and so you see the affected UID given at the time)
Hi!

I'm not exactly sure how you mean now. I know, it's strange that when I delete an account in workgroup manager, the home directory for that user doesn't removes. So that is why I need a script to delete this numbered owners on the server.

I don't think I can do this on an easier way than to delete the user home directories with some script... But I need help do do this.

EDIT

This seems to be more difficult than I first thought. But I have some idea how to do this.
With this script ls -la | Awk '{print $3" "$9}' | grep '[0-9][0-9][0-9][0-9]'

I get this result:
5074 AbdMow1121
5248 AdaChr0814
5196 AdrLuk0908
1355 AgnBr02
5276 AgnHel0616
AgnMat0422 AgnMat0422
5274 AhmHas0101
AidHod0126 AidHod0126
5288 AidJac0313
1104 AleBe11
5242 AleBor1201
5265 AleFor0217
5019 AleHal0502

I'm very near my goal now, the only thing I want to do know is to filter the names from the first column like:
AgnMat0422
AidHod0126
AleNou1112

And so on...

Do someone know any possibility to only focus on the first column with grep so grep doesn't notice about the second column so I only need to type:
ls -la | Awk '{print $3" "$9}' | grep '[0-9][0-9][0-9][0-9]' But are only interested to grep $3 not the $9 column...

---------- Post updated at 09:11 AM ---------- Previous update was at 07:00 AM ----------

I solved the problem myself:
I was very near the solution but forget the ^ in the beginning of the grep syntax. Here is the code to delete this user directories:
Code:
for i in `ls -la | Awk '{print $3" "$9}' | grep '^[0-9][0-9][0-9][0-9]'` ; do rm -rf $i; done

Smilie

Last edited by vbe; 08-18-2011 at 10:01 AM.. Reason: use code tags please for code and data
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

determine owner directory permissions from within the directory

From within a directory, how do I determine whether I have write permission for it. test -w pwd ; echo ? This doesn't work as it returns false, even though I have write permission. (4 Replies)
Discussion started by: Sniper Pixie
4 Replies

2. UNIX for Dummies Questions & Answers

ghost file, delete help

I'm trying to delete a folder in my trash that contains no files or hidden files and nothing happens. It is still there. However, when I try to delete everything in the folder in terminal I receive an error: Ti?ng Viê?t.html: No such file or directory. I can't find this file anywhere on my tiger... (1 Reply)
Discussion started by: jopper
1 Replies

3. Shell Programming and Scripting

to parse a directory and its subdirectories and find owner name of files

hi all, i need to capture all the files in a directory and its subdirectories that have owner name different than the root owner. for one file it is " stat -c %U filename " but i need to search for each and every file and record it. thanks in advance (14 Replies)
Discussion started by: vyasa
14 Replies

4. UNIX for Dummies Questions & Answers

How to display only Owner and directory/sub directory names under particular root

hai, I am new to Unix, I have a requirement to display owner name , directory or sub directory name, who's owner name is not equal to "oasitqtc". (here "oasitqtc" is the owner of the directory or sub directory.) i have a command (below) which will display all folders and sub folders, but i... (6 Replies)
Discussion started by: gagan4599
6 Replies

5. UNIX for Dummies Questions & Answers

Group files by owner and show directory

Hello, i would like to find huge files and group them by owners. To find big files i use this command: ls -lR | sort -bnr +4 | head -n 75 which give me 75 biggest files, then i need to see in which subdirectory is every file. second thing i dont know is how to group those files by owner, could... (6 Replies)
Discussion started by: dealer1985
6 Replies

6. AIX

Unix root directory owner wrong AIX 5.3

The a chown was done and instead of using ./ a / was used and root ownership files got changed. I need to change the ownership of the files/directory back - backups are not working and I am concerned a reboot will not be successful. Can anyone provide the ownership of these files/directories... (6 Replies)
Discussion started by: spike1
6 Replies

7. OS X (Apple)

Logic of owner of directory or file

Would the owner as listed , be the one who made the directory in the first place. when any one could use chown in a script. I do not know where this directory came form or who made it. And am attempting to just find out more info on it. what could i use to find its origins and its why does it... (3 Replies)
Discussion started by: cowLips
3 Replies

8. Solaris

Changing file/directory owner

Hi , I want to change owner of files or folder from 23186 to dsadm, Present ------- -rw-r--r-- 1 23186 gdstage 10240 Oct 31 2007 BLTRS drwxrwxrwx 3 23186 gdstage 512 Sep 1 2010 sql Required as ----------- -rw-r--r-- 1 dsadm gdstage 10240 Oct 31 2007 BLTRS drwxrwxrwx 3 dsadm gdstage... (6 Replies)
Discussion started by: sridhardwh
6 Replies

9. AIX

How to set owner and permission for files/directory in directory in this case?

Hi. My example: I have a filesystem /log. Everyday, log files are copied to /log. I'd like to set owner and permission for files and directories in /log like that chown -R log_adm /log/* chmod -R 544 /log/*It's OK, but just at that time. When a new log file or new directory is created in /log,... (8 Replies)
Discussion started by: bobochacha29
8 Replies

10. UNIX for Beginners Questions & Answers

Is there a way to restrict a user (owner) to execute scripts from a specific directory

Hello, I have a user Bob on a RHEL 7 server1. Where his script area is "/home/Bob/scripts/" and he is the owner for this directory. On the server1, there is a NFS mount from another server2, with path as "/global/work/" and Bob is the owner for this directory too in server2. (Same UID and GID... (5 Replies)
Discussion started by: karumudi7
5 Replies
LOGINS(1)						    BSD General Commands Manual 						 LOGINS(1)

NAME
logins -- display account information SYNOPSIS
logins [-admopstux] [-g groups] [-l logins] DESCRIPTION
The logins utility displays information about user and system accounts. The following options are available: -a Display information about the password change and account expiration times for each account. -d Select accounts with duplicate UIDs. -g groups Select accounts that are members of the specified groups. If multiple group names are specified, they must be separated with com- mas. -l logins Select accounts matching the specified login names. If multiple names are specified, they must be separated with commas. -m Show information about secondary groups. -o Display the information for each account on a single line of colon-separated fields. -p Select accounts with no password. -s Select system accounts. These are currently defined as accounts with UIDs below 1000, plus the ``nobody'' account (UID 65534). -t Sort selected accounts by name rather than by UID. -u Select user accounts. These are currently defined as accounts with UIDs above 1000, except the ``nobody'' account (UID 65534). -x Display information about each account's home directory and shell. If multiple selection options are specified, all accounts matching any of the selection criteria will be displayed. If no selection options are specified, all accounts will be displayed. SEE ALSO
getgrent(3), getpwent(3), group(5), passwd(5), pw(8) HISTORY
The logins utility appeared in FreeBSD 4.10. AUTHORS
The logins utility was written by Dag-Erling Smorgrav <des@FreeBSD.org> based on similar utilities in other operating systems. BSD
March 6, 2004 BSD
All times are GMT -4. The time now is 05:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy