Bash Script - ls-octal.sh - ls + octal permissions

SlowCoder

Gold Member
Gold Supporter
Joined
May 2, 2022
Messages
456
Reaction score
313
Credits
3,611
This is my solution from this thread. Member wanted to list all files in a directory with their octal permissions.
This script performs a ls -l style file list, with the octal permissions in the first column. The output formatting isn't perfect, but gets the point across.

Script:
Bash:
#!/bin/bash

# list all files in current directory, and include their octal permissions

# include hidden
shopt -s dotglob

# iterate
for f in *
do
    echo -n $(stat "$f" -c '%a')" "
    echo "$(ls -ld --color=always "$f")"
done
 


OP
SlowCoder

SlowCoder

Gold Member
Gold Supporter
Joined
May 2, 2022
Messages
456
Reaction score
313
Credits
3,611
If it's ok, I prefer to create a separate thread for my scripts, which will allow conversations to take place without getting lost in the shuffle. I created a post in the new thread, and linked them to get us started.
 

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
6,471
Reaction score
5,727
Credits
52,057
All good. My goal is a thread without much digression, so maybe that'll keep any digression to the threads you made. That'll help!
 
OP
SlowCoder

SlowCoder

Gold Member
Gold Supporter
Joined
May 2, 2022
Messages
456
Reaction score
313
Credits
3,611
Did you mean to post that in this thread:
How about this: I'll put smaller scripts into the main thread, which will help get the thread started. But my larger scripts I'd like to make their own to make conversation easier. Good?
 

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
6,471
Reaction score
5,727
Credits
52,057
Either way works. The main goal is a central place where people can find 'em. So, that works. The secondary goal is to keep it on topic. That remains to be seen!
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Members online


Top