우분투 cp 덮어쓰기 막기 -i 옵션

1 개요[ | ]

우분투 cp 덮어쓰기 막기
  • CentOS와는 달리 우분투에서는 cp 수행시 덮어쓰기 여부를 물어보지 않고 그냥 덮어쓴다.
  • 무조건 덮어쓰기 되는 것을 막으려면 -i 또는 --interactive 옵션을 주어야 한다.

2 실습: 기본(무조건 덮어씀)[ | ]

root@zetawiki:~# echo hello > 1.txt
root@zetawiki:~# echo world > 2.txt
root@zetawiki:~# cp 1.txt 2.txt
root@zetawiki:~# head *.txt
==> 1.txt <==
hello

==> 2.txt <==
hello
→ 1.txt가 2.txt로 덮어써짐

3 실습: 덮어쓰기 방지(-i)[ | ]

root@zetawiki:~# echo hello > 1.txt
root@zetawiki:~# echo world > 2.txt
root@zetawiki:~# cp 1.txt 2.txt -i
cp: overwrite ‘2.txt’? n
→ 이미 있는 파일에 복사하려고 하면 덮어쓰겠냐고 물어봄
→ y Enter하면 덮어쓰기, n Enter하면 취소. 여기서는 n Enter
root@zetawiki:~# head *.txt
==> 1.txt <==
hello

==> 2.txt <==
world
→ cp가 취소되어 2.txt의 원래 내용 world가 그대로 있음

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}