There is a chmod command to set file permissions, but can I get file permissions in octal mode (such as 755) from the command line?
You can try
From the man page of stat,
File permissions in Linux can be displayed in octal format using Linux stat command.
Just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, Navigate to the directory where you want to find the file permissions in octal mode.
%A Access rights in human readable form
%a Access rights in octal
%n File name
As detailed in “755”-style permissions with ‘ls’ by Adam Courtemanche on AgileAdam.com, you can create an alias
This has a serious shortcoming, though, as techtonik points out. You cannot pass arguments to this
The fix is to define
If you're trying this out interactively in your shell, run
Why does this work? Unlike aliases, bash shell functions can take positional parameters, i.e., command-line arguments.
Since you can pass options to
1One may note this seems to flaunt the general rule about not parsing output from
Just extending\simplifying previous 'stat' related answers:
You can simply run:
The output will contain octal permission along with other info.
Note the: (0644/-rw-r--r--)
For portability, you can use
If you want to notice when an error occurs, try: