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:

Step 1 – basic listing


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 🙁

Leave a Reply

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