Anderson M. Gomes의 답변을 확장하여 Bash를 사용하면 디렉토리 스택 의 위치를 ~N(또는 ~+N) 를 입력하여 디렉토리 스택의 이전 디렉토리를 참조 할 수 있습니다 N. 예를 들면 다음과 같습니다.
# go some places
$ cd /path/to/source/directory
$ pushd /path/to/destination/directory
$ pushd $HOME
$ pushd /tmp
# show the current dir stack
$ dirs -v
0 /tmp
1 ~
2 /path/to/destination/directory
3 /path/to/source/directory
이제 다음을 사용하여 두 개의 과거 디렉토리 사이에서 파일을 복사 할 수 있습니다.
cp -v ~3/file1.txt ~2
원래 포스터의 문제를 해결하려면 다음을 수행하십시오.
$ cd /path/to/source/directory
$ pushd /path/to/destination/directory
# show the current dir stack
$ dirs -v
0 /path/to/destination/directory
1 /path/to/source/directory
# copy
cp -v ~1/file[123].txt .
많은 파일 세트를 사용하면 이름을 매니페스트 파일에 나열한 다음 소스 디렉토리에서 복사를 수행 할 수 있습니다.
$ cd /path/to/destination/directory
$ pushd /path/to/source/directory
# copy
cp -v $(cat files_to_copy.list) ~1
참조 : Bash 매뉴얼 페이지의이 섹션
마찬가지로 Tcsh에서는 =2(이 아닌 ~2) 표기법을 사용 하여 디렉토리 스택의 두 번째 디렉토리를 참조 할 수 있습니다 .
참조 : Tcsh 매뉴얼 페이지의이 섹션
cd명령 을 입력해야 하므로cd -이전 디렉토리로 돌아가서 위쪽 화살표를 눌러cd명령 을 호출하고cp대신 줄을 편집하십시오cd. (ctrl-a (라인 시작), alt-d (kill-word)cp -a, ctrl-e (라인 끝)).