터미널 사용법

Haiseong Jeong·2022년 10월 28일
2
post-thumbnail

1. Change Directory

Command: cd

What it does: This command will change the directory that you’re currently working with in the Terminal in order to execute other commands on a different directory, view the contents of a different directory or open a file in a different directory. This is a very common command that will be used when working with the CLI. If you ever lose your place and which directory you’re in, type pwd (print working directory) and press Return to echo the current path.

현재 작업하고 있는 디렉토리의 위치를 이동하는 명령어다.

Example: cd “path/to/directory/”

2. Listing Directory

Command: ls

What it does: Use this command after navigating into a directory using the cd command to view the contents (files and directories) inside of the current directory. Use the argument -l (ls -l) to get even more information about each of the files, including the permissions, owner and date created.

디렉토리(directory)에 있는 내용(디렉토리, 파일 등)을 확인한다.

Example: ls “path/to/directory/”

3. Open files

Command: open

What it does: When browsing a directory, you may encounter a file that you wish to open on your Mac. That’s where the open command comes in. Typing this command followed by a space and the filename will open the file with the app that can open that file type on the Mac. When typing the filename, you don’t need to type the full name, partially type what you can, then press tab to autocomplete the remaining text.

확장자에 대해 기본 어플리케이션을 실행해주는 명령어이다.

Example: open “filename”

4. Copy a file to another directory

Command: cp

What it does: This command facilitates copying a file from one location to another, or just simply making a copy of the same file with a new name. When specifying the first argument, include the originating file that you wish to copy followed by a space and a full path, filename and extension of where you want the copy to be placed when the command is executed. The Terminal will return when the copy has been completed.

파일, 디렉토리를 복사한다.

Example: cp “filename” “newfilename”

5. Move a file

Command: mv

What it does: When you don’t want to copy a file, but instead move it, use the same format of the cp command, but instead replace ‘cp’ with ‘mv’. This will perform a file move from one location to another, removing the file from the original location and putting it into the new location.

파일, 디렉토리의 위치를 옮긴다.

Example: mv “filename” “path/to/new/file/location”

6. Create a text file

Command: touch

What it does: The touch command allows you to create any type of file, but it’s blank. After you create the blank file, you can open it in a text editor by typing open filename.

touch는 파일의 날짜와 시간을 수정하는 명령어이긴 하지만, 0바이트 파일을 생성하기 위해 자주 사용되는 명령어다.

Example: touch myfile.txt

7. Create a directory

Command: mkdir

What it does: This command will allow you to create a directory (folder) right from the CLI. When you need a place to store new files, just use this command to add a new directory in the current working directory, or specify a full path to the location where you want the new directory to be placed.

새로운 디렉토리를 만드는 명령이다.

Example: mkdir “path/to/new/directory”

8. Remove an empty directory

Command: rmdir

What it does: When you’ve created a folder that has the wrong name, you can easily use the mv command to rename it, or if you want to remove a directory altogether, use the rmdir command followed by the path to the directory.

빈 디렉토리를 삭제하는 명령어입니다. 디렉토리 안에 파일이 있으면 삭제할 수 없다.

Example: rmdir “path/to/directory”

9. Remove nested directories

Command: rm -R

What it does: When you want to remove an entire directory that might contain other directories or files, then the rm -R command is where you will turn. This command is irreversible, (unlike deleting files in the Finder and being able to restore them from the Trash). When this command is executed, all files and directories inside of the path you specify will be deleted immediately.

디렉토리를 삭제하는 명령어다. -R 이 recursive를 의미해 폴더가 비어있지 않아도 재귀적으로 안에 있는 내용까지 지운다.

Example: rm -R “/path/to/root/directory”

10. Execute commands with superuser privileges

Command: sudo

What it does: sudo (or super user do) is a command that allows you to elevate your user privileges while executing the command to administrator privileges. This is required for some commands to run —for instance removing a file that is owned by another user. When you run this command, you will see a password field appear in the Terminal where you will need to type your user account password to finish the command execution.

일반 사용자가 root권한을 잠시 빌려 명령을 실행하게 하는 명령어이다.

Example: sudo “command”

11. Clear the Terminal screen of all previous commands

Command: Clear

What it does: It removes all previously typed commands from the Terminal view and gives you back a clean slate to work from. Instead of typing clear, you can also alternatively press Command+K to perform the same action.

터미널의 내용을 모두 지우는 명령어다.

Example: clear

12. Show manual page for a command

Command: man

What it does: Most commands in the Terminal ship with a manual that allows you to get help or look up arguments and other information on what a command does. Use this man command when you want to find more information about a particular command.

각종 명령어, 프로그램의 사용법(매뉴얼)을 확인한다.

Example: man “command”

profile
나는 개발자다. 5000만큼 코딩한다.

0개의 댓글