Create text or csv file containing only file names from ‘ls -l’ command

What I want to achieve is the creation of a simple text file myfiles.txt that contains the name of each file in one directory. File names should be separated by a line break. 

The content of myfiles.txt should contain file name that look like this:

create file listing only form ls - animated gif

Step 1 – basic listing

returns

Step 2 – remove first line from listing

We remove the first line that says “total 8”

That returns

Step 3 – remove directories

Now all lines that start with “d” (directories) will be removed.

Step 4 – extract file names

awk will return only the 9th block of each line. Blocks are separated by spaces in its default operating mode. Thus returning:

Step 5 – write the file

This will finally create our file!

 

0 Noone thinks it's helpful 🙁

1 Comment Create text or csv file containing only file names from ‘ls -l’ command

  1. Lars Händler

    ls -p | grep -v /
    does the same but way shorter … thanks to Sven for the supplying this solution

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *