PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, September 14, 2022

[FIXED] How to save `find -exec` result and used to compare `FILE OWNER`,regardless white space file name?

 September 14, 2022     bash, compare, exec, find, permissions     No comments   

Issue

find . -depth -exec stat --format '%n %U %G' {} + | sort -d > acl_file_old
#some days later,do it again,and then compare
find . -depth -exec stat --format '%n %U %G' {} + | sort -d > acl_file_new
while read FILE OWNER GROUP; do
    while read FILE_NEW OWNER_NEW GROUP_NEW; do
    if [[ $FILE == $FILE_NEW ]]; then
    echo "$FILE"
    break
    done < $result_dir/acl_file_new
done < $result_dir/acl_file_old

Run above bash script,When file name has white space,such as my file here,while read FILE works not well.

I already read similar post1,post2,I know looping over find's output is bad practice.The problem is I need save find -exec result acl_file_old first.

How to save find -exec result and used to compare FILE OWNER,regardless white space file name?


Solution

The read command assigns the words found on the line to the variables.

Note that the last variable is assigned with all the chars remaining up to the end of the line.

The first quick win would be to change the order and make sure that the filename is located at the end with ... -exec stat --format '%U %G %n' {} + ...

Then change the order of the variables to while read -r OWNER GROUP FILE ; do ...

It there are more fancy chars this would be broken anyway. Maybe for (space) it would do the trick ?



Answered By - Jay jargot
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing