리눅스 / 명령어 / 연산자 - ;, &&, ||
Created 2025-06-01
Last Modified 2025-06-01
리눅스 셸에서 ;, &&, || 는 명령어 실행 방식을 제어하는 연산자입니다. 각 기호의 의미와 사용법은 다음과 같습니다.
;
명령어를 순차적으로 실행합니다. 앞의 명령이 성공하든 실패하든 다음 명령어를 실행합니다.
예를 들어 temp 디렉토리가 있는 경우 mkdir temp 명령은 실패합니다. 그래도 ll 명령을 실행합니다.
# mkdir temp ; ll mkdir: cannot create directory ‘temp’: File exists total 40 drwx------ 6 root root 4096 May 28 00:14 ./ drwxr-xr-x 23 root root 4096 May 22 2024 ../ -rw------- 1 root root 1531 May 28 00:14 .bash_history -rw-r--r-- 1 root root 3106 Apr 22 2024 .bashrc drwx------ 2 root root 4096 May 22 2024 .cache/ -rw------- 1 root root 20 May 28 00:14 .lesshst drwxr-xr-x 3 root root 4096 May 22 2024 .local/ -rw-r--r-- 1 root root 161 Apr 22 2024 .profile drwx------ 2 root root 4096 May 22 2024 .ssh/ drwxr-xr-x 3 root root 4096 May 27 23:27 temp/
&&
앞의 명령어를 실행하고, 성공하면 뒤의 명령어를 실행합니다.
예를 들어 temp 디렉토리가 있는 경우 mkdir temp 명령은 실패합니다. 그래서 ll 명령은 실행하지 않습니다.
# mkdir temp && ll mkdir: cannot create directory ‘temp’: File exists
||
앞의 명령어를 실행하고, 실패하면 뒤의 명령어를 실행합니다.
예를 들어 temp 디렉토리가 있는 경우 mkdir temp 명령은 실패합니다. 그래서 ll 명령을 실행합니다.
# mkdir temp || ll mkdir: cannot create directory ‘temp’: File exists total 40 drwx------ 6 root root 4096 May 28 00:14 ./ drwxr-xr-x 23 root root 4096 May 22 2024 ../ -rw------- 1 root root 1531 May 28 00:14 .bash_history -rw-r--r-- 1 root root 3106 Apr 22 2024 .bashrc drwx------ 2 root root 4096 May 22 2024 .cache/ -rw------- 1 root root 20 May 28 00:14 .lesshst drwxr-xr-x 3 root root 4096 May 22 2024 .local/ -rw-r--r-- 1 root root 161 Apr 22 2024 .profile drwx------ 2 root root 4096 May 22 2024 .ssh/ drwxr-xr-x 3 root root 4096 May 27 23:27 temp/