How to copy files only?

QuestionsQuestions8 SkillsProBasic Files OperationsAug, 08 2025
0214

To copy only files (excluding directories) in Bash, you can use the cp command with a wildcard. Here's an example:

cp /source_directory/* /destination_directory/
  • /source_directory/* matches all files in the source directory.
  • /destination_directory/ is where the files will be copied.

If you want to ensure that only files are copied and not any subdirectories, you can use the find command:

find /source_directory -maxdepth 1 -type f -exec cp {} /destination_directory/ \;
  • -maxdepth 1 limits the search to the top level of the source directory.
  • -type f ensures that only files are selected.

Feel free to ask if you need more details or examples!

0 Comments

no data
Be the first to share your comment!