Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

I must parse ls -Al output and get file or directory name

ls -Al output :

drwxr-xr-x  12 s162103  studs         12 march 28 2012 personal domain
drwxr-xr-x   2 s162103  studs          3 march 28 22:32 public_html
drwxr-xr-x   7 s162103  studs          8 march 28 13:59 WebApplication1

I should use only ls -Al | <something>

for example:

ls -Al | awk '{print $8}'

but this doesn't work because $8 is not name if there's spaces in directory name,it is a part of name. maybe there's some utilities that cut last name or delete anything before? I need to find any solution. Please, help!

share|improve this question

marked as duplicate by manatwork, jordanm, jasonwryan, Renan, vonbrand Mar 30 '13 at 19:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
It's also cross-posted to stackoverflow.com/questions/15721925/… –  jordanm Mar 30 '13 at 18:47

1 Answer 1

You should never attempt to parse ls for a list of filenames. The bash wiki has an entire article about why you shouldn't parse the output of ls. Having files with spaces is one of the biggest reasons.

You want to use a glob instead:

printf '%s\n' *

Your question only indicates that you want to print the filename, but I suspect you also want to take an action on it. In that case, you want to iterate over the glob:

for f in *; do
    somecommand "$f"
done
share|improve this answer
    
dupe from stackoverflow stackoverflow.com/questions/15721925/… –  tink Mar 30 '13 at 19:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.