Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

UNIX – List Files With Permissions In CHMOD Numbers

Posted on January 24, 2017April 13, 2020 By David Kittell

If you’re on UNIX you know ls will list files in a directory but typically you’ll get something like

$ ls
dns  index.html  info.php
$ ls -la
total 20
drwxr-xr-x. 3 webadmin www-data 4096 Jan 24 11:41 .
drwxr-xr-x. 4 webadmin www-data 4096 Jan 24 08:13 ..
drw-r--r--. 2 webadmin www-data 4096 Jan 24 09:31 dns
-rw-r--r--. 1 webadmin www-data 2199 Jan 24 08:14 index.html
-rw-r--r--. 1 webadmin www-data   19 Jan 24 10:25 info.php

You can simily stat the file(s) with the below

# On Mac
stat -f "%OLp" <file>

# On Ubuntu (or most Linux/Unix servers)
stat --format '%a' <file>

# On Busybox
stat -c '%a' <file>

What if we work with stat and make it easier?

# UNIX
sudo cp /etc/bashrc /etc/bashrc.original
echo "alias lsc='stat -c \"%a %A \$s %U:%G %y %n\" *'" | sudo tee -a /etc/bashrc
# MAC OS X
#alias lsc='stat -f "%A %t %Su:%Sg %t %Sm %t %N" *'
lsc
$ lsc
644 drw-r--r--  webadmin:www-data 2017-01-24 09:31:15.077301144 -0500 dns
644 -rw-r--r--  webadmin:www-data 2017-01-24 08:14:03.161307507 -0500 index.html
644 -rw-r--r--  webadmin:www-data 2017-01-24 10:25:42.844728348 -0500 info.php
Originally Posted on January 24, 2017
Last Updated on April 13, 2020
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

CentOS Code Fedora Mac OS X Shell Mac OSX Red Hat Ubuntu UNIX UNIX Shell Scripts

Post navigation

Previous post
Next post

Related Posts

PHP – Create Dynamic Breadcrumb

Posted on December 21, 2015February 12, 2016

<?php /* Credit goes to Dominic Barnes – http://stackoverflow.com/users/188702/dominic-barnes http://stackoverflow.com/questions/2594211/php-simple-dynamic-breadcrumb *\ // This function will take $_SERVER[’REQUEST_URI’] and build a breadcrumb based on the user’s current path function breadcrumbs($separator = ‘ &raquo; ‘, $home = ‘Home’) { // This gets the REQUEST_URI (/path/to/file.php), splits the string (using ‘/’) into an…

Read More

NetSuite – SuiteScript 2.0 – Useful Functions

Posted on August 31, 2018

These first function snippets are from https://gist.github.com/W3BGUY /** * @NApiVersion 2.x * @NScriptType ScheduledScript * @NModuleScope SameAccount * * According to the documentation this is a read-only field. According to this working code and a verification from * NetSuite tech support, the documentation is wrong. Hope this helps someone out….

Read More

PowerShell – Backup Windows Drivers

Posted on October 21, 2016

Prerequisite: Must have PowerShell 5.0 or higher This will backup all 3rd party drivers in a Windows based computer. clear if ($PSVersionTable.PSVersion.Major -lt 5) { Write-Output "Your version of PowerShell is not supported please upgrade to 5.0 or higher" } else { $ExportDirectory="$($env:USERPROFILE)\Desktop\DriverBackup" Write-Output "Creating temporary directory for the driver…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes