Friday, May 3, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1211  / 3 Years ago, tue, august 31, 2021, 11:37:40

How can I copy *.txt files only from a directory and all its children directories?



Say I have a folder A containing .txt files and subfolders B C etc that contain .txt files and so on and I just want all the .txt files?


More From » command-line

 Answers
7

This will find all .txt files starting in the current folder (.) and scp them one at a time to hostname and place them in the home folder.



for filename in $( find . -name '*.txt' ); do scp "$filename" hostname:~/ ; done


Edit: It is important to note you want the quotes around the file name incase the filename has a space in it, if it does and you don't quote it then the application will treat it like multiple arguments instead of one.


[#26645] Thursday, September 2, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
learty

Total Points: 432
Total Questions: 115
Total Answers: 109

Location: Wallis and Futuna
Member since Tue, Mar 30, 2021
3 Years ago
learty questions
Sat, May 21, 22, 15:30, 2 Years ago
Sun, Jan 9, 22, 22:31, 2 Years ago
Mon, Jul 4, 22, 11:31, 2 Years ago
Tue, Mar 22, 22, 16:28, 2 Years ago
;