Moving all the txt files from all the subfolders to another single folder in Linux

            


 Some times we need to move all the files with same extension to a single desired folder. It can be easy if there is only two or three folders...Just think there is hundreds of folders and its sub folders are there and need to move the files from all these folder.

Searching all the folder manually and move these files to the outside folder is a big task.In such case we can use the below command in order to move all the files to our desired external folder. 

Syntax

find <Parent_folder> -type f -iname "*.txt" -exec mv --backup=numbered -t <destination folder> {} +


example


find /source -type f -iname "*.txt" -exec mv --backup=numbered -t /root/Desktop/destination {} +


Here /source is the parent folder contain all its subfolders which has the required the .txt files and /root/Desktop/destination is the path where all the .txt files from the source location is moved.


NOTE: With the above command we can move any type of files from the source location by changing the extension in the command...ie .txt

No comments:

Post a Comment