Find the answer to your Linux question:
Results 1 to 2 of 2
Hey, I know there is a way to do this because I did it the other day but now for the life of me I can't remember how to, or ...
  1. #1
    Just Joined!
    Join Date
    Sep 2008
    Posts
    6

    Extracting file permissions

    Hey,

    I know there is a way to do this because I did it the other day but now for the life of me I can't remember how to, or find it through google. Basically, I want to extract segments from some output, specifically when I do a ls -l. For example, my output looks like:

    Code:
    -rwxrwx--- 0 hygelac csmajor 0 Sep 15 21:22 mytext.txt
    I want to be able to break apart each segment, so for example I could just reference "-rwxrwx---".

    I tried

    Code:
    ls -l mytext.txt | head -1
    But that didn't work

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    So what head does is to print the first N lines of its input. So that's not what you want.

    You are looking for a utility called cut. cut allows you to split input based on some delimiter (the default is a tab) and print out the fields that you want. So for instance:
    Code:
    tanya:~ alex$ echo "hello there" | cut -d' ' -f1
    hello
    The -d flag allows me to set the delimiter that I want (in this case, a single space). The -f flag allows me to set what fields I want to be printed. See the man page for more information.

    I hope that helps! If you're trying to do more complicated field-splitting, you can use a tool like awk, but that is major overkill for this.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...