English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have several thousand numbered photos on my Linux machine with filenames of the form IMG_1234.jpg. Sometimes I want to copy some of them using the command line.

Suppose I want to copy images IMG_1000.jpg through IMG_1056.jpg to a new directory. Is there a one-line command I could use to do this?

I'm not too familiar with piping and I/O redirection, or with things like grep or sed, but I have been able to obtain a list of filenames for images IMG_1000.jpg through IMG_1099.jpg using:

$ ls | grep IMG_10..\.jpg > images.txt

I was thinking that I might somehow pipe the output of the grep command to cp, but I can't figure out how to get cp to recognize the input.

2007-10-20 08:21:08 · 2 answers · asked by mdd4696 3 in Computers & Internet Software

2 answers

An * is a wildcard for "anything". A ? is a wildcard for "1 character" so the easiest answer would be
cp IMG_10??.jpg /target/dir

You can also replace any of the ? with a braced range such as
[2-5] for two thru five so your initial request of 1000 to 1056 could be done as
cp IMG_10[0-5]?.jpg /target/dir

2007-10-20 15:02:24 · answer #1 · answered by Gandalf Parker 7 · 0 1

your place itemizing is ~/ and the command is cp. Do a guy cp for greater switches and recommendations, yet something like cp filename ~/ will purely reproduction it to the basis of your place itemizing.

2016-11-09 00:58:11 · answer #2 · answered by apley 4 · 0 0

fedest.com, questions and answers