bash 스크립트에서 파일을 복사하려고하지만 파일 이름이 시간이 지남에 따라 변경됩니다. 그러나 파일 이름의 시작과 끝은 동일하게 유지됩니다.bash 파일의 일부 파일 이름을 알 수없는 파일 복사
cp start~end.jar
~ 무엇이든 될 수 있습니다
방법은 내가 이렇게 같은 파일을 얻을 수 있도록 있는가?
우분투 컴퓨터에서 cp 명령을 실행하면 우분투 컴퓨터에서 bash 스크립트가 실행됩니다.
bash 스크립트에서 파일을 복사하려고하지만 파일 이름이 시간이 지남에 따라 변경됩니다. 그러나 파일 이름의 시작과 끝은 동일하게 유지됩니다.bash 파일의 일부 파일 이름을 알 수없는 파일 복사
cp start~end.jar
~ 무엇이든 될 수 있습니다
방법은 내가 이렇게 같은 파일을 얻을 수 있도록 있는가?
우분투 컴퓨터에서 cp 명령을 실행하면 우분투 컴퓨터에서 bash 스크립트가 실행됩니다.
글로브 (start*end
가) 당신에게 일치하는 모든 파일을 제공 할 것입니다. 보다 구체적인 제어를위한 bash는 설명서의 Expansion > Pathname Expansion > Pattern Matching
섹션 밖으로
확인
* Matches any string, including the null string.
? Matches any single character.
[...] Matches any one of the enclosed characters. A pair of characters separated by a hyphen denotes a range expression; any character that sorts between those two characters, inclusive, using the current locale's collat-
ing sequence and character set, is matched. If the first character following the [ is a ! or a^then any character not enclosed is matched. The sorting order of characters in range expressions is determined by
the current locale and the value of the LC_COLLATE shell variable, if set. A - may be matched by including it as the first or last character in the set. A ] may be matched by including it as the first character in
the set.
하고 extglob
을 사용하는 경우 :
?(pattern-list)
Matches zero or one occurrence of the given patterns
*(pattern-list)
Matches zero or more occurrences of the given patterns
+(pattern-list)
Matches one or more occurrences of the given patterns
@(pattern-list)
Matches one of the given patterns
!(pattern-list)
Matches anything except one of the given patterns
사용하십시오 glob
변수 텍스트를 캡처 :
cp start*end.jar
한 조언의 비트; 예상보다 많은 파일을 일치시키지 않으려면 패턴을 가능한 한 구체적으로 만드십시오. 예를 들어 중간 부분이 YYYY-MM-DD 형식의 타임 스탬프 였음을 알고 있다면'start * ????.? end.jar'를'start * end.jar'로 바꾸십시오. 또는 더 좋게,'start - @ (19 | 20) [0-9] [0-9] - @ ([1-9] | 10 | 11 | 12) - @ ([1-9] | 1 [1 -9] | 2 [1-9] | 3 [01] -end.jar'. – chepner