2

I have 2 backup files but they have 2 different colors? So what is different between red file and green file in Terminal (macOS) enter image description here

terdon
  • 242,166
HIẾU
  • 21
  • 1
  • 1
  • 2
  • if you type ls -l instead of just ls then you will probably find a difference in the permissions for the files with different colours. – symcbean Feb 23 '23 at 22:09

2 Answers2

2

The correct answer depends on what coloring scheme is adopted by your shell, but I think it is possible to explain the behavior you experience from some general considerations:

  • The colors used in the output of ls are based on the file type (usually identified by their extensions, e.g. .png, .zip, etc.) and the file/directory access permissions.
  • On many Linux systems, the color red is used for either
    • symbolic links that point to a non-existent file (not likely the explanation in your case)
    • compressed files like .zip, .gz and .bz2
  • The color green on the other hand is usually used for files that have the "execute permission" set. Note that on "permission-agnostic" file systems such as FAT32 (very common on USB sticks), the "executable" bit is set by default, i.e. all files stored on such a file system are marked as executable.

If more than one of these conditions apply in a "conflicting way", the result depends, but usually, the "permissions" settings take precedence over the "file type" settings.

In your case, the explanation is probably the following:

  • Most files in your backup directory were copied from a "permission-agnostic" filesystem with either cp -p or rsync -a, i.e. in a way that preserves the file permissions, and have the "execute" bit set. This is why they are all colored in green on your ls output.
  • The one .tar.gz file colored in red came from a filesystem where the "execute" bit is not set by default, and doesn't have that bit. Then, the coloring is performed according to file type, and therefore the file is colored in red as it is a compressed file.

If you are interested in learning more, you can take a look at

AdminBee
  • 22,803
0

On my Mac the red filename was caused by the file being executable, which you can change with chmod -x my_file.

Noumenon
  • 101