본문 바로가기
프로그래밍/ETC

[Terminal] 터미널 기본 명령어 #2 "touch, cp, mv, rm, -r"

by research_notes 2024. 5. 15.
728x90
반응형

MAC Terminal Basic Command Lines

<Create, Copy, Move, and Delete Files>

 

1.  Creating a File (파일 생성하기)

$ touch test/text.txt

Example
$ pwd
/Users/user/Desktop/testFolder
$ ls
practice
$ touch text.txt
$ ls
practice	text.txt

 

2. Copying a File (파일 복사하기)

$ cp "filename1" "filename2"

Example
$ ls
practice	text.txt
$ cp text.txt textCopy.txt
$ ls
practice	text.txt	textCopy.txt

 

3. Moving a File (파일 이동하기)

$ mv /path/to/the/file/to/move  /path/to/where/it/should/be/moved

Example
$ pwd
Users/user/Desktop
$ ls
practice	text.txt	textCopy.txt

$ mv text.txt practice/text.txt
$ ls
practice textCopy.txt
$ ls practice
text.txt

 

 

4. Deleting a File (파일 삭제하기)

$ rm text.txt

Example
$ ls practice
text.txt
$ rm practice/text.txt
$ ls practice
$ 			# nothing left

 

5. 디렉토리 안에 있는 폴더와 파일들 함께 다루기 (-r)

$ cp -r "directory1" "directory2"
$ rm -r /directory/that/you/want/to/remove
$ mv -r /dir/you/want/to/move /path/to/locate

Example
$ pwd
/Users/user/Desktop/testFolder
$ ls
practice	textCopy.txt

$ ls practice
textCopy.txt

$ mkdir Folder
$ ls
Folder	practice	textCopy.txt
$ cp practice Folder  # 'practice'라는 디렉토리/폴더를 'Folder'라는 디렉토리로 복사하고 싶었으나, 에러
cp: practice is a directory (not copied). 
$ cp -r practice Folder
$ ls Folder
practice
반응형

 

728x90
반응형