Linuxopsys
Linuxopsys

@linuxopsys

5 Tweets 5 reads Feb 16, 2023
Linux tip of the day 🐧😎
You can use the find command's -exec option to call an external program to perform a specific action on the returned files that match specific criteria. For example, deleting files, listing file perms, and so on.
$ find ~/ -type f -exec ls -lah {} +
This is very useful when performing the same action on multiple files in different locations.
The above command is an example of listing the permissions and other metadata of every file that the find command finds.
A breakdown of the -exec option:
• exec ls - this tells find to execute the ls command on every filename that matches the search string.
• -lah - displays all files, including hidden files, their permissions, and other file metadata, such as sizes, in human readable format.
• {} - The “{}” placeholder represents each filename and must be the last item in the parameter list.
• ; - To indicate the end of the parameter list, a semicolon ";" is used. It must be escaped with a backslash "\" otherwise the shell will interpret it.
You can also use the + instead of the ; to indicate the end of the parameter list. There should be a space between the + and the curly braces "{}".
Follow us (@linuxopsys) for more byte sized Linux tips and be a better informed Linux user 🐧😎

Loading suggestions...