How to use find In Linux
Here, the command find initiates a search and allows actions to be performed based on the search results.
Syntax:
find dir1 dir2 /home/kalilinux/dir3 -maxdepth 0 -exec cp xyz.txt {} \;
Were,
- dir1 dir2 are the folders name and /home/kalilinux/dir3 is the directory name with its proper location where we want to perform the copy action.
- -maxdepth: Set the maximum number of levels (like here we have set 0) that find will descend into a directory tree when performing tests and actions.
- -exec: It is used to perform User-defined actions. In addition to the predefined actions, we can also invoke arbitrary commands with the help of the -exec command.
- cp: It is the basic copy command.
Output:
How to Copy a File to Multiple Directories in Linux
In this article, we will discuss how to copy a file to multiple directories in Linux. xargs, find, tee, shell loop, and parallel are the commands that can help you to copy a File to Multiple Directories.
Suppose we have a file with the name “xyz.txt” and we want to copy it into 3 directories with the name dir1, dir2, and dir3 then we use the following methods: