1

I was working on a lab and was having trouble with the function of part of a command we are supposed to learn. Here it is:

find . -name "*.txt" -exec ls -l {} \;

I have determined that the find . -name "*.txt" is finding all files in the current directory with the extension .txt, however I am not sure what -exec ls -1 {} \; is doing within the command. Any help or basic explanation would be much appreciated.

1 Answers1

1

If we split this by parts:

find . -name "*.txt" -exec ls -l {} \;
  • find . = Find all files/directories starting from the current directory
  • -name "*.txt" = Filter only files/directories with names ending in *.txt
  • -exec = Execute the following command for each file
    • ls -l {} = Run ls -l ({} gets substituted with the name of the file)
    • \; = end of command
Stewart
  • 13,677