OS/Linux

[Linux] cp 덮어쓰기

개발계발게발 2022. 7. 14. 11:30
반응형

리눅스 cp 덮어쓰기

cp overwrite 무시, cp alias 무시하기

 

[root@localhost data]# cp hello.txt hello2.txt
cp: overwrite `hello2.txt'?

cp 중복 파일 존재시 overwrite 질문 상황

수작업의 경우 y를 눌러주면 되지만, 파일 갯수가 많거나 스크립트 작업시 문제 발생

 

 

[root@localhost data]# cp -f hello.txt hello2.txt
cp: overwrite `hello2.txt'?

-f 옵션을 넣어도 소용없음

 

[root@localhost data]# which cp
alias cp='cp -i'
        /usr/bin/cp

cp 에대한 alias로 --interactive(덮어쓸 때 대화식 진행) 옵션이 있어서 그렇다...

 

 

해결 방법

1. 'yes | '  를 앞에 넣어 사용 

[root@localhost data]# yes | cp hello.txt hello2.txt
cp: overwrite `hello2.txt'? [root@localhost data]#

2. cp 앞에 역슬래시(escape 문자)를 넣으면 alias 대신 원래의 명령어가 실행

[root@localhost data]# \cp hello.txt hello2.txt
[root@localhost data]#

 

3. 전체 경로 사용

[root@localhost data]# /bin/cp hello.txt hello2.txt 
[root@localhost data]#

 

반응형