![]() ![]() The issue with the above command arises when you have two files with the same filename, such as “dir1/filename.txt” and “dir2/filename.txt,” and when you use the above command, it will not copy the second file due to a file name clash.Īnother issue with the commands is that when you copy a file recursively, the above command does not preserve the directory structure. iname '*.txt' -type f -print0 | xargs -0 mv -t ~/Documents The above command will not work if you source file path contain white space, so you can use the following command to overcome from the situation. ![]() ![]() To avoid errors, make sure your system has access to the destination path.Īlso Read: 20+ Find command which you can use daily The output of the above command is shown below:įind and Copy Files with Specific File Extensions So let’s take a simple example where you will learn how to use the find command to locate a file on the basis of a particular file extension, and after getting the result, you can use the cp or mv commands to copy or move the file to the desired location. Most likely, you will manually look for the specific file extension in each directory, and then you will copy it to another location, right? But I don’t recommend this because you can use the find command to find the file based on your given pattern.Īnd here is the syntax which you can use to find and copy file: $ find /path/where/to/look -name "file.extension" | cp -vt /destionation/path If you want to move all the specific files with certain extensions from multiple directories to a specific directory, then what will you do? * Match one or number of more occurrenceįind and Copy Files with Specific File Extension.Move or Copy Specific file Extension using Wildcard Character in FilenameĪnd here is the wildcard character that you can use to copy or move a file from the directory: ![]()
0 Comments
Leave a Reply. |