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 ...
- 09-16-2008 #1Just 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:
I want to be able to break apart each segment, so for example I could just reference "-rwxrwx---".Code:-rwxrwx--- 0 hygelac csmajor 0 Sep 15 21:22 mytext.txt
I tried
But that didn't workCode:ls -l mytext.txt | head -1
- 09-16-2008 #2
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:
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.Code:tanya:~ alex$ echo "hello there" | cut -d' ' -f1 hello
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


Reply With Quote