특정 예시에 대한 바로가기

특정 예시에 대한 바로가기

Documents각 파일에 명시적으로 쓰지 않고 이 디렉터리에서 다른 디렉터리로 5개의 파일을 이동하고 싶습니다 . 사용할 수 있는 단축키(예: 숫자 사용)가 있나요?

나는 이런 일을 하고 싶지 않습니다:

mv ./Documents/Curriculum Vitae (Francais).pdf ./Anotherdirectory
mv ./Documents/Lettre de motivation - Candidature Agent Soutien technique.pdf ./Anotherdirectory
mv ./Documents/Lettre_de_reference_1.pdf ./Anotherdirectory
mv ./Documents/Lettre_de_reference_2.pdf ./Anotherdirectory
mv ./Documents/Lettre_de_reference_3.pdf ./Anotherdirectory

또는

mv ./Documents/Curriculum Vitae (Francais).pdf ./Documents/Lettre de motivation - Candidature Agent Soutien technique.pdf ./Anotherdirectory ./Documents/Lettre_de_reference_1.pdf ./Documents/Lettre_de_reference_2.pdf ./Documents/Lettre_de_reference_3.pdf ./Anotherdirectory

각 파일에 번호(예: mv ./Documents/1;2;3;4;5 ./Anotherdirecotry)를 연결하고 매번 전체 경로 대신 해당 번호를 사용할 수 있다면 더 편리할 것입니다.

내 문제를 해결하려면 이 파일을 참조하는 방법을 알아야 합니다.

jeremie@jeremie-MacBookPro ~> ls ./Documents
Curriculum_Vitae/
Curriculum Vitae (Francais).pdf
Lettre de motivation - Candidature Agent Soutien technique.pdf
Lettre_de_reference_1.pdf
Lettre_de_reference_2.pdf
Lettre_de_reference_3.pdf

달러 기호를 사용하여 파일을 참조할 수 있다고 생각했습니다. 따라서 파일에 액세스하고 싶으면 Curriculum Vitae (Francais).pdf이 명령을 사용할 수 있습니다 ls ./Documents/$2.

답변1

많은 Unix/Linux 명령을 사용하면 단일 명령으로 여러 파일 이름을 지정할 수 있습니다. 따라서 모든 파일을 동일한 대상으로 이동하려는 경우 5개의 개별 명령을 사용할 필요가 없습니다.

mv "./Documents/Curriculum Vitae (Francais).pdf" "./Documents/Lettre de motivation - Candidature Agent Soutien technique.pdf" ./Documents/Lettre_de_reference_1.pdf ./Documents/Lettre_de_reference_2.pdf ./Documents/Lettre_de_reference_3.pdf ./Anotherdirectory

노트:

  • ./Documents/Curriculum Vitae (Francais).pdf명령의 여러 "단어"는 일반적으로 별도의 파일 이름으로 처리되므로 소프트웨어가 이를 세 개의 파일 이름 대신 단일 파일 이름 으로 처리하도록 하려면 특별한 작업을 수행해야 합니다 . 실제로 여러 문자는 특별하므로 파일 이름의 일부로 사용하려면 특별한 방법으로 처리해야 합니다. 이러한 문자에는 , , &, *, (, ), {, }, [, ], |, \, ;, ', ", <, 및 때로는 . 이를 처리하는 가장 쉬운 방법은 따옴표(위에 표시된 것처럼 큰따옴표 또는 작은따옴표)로 묶는 것입니다.>?!$`~
    './문서/이력서(프랑스어).pdf'
    (일부 문자의 경우 규칙이 더 복잡해집니다.) 또 다른 방법은 \각 특수 문자 앞에 백슬래시( )를 추가하는 것입니다.
    ./문서/커리큘럼\ 이력서\ \(프랑스어\).pdf
    대부분의 사람들은 인용이 더 편리하다고 생각합니다.
  • ./현재 디렉터리의 파일(및 디렉터리)을 처리할 때 일반적 으로 이것이 필요할 때 를 사용할 필요가 없습니다 .구현하다현재 디렉터리의 프로그램입니다. 이는 파일 이름이 대시로 시작되는 것을 방지하는 유용한 방법이기도 합니다(-). 이게 정상적인 역할이구나~에파일 이름(예: Lettre de motivation - Candidature Agent Soutien …)이지만 처음에는 옵션으로 해석됩니다. 대시로 시작하는 파일 이름을 처리하는 또 다른 방법은 이중 대시(--) 첫 번째 파일 이름 앞에, 예를 들어
    MV[옵션]--파일 1 파일 2 파일 3 파일 4 파일 5 대상 디렉터리
    그러나 이것이 항상 작동하는 것은 아닙니다.

움직이고 싶다면모두현재 디렉터리의 파일을 하위 디렉터리로 복사하려면 .pdf다음을 수행하세요.

mv -- *.pdf Anotherdirectory

꼭 참고하시기 바랍니다아니요여기에 *따옴표로 묶어주세요. 이번에는 당신생각하다"이 패턴과 일치하는 모든 파일"이라는 특별한 의미를 얻으려면.

여러 파일 이름이 매우 유사한 경우 다음과 같은 몇 가지 다른 방법을 사용할 수 있습니다.

mv -- … Documents/Lettre_de_reference_?.pdf Anotherdirectory

그리고

mv -- … Documents/Lettre_de_reference_[123].pdf Anotherdirectory

그리고

mv -- … Documents/Lettre_de_reference_[1-3].pdf Anotherdirectory

그리고

mv -- … Documents/Lettre_de_reference_{1,2,3}.pdf Anotherdirectory

그리고

mv -- … Documents/Lettre_de_reference_{1..3}.pdf Anotherdirectory

설명서를 읽고 어떻게 다른지 알아보세요.

답변2

mv ./Documents/file{1..5} ./Anotherdirectory

답변3

요구 사항이 매우 구체적이므로 다음과 같은 기능을 만드는 것이 좋습니다.

mymv(){ mv ./Documents/"$1" ./Anotherdirectory; }  

$1이는 함수의 첫 번째 매개변수를 나타냅니다.

함수를 정의한 후 파일을 이동할 때마다 다음을 사용하십시오.

mymv FILE

관련 정보