LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ls command question (https://www.linuxquestions.org/questions/linux-newbie-8/ls-command-question-117531/)

eastj1974 11-18-2003 03:37 PM

ls command question
 
I'm writing a scripts that requires the names and dates of files within a directory.

I could do ls -l to get this information but it also has the owner and rights that I don't need. I thought I could pipe the ls command with a cut command to only get the date and the filename but I can't get it to work.

Does anyone have any suggestions? Thanks.

Tinkster 11-18-2003 04:03 PM

Have a closer look at awk ...

Cut, btw, should be just fine... what's the problem?


Cheers,
Tink

eastj1974 11-18-2003 05:00 PM

I don't know how to use cut. I assume its in the form

ls -l | cut.

but I don't know what options I need to pass to get the last two columns.

Tinkster 11-18-2003 05:22 PM

Heh ... have you tried a
man cut? :)


But really, since cut's delimiter handling is
a bit unwieldy I'd suggest using awk ...

try
ls -l | awk '{printf "%2d %3s %s\n", $7, $6, $9}'

Cheers,
Tink

eastj1974 11-18-2003 05:44 PM

thanks that makes worked. I tried using cut with the ' ' delimiter but it wasn't working well. awk is easier. J


All times are GMT -5. The time now is 11:37 PM.