Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7490291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:34:39+00:00 2026-05-29T15:34:39+00:00

How can I write a bash script on Linux to determine which files in

  • 0

How can I write a bash script on Linux to determine which files in two directories have different permissions?

For example, I have two directories:

fold1 having two files:

 1- file1 (-rw-rw-r--)  
 2- file2 (-rw-rw-r--)

fold2 having same-name files with different permissions:

1- file1 (-rwxrwxr-x)  
2- file2 (-rw-rw-r--)

I need a script to output the file names that have different permissions,
so the script will print only file1

I am currently checking the permissions manually by displaying the files with:

for i in `find .`; do ls -l $i ls -l ../file2/$i; done
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:34:40+00:00Added an answer on May 29, 2026 at 3:34 pm

    Parsing find . output with: for i in $(find .) is going to give you trouble for any filenames with spaces, newlines, or other perfectly normal characters:

    $ touch "one file"
    $ for i in `find .` ; do ls -l $i ; done
    total 0
    -rw-r--r-- 1 sarnold sarnold 0 2012-02-08 17:30 one file
    ls: cannot access ./one: No such file or directory
    ls: cannot access file: No such file or directory
    $ 
    

    Since permissions can also differ by owner or by group, I think you should include those as well. If you need to include the SELinux security label, the stat(1) program makes that easy to get as well via the %C directive:

    for f in * ; do stat -c "%a%g%u" "$f" "../scatman/${f}" |
        sort | uniq -c | grep -q '^\s*1' && echo "$f" is different ; done
    

    (Do whatever you want for the echo command…)

    Example:

    $ ls -l sarnold/ scatman/
    sarnold/:
    total 0
    -r--r--r-- 1 sarnold sarnold 0 2012-02-08 18:00 funky file
    -rw-r--r-- 1 sarnold sarnold 0 2012-02-08 18:01 second file
    -rw-r--r-- 1 root    root    0 2012-02-08 18:05 third file
    
    scatman/:
    total 0
    -rw-r--r-- 1 sarnold sarnold 0 2012-02-08 17:30 funky file
    -rw-r--r-- 1 sarnold sarnold 0 2012-02-08 18:01 second file
    -rw-r--r-- 1 sarnold sarnold 0 2012-02-08 18:05 third file
    $ cd sarnold/
    $ for f in * ; do stat -c "%a%g%u" "$f" "../scatman/${f}" | sort | uniq -c | grep -q '^\s*1' && echo "$f" is different ; done
    funky file is different
    third file is different
    $ 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I write a Linux Bash script that tells me which computers are
I want to write a sh/bash script that can determine whether a particular directory
I'm trying to write a bash script that can edit itself. The line of
How can I write a bash script to list directory entries in the svn
I want to write a bash script that (recursively) processes all files of a
I'm trying to write a bash script which will, given the name of a
I want to write a Java method which reads in a bash script into
I want to write a bash script that I can run in a directory
In a bash script, I can write: exec 2>&1 exec someprog And the stderr
i'm trying to write a SVN pre-commit hook script in Linux Bash that will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.