Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Maybe an awk command is enough

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AIX Server 10 87
Linux : can't create transaction lock error 1 76
OpenLDAP Proxy to Active Directy 6 363
Unix Question 19 50
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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 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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

840 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