How to print only certain characters?
Solution 1
I think you want this command:
ls -l partition | cut -c5-7 | tr rwx cse |sed 's/-//'
You can remove the one extra command(cut -d ' ' -f 1
) and replace it with your last cut command(cut -c5-7
) and also add sed 's/-//'
at the end to remove all -
s. Now you are done. you didn't need to adding extra |
.
And even better: you can also change the dash(-
character with Null character(\0
) as following):
ls -l partition | cut -c5-7 | tr 'rwx-' 'cse\0'
Replaced -
char with null character(\0
).
Solution 2
Alternative way without ls
:
getfacl -c partition | sed -n '/group::/{s/.*:://;y/rwx/cse/;s/-//g;p;}'
Solution 3
Another alternative (piping two tr
commands):
ls -l partition | cut -c5-7 | tr -dc rwx | tr rwx cse
Related videos on Youtube
laurentiupiciu
Updated on September 18, 2022Comments
-
laurentiupiciu almost 2 years
I have to translate the permissions of a file this way:
r ► c w ► s x ► e
Then, I must extract the group of characters which are related to owner group. Last step is to print that group of characters without "-" (only letters).
I managed to write a command till now:
student@vm-uso ~team2 $ ls -l partition -rw-r--r-- 1 student student 10485760 nov 24 21:04 partition student@vm-uso ~team2 $ ls -l partition | cut -d ' ' -f 1| tr rwx cse | cut -c5-7 c-- student@vm-uso ~team2 $
Forwards, I have to add another '|' in order to print only the letter (without the characters '-').
-
terdon over 9 years
-
Scott - Слава Україні over 9 yearsAnother way to filter out the dashes is
| tr -d -
, which is a little bit liketr - "\0"
except it doesn't insert nul bytes, it just deletes the dashes.
-