print all filenames in directory with path to another file

hi,

i have a directory at

/path/unix

with the following files

1.txt
2.txt
3.txt
4.txt

I want to make another file called

filenames.txt

at a different location called /path/home. So, my output file would be

/path/home/filenames.txt

with contents

/path/unix/1.txt
/path/unix/2.txt
/path/unix/3.txt
/path/unix/4.txt

I tried the following code

ls -d $PWD/* > /path/home/filenames.txt

It is giving me an error saying

-bash : /bin/ls: Argument list too long

Try..

find /path/unix -type f >  /path/home/filenames.txt
1 Like