What does this mean in my program? -exec ls -s {} [duplicate]
Emily Wong
-exec ls -s is part of my program just want to know what does -s {} mean. This is my whole program, I know what it does:
find $root -type f -exec ls -s {} \; | sort -n | tail -n 15 >> ~/prog.log 0 2 Answers
-exec is an option for find which runs a command using the filenames it found. The syntax of -exec is:
-exec command {} [;|+]The {} is replaced by the name of the files (one file per execution of command if ; is used, multiple files if + is used).
ls -s prints the size of the file along with the filename.
This can be done entirely in find, using the -printf option:
find "$root" -type f -printf "%s %p\n" | ... 2 This command finds files in directory $root, then executes a command on each of them. The command is ls -s filename and {} is the placeholder in the command that is replaced by each of the names of the files found in $root.