0

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 '-').

4
  • 3
    Please don't paste screenshots of text; post the actual text...
    – jasonwryan
    Commented Nov 24, 2014 at 20:20
  • 1
    If you want to filter out the -s, then append to the end of your command ...| sed 's/-//g'. sed is a tool used to edit inline a stream of text, s/foo/bar/g means to replace all instances of foo with bar (in this case, nothing), and the final g means to do so globally.
    – DopeGhoti
    Commented Nov 24, 2014 at 20:25
  • Hi and welcome to the site. Please edit your question and 1) replace the screenshot with a copy/paste of the actual text (see here for help on formatting your post) 2) Show us the output you want. Don't describe it, give us an actual example that we can produce for you.
    – terdon
    Commented Nov 24, 2014 at 20:27
  • Another way to filter out the dashes is | tr -d -, which is a little bit like tr - "\0" except it doesn't insert nul bytes, it just deletes the dashes. Commented Nov 24, 2014 at 23:29

3 Answers 3

3

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).

2

Alternative way without ls:

getfacl -c partition | sed -n '/group::/{s/.*:://;y/rwx/cse/;s/-//g;p;}'
1

Another alternative (piping two tr commands):

ls -l partition | cut -c5-7 | tr -dc rwx | tr rwx cse

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .