Solved

Maybe an awk command is enough

Posted on 2001-06-30
3
174 Views
Last Modified: 2013-12-27
I want to find in a big directory (where  the owner and the file name have the same name) which files have not the same name as owner (in order to correct this situation).


0
Comment
Question by:vage78
3 Comments
 
LVL 3

Expert Comment

by:interiot
ID: 6240928
Sorry, I'm a perl weanie.  Ignore this if you want.

This works:

     ls -l | perl -nale 'print unless $F[2] eq $F[-1]'

There are a couple caveats...  I tested this on a linux box, and the file's owner gets truncated to 8 characters, but the filenames weren't truncated, so this second version is preferable in that case:

     ls -l | perl -nale 'print unless $F[-1] =~ /^$F[2]/'

But then if user 'rj' owns the file 'rjackson', then the second one won't work.  So I guess you could do something like this:

     ls -l | perl -nale 'print unless (length $F[2]<8 && $F[-1] eq $F[2] || $F[-1]=~/^$F[2]/)'

which mitigates the problem slightly, but it's still not possible to solve this fully unless you stat the file directly or convince ls to not truncate the owner's name.

Caveat two:  Outputs of ls on different unicies may use different columns for the file owner.  Column -1 is the last colum, column 2 is the 3rd column.  Monkey with this until the outputs look right:

     ls -l | perl -nale 'print "$F[2]\t$F[-1]"'

the owner is on the left and the filename is on the right.
0
 
LVL 38

Accepted Solution

by:
yuzh earned 15 total points
ID: 6243460
Hi vage78,

   A "find" command will do the job for you:

   cd mybig-dir
    find . -name myfile -user my-user-name -print

   If you need to search the dir own by the other,  then you need to su
as root, and use the above command.

   You can redirect the output to a file:
    find . -name myfile -user my-user-name -print >Filelist

Cheers

   yuzh
0
 
LVL 4

Expert Comment

by:jlms
ID: 6245318
If all your files are directly under your big directory

ls -l | awk '$3 != $9{print $9}'

will do what you need.

You can filter before the | if you require a better input to the awk oneliner (to eliminate subdirs for example) but this should work.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
prtdiag report hdd failure 10 135
Oracle Finace 3 66
How to calculate the current use of PVU on my TSM server. 4 59
Image not there 4 44
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now