Task Question:
Login to the Server 3 by using credentials in kodekloud.
Executing the command
sudo find /var/www/html/media -type f -name “*.js” -exec cp — parents {} /media \;
- We can do this task by using a single command Find
- We are finding files in the directory /var/www/html/media. Given as first argument to find.
- We can specify type of file using -type option. Where f is for file , d is for directory.
- We can specify name of file using -name option.. Where we use wildcard expression to get only .js files.
- From find command we can execute other commands by using -exec option.
- In this task we use cp(copy) command to copy the .js extension files with their parent directory using argument “ — parents”.
- Here, we find the .js extension files with their parent directory, but we need to pipe(input of find command ) to cp (copy) by using “{}”.
- We close the command by providing “\;” in the end.
Finally check the /media folder to verify we have copied only .js files with their parent directories.