Xargs
| 운영 체제 | 유닉스, 유닉스 계열 |
|---|---|
| 종류 | 명령어 |
xargs는 유닉스 및 유닉스 계열 운영 체제의 명령어로 표준 입력을 통해 명령 줄을 만들고 실행하는 데 사용한다. 버전 2.6.23 이전의 리눅스 커널에서는 긴 목록의 매개변수가 명령어를 통해 이용하지 못하는 경우도 간혹 있으므로[1] xargs는 변수 목록을 여러 하부 목록으로 잘게 나누어서 받아들일 수 있게 한다.
예를 들면, 다음 명령어들은 /path 아래에 파일들이 너무 많이 있을 경우 "Argument list too long"이란 메시지를 내며 실행되지 않는다.
rm /path/*
또는
rm `find /path -type f`
그러나, (같은 역할을 하는) 다음 명령어는 파일 개수와 상관없이 실행된다.
find /path -type f -print0 | xargs -0 rm
이 예제에서, find는 파일이름의 리스트를 갖는 xargs를 입력으로 받는다.
xargs는 이 리스트를 세부리스트로 나누면서 각각의 리스트에 대해서 rm을 호출한다.
이 방법은 같은 역할을 하는 다음의 명령어 보다 더 효율적이다.
find /path -type f -exec rm '{}' \;
위 명령어에서는 각각의 파일에 대해 rm이 호출된다.[2]
같이 보기
각주
외부 링크
| 이 글은 소프트웨어에 관한 토막글입니다. 여러분의 지식으로 알차게 문서를 완성해 갑시다. |
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.