Solved

Maybe an awk command is enough

Posted on 2001-06-30
3
190 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
[X]
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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
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…
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.:

724 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