Say I have the following output from
drwxr-xr-x 2 root root 4096 Apr 7 17:21 foo
How can I automatically convert this to the format used by
$ echo drwxr-xr-x | chmod-format 755
I'm using OS X 10.8.3.
Some systems have commands to display the permissions of a file as a number, but unfortunately, nothing portable.
If you want the permissions expressed in octal, you need:
BSDs (including Apple OS/X) have a
GNU find (from as far back as 1990 and probably before) can print the permissions as octal:
Later (2001, long after
Long before those, IRIX already had a
Again, when there's no standard command, the best bet for portability is to use
You can ask GNU
So in your case:
Or you can even automate it by formatting
The above solution will also work for multiple files if using a wildcard:
Will work correctly with file names containing whitespace characters, but will fail on file names containing single quotes.
I once came up with:
(more as an exercise in
This command on Mac under sh
if you only want the numeric permission, use %Lp only.
The 700 is the numeric permission which can be used in chmod, and Desktop is the filename.
If your goal is to take permissions from one file and give them to another as well, GNU
Here is a script, which does exactly that:
An alternative, if you want to save the permissions away, to restore them later on, or on a different file is to use
(on Solaris, use
However, though they are available on some BSDs, they are not on Apple OS/X where the ACLs are manipulated with
On Mac OS X (10.6.8) you have to use
To just translate a symbolic permission string produced by