What is a one liner to get the second field of ls -la?

Posted on 2006-03-26
Last Modified: 2010-05-18
I'm looking for a perl one liner to get the second field using ls -la?
Question by:ckaspar
    LVL 25

    Expert Comment

    ls -la | perl -ne 'split; print "$_[1]\n";'
    LVL 6

    Expert Comment

    other option is
    ls -la | perl -ne '/^\s*\S+\s+(\S+)/&&print"$1\n"'
    LVL 84

    Accepted Solution

    ls -la | perl -ne 'print /\S\s+(\S+)/,"\n"'
    ls -la | perl -pe 's/\s*\S+\s+(\S+).*/$1/'

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
    A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now