Linux2010. 9. 19. 21:44
완전 다른 디렉토리로 이동할때 가끔 이전의 경로로 돌아가고 싶은 때가 있다.
귀찮지만 일일이 치곤했는데, 귀차니즘(실은 모토쿼티에서 일일이 치긴 곤혹이라..) 때문에 다시 찾아보니
간단한 해결 방법이 있었다.

 cd $OLDPWD
 cd -

두가지 모두 bash 쉘에서 작동을 한다.
그래도 cd - 가 타수가 적어지니 더 편한듯!


OLDPWD
The previous working directory as set by the cd command.

[링크 : http://linux.die.net/man/1/bash]

you can go back to the previous directory without having to type in the entire directory path by using the command “cd –”.

[링크 : http://techie-buzz.com/.../how-to-go-back-to-previous-directory...putty.html]


'Linux' 카테고리의 다른 글

POSIX - Portable Operating System Interface [for Unix]  (6) 2010.09.21
커널의 종류(kind of kernels)  (0) 2010.09.21
mkinitramfs  (0) 2010.09.19
top (1) - load average ?  (4) 2010.09.12
curl  (0) 2010.09.11
Posted by 구차니
Linux2010. 4. 19. 17:13
리눅스에서 cd는 디렉토리를 변경하고,
pwd는 현재 작업 디렉토리를 보여준다.

그걸 api 수준에서 보자면
cd는 chdir() 이고
pwd는 getcwd() 이다.

long getcwd(char *buf, unsigned long size);

#include <unistd.h>
int chdir(const char *path);
int fchdir(int fd);

[링크 : http://linux.die.net/man/3/getcwd]
[링크 : http://linux.die.net/man/3/chdir]


2010.04.20 추가

코드샘플
#include "unistd.h"

void main()
{
	int ret;
	char buff[256];
	
	getcwd(buff, 255);
	printf("%s\n",buff);
	
	ret = chdir("/etc");

	getcwd(buff, 255);
	printf("%s\n",buff);	
}

Posted by 구차니