copy all files in folder one by one on linux
- User
copy all files in folder one by one on linux
- Assistant
There are several ways to copy all files in a folder one by one on Linux. Below are a few methods:
- Using the cp command with a for loop:
codefor file in /path/to/folder/* do cp "$file" /path/to/target/folder/ doneThis will copy each file one by one from the source folder to the target folder.
- Using the find command with the cp command:
codefind /path/to/source/folder -type f -exec cp {} /path/to/target/folder/ \;This will find all files in the source folder and execute the cp command for each file, copying it to the target folder one by one.
- Using the xargs command with the cp command:
codels /path/to/source/folder/ | xargs -I {} cp /path/to/source/folder/{} /path/to/target/folder/This will list all files in the source folder, and use xargs to execute the cp command for each file, copying it to the target folder one by one.
Note: It's important to ensure that the target folder exists before running any of these commands.
- User
what if i need copy all files from 52 like in this filename example: [Anistar.org] Swallowed Star [TV-1] - 53 [1080p].mp4 [Anistar.org] Swallowed Star [TV-1] - 54 [1080p].mp4 [Anistar.org] Swallowed Star [TV-1] - 55 [1080p].mp4 etc?
- Assistant
You can still use the methods mentioned above, but with a slight modification to target files that match the pattern "[Anistar.org] Swallowed Star [TV-1] - XX [1080p].mp4", where XX is a number:
- Using the cp command with a for loop:
codefor file in /path/to/folder/*[Anistar.org]*.mp4 do cp "$file" /path/to/target/folder/ doneThis will copy each file that matches the pattern "[Anistar.org] Swallowed Star [TV-1] - XX [1080p].mp4" one by one from the source folder to the target folder.
- Using the find command with the cp command:
codefind /path/to/source/folder -name "*[Anistar.org]*.mp4" -type f -exec cp {} /path/to/target/folder/ \;This will find all files that match the pattern "[Anistar.org] Swallowed Star [TV-1] - XX [1080p].mp4" in the source folder and execute the cp command for each file, copying it to the target folder one by one.
- User
i need all files starts from [Anistar.org] Swallowed Star [TV-1] - 53 [1080p].mp4
- Assistant
In that case, you can modify the file pattern in the methods mentioned above to match the files starting with "[Anistar.org] Swallowed Star [TV-1] - 53":
- Using the cp command with a for loop:
codefor file in /path/to/folder/*[Anistar.org]*53*.mp4 do cp "$file" /path/to/target/folder/ doneThis will copy each file that starts with "[Anistar.org] Swallowed Star [TV-1] - 53" one by one from the source folder to the target folder.
- Using the find command with the cp command:
codefind /path/to/source/folder -name "*[Anistar.org]*53*.mp4" -type f -exec cp {} /path/to/target/folder/ \;This will find all files that start with "[Anistar.org] Swallowed Star [TV-1] - 53" in the source folder and execute the cp command for each file, copying it to the target folder one by one.
- Using the xargs command with the cp command:
- User
53 is a periodic number. there are many files with numbers
- Assistant
If the number 53 is a periodic number and there are many files with similar filenames except for the periodic part of the filename (which could be any number), you can use a wildcard character to match any number. Here's how you can modify the commands to copy all files that start with "[Anistar.org] Swallowed Star [TV-1] -" followed by any number and ending with ".mp4":
- Using the cp command with a for loop:
codefor file in /path/to/folder/*[Anistar.org]*[0-9]*.mp4 do cp "$file" /path/to/target/folder/ doneThis will copy each file that matches the pattern "[Anistar.org] Swallowed Star [TV-1] - XX [1080p].mp4" one by one from the source folder to the target folder.
- User
not any numbers i need only files starting from 53 in lis like this [Anistar.org] Swallowed Star [TV-1] - 51 [1080p].mp4, [Anistar.org] Swallowed Star [TV-1] - 52 [1080p].mp4, [Anistar.org] Swallowed Star [TV-1] - 53 [1080p].mp4, [Anistar.org] Swallowed Star [TV-1] - 54 [1080p].mp4 and so on
- Assistant
In that case, you can modify the regular expression to specifically match numbers starting from 53. Here's how you can modify the commands:
- Using the cp command with a for loop:
codefor file in /path/to/folder/*[Anistar.org]*53*.mp4 do cp "$file" /path/to/target/folder/ doneThis will copy each file that starts with "[Anistar.org] Swallowed Star [TV-1] - 53" one by one from the source folder to the target folder.
- Using the find command with the cp command:
codefind /path/to/source/folder -name "*[Anistar.org]*53*.mp4" -type f -exec cp {} /path/to/target/folder/ \;This will find all files that start with "[Anistar.org] Swallowed Star [TV-1] - 53" in the source folder and execute the cp command for each file, copying it to the target folder one by one.
- Using the xargs command with the cp command: