Skip to main content
added 10 characters in body
Source Link
user1794469
  • 4.2k
  • 1
  • 27
  • 42

You can do this with a one liner:

grep '^aaa.*\.png$' list.txt | xargs -I '{}' cp '{}' destination_dir/

grep is looking for 'aaa' at the start of the line followed by zero or more characters and ending with '.png'. It then pipes that as a list of arguments to cp which moves them to 'destination_dir'

If you are in the directory of the files you can just cp them with:

cp aaa*.png destination_dir

You can do this with a one liner:

grep '^aaa.*\.png$' list.txt | xargs cp {} destination_dir/

grep is looking for 'aaa' at the start of the line followed by zero or more characters and ending with '.png'. It then pipes that as a list of arguments to cp which moves them to 'destination_dir'

You can do this with a one liner:

grep '^aaa.*\.png$' list.txt | xargs -I '{}' cp '{}' destination_dir/

grep is looking for 'aaa' at the start of the line followed by zero or more characters and ending with '.png'. It then pipes that as a list of arguments to cp which moves them to 'destination_dir'

If you are in the directory of the files you can just cp them with:

cp aaa*.png destination_dir
Source Link
user1794469
  • 4.2k
  • 1
  • 27
  • 42

You can do this with a one liner:

grep '^aaa.*\.png$' list.txt | xargs cp {} destination_dir/

grep is looking for 'aaa' at the start of the line followed by zero or more characters and ending with '.png'. It then pipes that as a list of arguments to cp which moves them to 'destination_dir'