[Urgent]how to print the file names into a txt file???

HI,

I have a folder with some 120 files...i just want to print all the file filenames(not the content or anything else) onto a file say .txt.

please help me with this command

Thanks a lot.

cd directory; find . -type f > file.txt
ls -1 > file.txt
printf "%s\n" * > txt
echo * > file

find <directory> -type f -maxdepth 1 -print >temp_file

anbu23,,,,

good to know above command

can we know what it does(logic)...pls

just type echo * on the command line and see what happens.

If you want to list the files which have 0 bytes size...then

find . -type f -size 0 -exec ls -l {} \; > temp.txt

check temp.txt file for result

g host dog 74

thanks for your reply..

just i want to know the logic..

echo * > file
  • expands to all the files and directory in the current directory

Thanks a lot for your replies guys.....I really appreciate your timely help....

That will put all the files on a single line, and if there are any filenames with spaces, you will not be able to extract accurate filenames.

Using printf "%s\n" * > txt puts each filename on a new line; it will work for all filenames that do not contain a newline character.

or start with a . (dot)

I checked with file with names like a\b

and it didnt work, as expected !

it works perfectly..

do you have any file(s) in current directory