Solved

Maybe an awk command is enough

Posted on 2001-06-30
3
171 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

705 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

19 Experts available now in Live!

Get 1:1 Help Now