폴더의 모든 파일 인쇄

폴더의 모든 파일 인쇄

lsreturn 을 가정하면 file1 file2 dir1 dire2 ...인쇄하고 싶습니다 you have file1 file2 dir1 dire2 ... in currnent folder.

어떻게 해야 하나요? ls | xargs -i echo 'you have {} in current folder'인쇄

현재 폴더에 file1이 있습니다
현재 폴더에 file2가 있습니다
현재 폴더에 dir1이 있습니다
현재 폴더에 dir2가 있습니다
현재 폴더에 xxx가 있습니다

또한 시도해 보았지만 ls |xargs printf 'you have %s %s %s %s in current folder' 제대로 작동하지 못했습니다. 파일 수가 정의되지 않았기 때문입니다. printf이 경우 올바른 구문은 무엇입니까?

ls | xargs printf 'you have $@ in current folder'내가 얻을 수 있는 가장 가까운 것이지만 작동하지 않습니다.

답변1

다음은 작동하지만 보안에 부정적인 영향을 미칠 수 있습니다.

echo "You have" * "in current folder"

IMO가 더 나은 접근 방식이지만 다음 두 줄이 필요합니다.

files=(*)
echo "You have ${files[@]} in curent folder"

printf를 사용하세요:

files=(*)
printf '%s ' "You have ${files[@]} in current folder"

답변2

가격 대비 가치:

echo You have $(ls) in the current folder 

답변3

나는 Jesse_b의 솔루션이 최고라고 생각하지만 비슷한 것을 원한다면 xargsGNU Parallel을 사용할 수 있습니다.

ls | parallel --xargs echo you have {} in current folder

관련 정보