MacIssues

How to use, troubleshoot, and repair your Mac

Skip to content
  • Main
  • Troubleshooting
    • Hardware
  • How-To
    • Core OS X
    • Printing and Peripherals
    • Sharing Services
    • Applications
    • Hardware
  • Reviews
  • About
  • Forum
  • Store
MacIssues

How to get file information from the command line in OS X

NewTerminalIconXWhen you are browsing your files in the OS X Finder, you will have a number of options for telling you what the file is. For starters, most files have an icon that represents the program that will open it, and then you can click the file and press Command-i to get information on it. When managing file in the OS X Terminal, if you are relatively new to the Terminal you may think the only identification for a file is its name (ie, a “.txt” suffix for a text file); however, there are several tools you can use to see quite a bit of information about a file.

When viewing information about files in the Finder, most of the information is from metadata that is just organized on a pretty interface, but this information is also available in the command line.

First, the basics about a file including its creation and modification dates, size, and access permissions, which are found by the “ls” command for listing items. With the following uses of the command, you can list this information about the targeted file. The first command will output modification dates and times for files, whereas the second will do so for creation times.

ls -l /path/to/file
ls -lU /path/to/file
file information using the ls command

The classic “ls” command with the long-format flag will give you size and modification or creation time information about a file.

If you are wondering what kind of file you are dealing with, you can use the “file” command, which is quite informative with its basic usage to tell you information such as the file being a text, html, or xml document, or for images tell you details such as resolution and bit depth:

file /path/to/file
file format information in the OS X Terminal

The “file” command can be used to get quick information about the formatting of a file, as opposed to its on-disk attributes.

The options so far only outline non-metadata attributes for a file, but you can also see a lot of information that OS X and other programs store in the file’s metadata by running the following command to list metadata attributes for the file:

mdls /path/to/file
metadata attributes seen in the OS X Terminal

If your file has metadata associated with it, then you can view them using the “mdls” command.

The details output by this command will be a list of metadata keys and their values. These will include details like file size, name, content type, image size and resolution, among many others. Note that metadata is intended for quick access to file information; however, it is maintained my services separate from the file and could be incorrect. For instance, there is nothing that prevents file size metadata from being different from a file’s size on disk. For the most part, system services keep this information up to date, but changes that do not invoke these services could require them to run in order to keep the metadata up to date.

A last metadata-handling routine is viewing and managing the extended attributes for files, which are metadata entries that set system functionality options as opposed to more content-based information. For the most part you will likely not need to interact with these beyond simply listing them, and perhaps deleting them from a file. To list them, you can run either of the following two commands:

ls -l@ /path/to/file
xattr -l /path/to/file
Extended attributes content listings in the OS X Terminal.

Extended attributes in OS X will likely only contain information that’s useful for power users.

Finally, as with any file the ability to read its content will also tell you information about the file. If in using the above options you have determined the file contains text (ie, its format is XML, HTML, CSV, TXT, or similar), then you can at least preview its contents in the Terminal by opening it in a Terminal-based text editor or concatenating its contents to the Terminal output, done with the following two commands:

nano /path/to/file
cat /path/to/file

Share This:

  • Print
  • Email
  • Facebook
  • Twitter
  • Google
  • LinkedIn
  • Reddit
  • More
  • Tumblr
  • Pinterest
  • Pocket

Like this:

Like Loading...

Related

This entry was posted in How-To and tagged extended attributes, ls, mdls, metadata, Terminal, xattr on January 19, 2016 by Topher Kessler.

Post navigation

← Tips and tricks for increasing the use of the OS X Console Overcome the OS X Dock getting stuck on a second monitor →

SUBSCRIBE AND FOLLOW

Facebooktwittergoogle_pluspinterestrsstumblrFacebooktwittergoogle_pluspinterestrsstumblr

E-Mail:

Help Support MacIssues!

New and Noteworthy Articles

  • Dos and Donts for managing data on external hard drives May 18, 2016
  • How to manage inactivated e-mail accounts in OS X May 8, 2016
  • How to enable screen sharing services remotely in OS X April 26, 2016
  • How to manage “No Backup for XX Days” warnings in OS X April 20, 2016
  • Using the OS X crash reporter to diagnose a program failure April 12, 2016

Search MacIssues

Submit a Question, Tip, or Fix

Time limit is exhausted. Please reload CAPTCHA.

Recent Comments

  • Robert C on Tackle external hard drives randomly ejecting in OS X
  • Rajesh on Will your Mac run Microsoft Office 2016?
  • Joe on How to fix deep formatting problems with OS X drives
  • MaX on Dos and Donts for managing data on external hard drives
  • Marcel van Osch on Fix About This Mac not showing proper disk space

Archives

  • May 2016 (2)
  • April 2016 (7)
  • March 2016 (4)
  • February 2016 (3)
  • January 2016 (4)
  • December 2015 (8)
  • November 2015 (11)
  • October 2015 (18)
  • September 2015 (15)
  • August 2015 (16)
  • July 2015 (19)
  • June 2015 (21)
  • May 2015 (23)
  • April 2015 (28)
  • March 2015 (27)
  • February 2015 (27)
  • January 2015 (31)
  • December 2014 (25)
  • November 2014 (25)
  • October 2014 (37)
  • September 2014 (30)
  • August 2014 (24)
  • July 2014 (27)
  • June 2014 (29)
  • May 2014 (35)
  • April 2014 (59)
  • March 2014 (28)

SITE NEWS

• MacIssues Amazon Store is live
• MacIssues is in Progress

Links and Friends

• MacIssues Forums
• iFixIt
• The Safe Mac
• Hervey Bay Mac User Group

Tags

Activity Monitor Apple Apple Watch App Store battery Disk Utility Dock e-mail El Capitan encryption FileVault Finder Hard Drive hotkey iCloud iOS iOS 8 iPad iPhone iTunes keyboard Keychain Mac Macbook Pro Mail malware Messages Network OS X OS X 10.10 OS X 10.11 password Permissions preview Safari Security Sleep software update Spotlight Terminal Text Thunderbolt Web browser Wi-Fi Yosemite

BLOG CATEGORIES

Advertise on MacIssues

More Information
Proudly powered by WordPress
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.
%d bloggers like this: