Skip to content

minority opinions

Menu
  • Home
  • 꿀팁정리 & 자기계발
  • 기술 정보 & 테크 소식
  • 이슈 뉴스 정리
  • 주식 경제
  • Tags
Menu

리눅스 기본 명령어 총정리

Posted on 2월 14, 20227월 8, 2023 by Daniel J.

Basic Linux Commands

Linux OS에서 자주쓰이며 가장 중요한 20가지 명령어에 대하여 알아보겠습니다. 

1. ls


디렉토리를 나열하는 명령어. Windows OS의 dir 과 같음.  리눅스에서 ls command는 파일과 디렉토리를 나열하는데 사용됩니다. 

ls -l | more  페이지별로 볼수 있도록 출력 페이지 번호를 출력 됩니다.

$ ls -l Filename
$ ls -al | more

ls -l 을 사용하면 디렉토리나 파일의 자세한 내용을 볼수있습니다.

  • 파일 권한 (File Permissions)
  • 파일 소유자 (File Owner)
  • 파일 그룹 (File Group)
  • 파일 크기 (File Size)
  • 타임스탬프 (time stamp)
  • 파일 이름 (File Name)

2. cd /var/log


cd 명령어는 change directory 의 약자로 현재 디렉토리를 변경하는 명령어입니다.

$ cd /var/log
$ cd -

3. grep 


grep 명령어는 file 내용중 특정 패턴에 일치하는 텍스트를 찾는데 사용됩니다.

grep은 한번에 많은 파일을 검색하여 원하는 텍스트를 찾을수도 있습니다.

grep Pattern file

grep success apache.log

$ grep 'success' apache.log
$ grep -r 'fail' /var/log/nginx

4. su / sudo 명령어


Linux 시스템에서 실행하려면 상승된 권한이 필요한 몇 가지 명령이 있습니다. 따라서 일반 사용자가 수행할 수 없는 시스템 관리자로 실행합니다.
su 명령은 shell을 super user로 사용하도록 변경하고 exit 명령을 사용할 때까지 계속해서 Super User 권한이  될 수 있습니다.

sudo – 는 슈퍼 유저로 무언가를 실행해야 하는 경우 sudo 명령을 사용할 수 있습니다. 이렇게 하면 상승된 권한으로 명령을 실행할 수 있으며 명령이 실행되면 일반 권한과 권한으로 돌아갑니다.

Example – 리눅스 종료 명령 시스템을 안전하게 끕니다.

sudo shutdown 2 : 2분 후 컴퓨터 종료 및 전원 끄기
sudo shutdown –r 2 : 종료되고 2분 후에 재부팅됩니다.
ctrl C 또는 shutdown –c 를 사용 하면 종료 프로세스를 중지하는 데 도움이 됩니다.

$ sudo shutdown 2
$ sudo shutdown -r 2

5. pwd (현재 작업 디렉토리 출력)


pwd 명령어는 현재 작업 디렉토리의 경로를 표시하며 cd 로 디렉토리 변경이 자주 있을때 유용합니다.

$ pwd

6. passwd command


pwd 명령 과 비슷해 보이지만 전혀 역할이 다른 명령어 입니다.


이 명령은 사용자 계정의 암호를 변경하는데 사용됩니다. 로그인 계정의 비밀번호나 다른 사용자의 비밀번호를 변경할 수 있습니다. 일반 시스템 사용자는 자신의 암호만 변경할 수 있는 반면 root 는 모든 계정의 암호를 수정할 수 있습니다.

passwd [username] 

$ passwd guest
$ passwd  (현재 계정 암호변경)

7. mv  파일 이동


파일 이나 디렉토리 이름을 바꾸거나 이동할때 사용되는 리눅스 명령어 입니다.

$ mv before.txt after.txt
$ mv directory01 directory02

8. cp 파일 복사


파일이나 디렉토리를 복사할때 사용되는 명령어 입니다.

$ cp sourcefile.txt copyfile.txt

$ cp -arv /var/log/apache /var/log/apache2

9. rm 파일및 디렉토리 삭제


rm 명령은 디렉토리 또는 디렉토리 자체에 있는 파일을 제거하는 데 사용됩니다. 디렉토리가 비어 있지 않으면 제거할 수 없습니다

rm [filename]

rm -r 은 디렉토리 전체 삭제

rm 명령어는 주의하여 사용해야합니다.

$ rm *

$ rm file01

$ rm -r /var/log/temp

10. mkdir 디렉토리 생성 명령어


mkdir [디렉토리 이름]  

$ mkdir /root/...
$ mkdir /var/log/elastic
[root@dscan log]# mkdir --help
사용법: mkdir [옵션]... 디렉터리...
Create the DIRECTORY(ies), if they do not already exist.

Mandatory arguments to long options are mandatory for short options too.
  -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask
  -p, --parents     no error if existing, make parent directories as needed
  -v, --verbose     print a message for each created directory
  -Z                   set SELinux security context of each created directory
                         to the default type
      --context[=CTX]  like -Z, or if CTX is specified then set the SELinux
                         or SMACK security context to CTX
      --help     이 도움말을 표시하고 끝냅니다
      --version  버전 정보를 출력하고 끝냅니다

11. chmod 


파일의 실행 권한을 변경합니다.

r 읽기

w 쓰기

x 실행권한

Example

  • chmod 755 test-script.sh
  • 첫 번째 숫자7  파일과 연결된 사용자를 나타냅니다.
  • 두 번째 숫자5  파일과 연결된 그룹을 위한 것입니다.
  • 세 번째 숫자5 사용자 또는 그룹의 일부가 아닌 다른 모든 사람을 의미합니다.
Octal NotationPermissionSymbolic Representation
0No Permission—
1Execute Permission Only–x
2Write Permission Only-w-
3Write and Execute Permissions (1+2)=3-wx
4Read Permission Onlyr–
5Read and Execute Permissions (1+4)=5r-x
6Read and Write Permissions (2+4)=6rw-
7Read, Write and Execute Permissions, Means Full Permissions (1+2+4)=7rwx
  • -rwxr- – r- – 사용자용 rwx
  • r – – 그룹용(읽기 전용)
  • r – – 기타(읽기 전용)

chmod 를 사용하는 다른 방법은 다음과 같습니다 .

chmod aw testfile.txt
이는 모든 사용자에게 testfile.txt 파일에 대한 쓰기 권한이 없음을 의미합니다.

chmod u + x test-script.sh
test-script.sh의 소유자는 파일을 실행할 수 있습니다.

$ chmod 755 test-script.sh
$ chmod aw testfile.sh
$ chmod u+x test-script.sh
[root@dscan log]# chown --help
사용법: chown [옵션]... [소유자][:[그룹]] 파일...
  또는:  chown [옵션]... --reference=참조파일 파일...
Change the owner and/or group of each FILE to OWNER and/or GROUP.
With --reference, change the owner and group of each FILE to those of RFILE.

  -c, --changes          like verbose but report only when a change is made
  -f, --silent, --quiet  suppress most error messages
  -v, --verbose          output a diagnostic for every file processed
      --dereference      affect the referent of each symbolic link (this is
                         the default), rather than the symbolic link itself
  -h, --no-dereference   affect symbolic links instead of any referenced file
                         (useful only on systems that can change the
                         ownership of a symlink)
      --from=CURRENT_OWNER:CURRENT_GROUP
                         change the owner and/or group of each file only if
                         its current owner and/or group match those specified
                         here.  Either may be omitted, in which case a match
                         is not required for the omitted attribute
      --no-preserve-root  do not treat '/' specially (the default)
      --preserve-root    fail to operate recursively on '/'
      --reference=RFILE  use RFILE's owner and group rather than
                         specifying OWNER:GROUP values
  -R, --recursive        operate on files and directories recursively

The following options modify how a hierarchy is traversed when the -R
option is also specified.  If more than one is specified, only the final
one takes effect.

  -H                     if a command line argument is a symbolic link
                         to a directory, traverse it
  -L                     traverse every symbolic link to a directory
                         encountered
  -P                     do not traverse any symbolic links (default)

      --help     이 도움말을 표시하고 끝냅니다
      --version  버전 정보를 출력하고 끝냅니다

Owner is unchanged if missing.  Group is unchanged if missing, but changed
to login group if implied by a ':' following a symbolic OWNER.
OWNER and GROUP may be numeric as well as symbolic.

예제:
  chown root /u        /u의 소유자를 "root"로 바꿈
  chown root:staff /u  똑같으나, 그룹은 "staff"로 바꿈
  chown -hR root /u    /u와 하위 파일의 소유자를 "root"로 바꿈

12. chown 소유권 변경 명령어


사용자, 그룹에 대한 파일이나 폴더 또는 여러 파일, 폴더의 소유권을 변경하는 데 사용됩니다.

chown user001 test-script.sh
chown -R elastic:elastic /var/log/elasic

13. cat 명령어 


cat 명령(“concatenate” 의 줄임말)은 Linux에서 가장 자주 사용되는 명령 중 하나입니다. cat 명령을 사용하면 단일 또는 여러 파일을 만들고, 파일 내용을 보고, 파일을 연결하고, 터미널 또는 파일에서 출력을 리디렉션할 수 있습니다.

$ cat testfile.log
$ cat file01.log file02.log file03.log
$ cat 1.txt 2.txt > 3.txt

14. echo 


echo linux command는 텍스트 또는 문자열을 표준 출력이나 파일에 표시하는 데 사용됩니다.
echo -e 옵션은 백슬래시가 있는 이스케이프 문자를 해석하는 역할을 합니다.

$ echo -e "Linux Basic Commands. \nBest Linux Commands List."
linux echo command example

15. wc 


Linux 운영 체제 의 wc (단어 수) 명령은 파일 인수로 지정된 파일의 새 줄 수, 단어 수, 바이트 및 문자 수를 찾는 데 사용됩니다.

  • wc -l : 파일의 줄 수를 출력
  • wc -w : 파일의 단어 수를 출력
  • wc -c : 파일의 바이트 수를 표시
  • wc -m : 파일의 문자 수를 출력
  • wc -L : 파일에서 가장 긴 줄의 길이만 출력
$ wc -l auth.log

16. man


linux man 명령은 명령/프로그램에 대한 온라인 참조 매뉴얼 페이지를 보는 데 사용됩니다.

man grep
man sed
man awk
man ls

17. history


history 명령은 이전에 사용한 명령을 표시하거나 사용자가 실행한 명령에 대한 정보를 가져오는 데 사용됩니다

$ history

[root@dscan log]# history --help
history: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
    Display or manipulate the history list.
    
    Display the history list with line numbers, prefixing each modified
    entry with a `*'.  An argument of N lists only the last N entries.
    
    Options:
      -c	clear the history list by deleting all of the entries
      -d offset	delete the history entry at position OFFSET.
    
      -a	append history lines from this session to the history file
      -n	read all history lines not already read from the history file
    		and append them to the history list
      -r	read the history file and append the contents to the history
    		list
      -w	write the current history to the history file
    
      -p	perform history expansion on each ARG and display the result
    		without storing it in the history list
      -s	append the ARGs to the history list as a single entry
    
    If FILENAME is given, it is used as the history file.  Otherwise,
    if HISTFILE has a value, that is used, else ~/.bash_history.
    
    If the HISTTIMEFORMAT variable is set and not null, its value is used
    as a format string for strftime(3) to print the time stamp associated
    with each displayed history entry.  No time stamps are printed otherwise.
    
    Exit Status:
    Returns success unless an invalid option is given or an error occurs.

18. clear


clear 명령은 터미널 화면을 전체 지울때 사용됩니다.

ssh 접속 tool의 특징마다 가끔 단축키도 사용됩니다. control key + l  -> terminal screen clear

[root@dscan log]# clear --help
clear: invalid option -- '-'
Usage: clear [options]

Options:
  -T TERM     use this instead of $TERM
  -V          print curses-version
  -x          do not try to clear scrollback

19. apt-get 


apt -get 은 데비안/우분투 시스템을 위한 강력하고 무료인 프론트엔드 패키지 관리자입니다. 새 소프트웨어 패키지를 설치하고, 사용 가능한 소프트웨어 패키지를 제거하고, 기존 소프트웨어 패키지를 업그레이드하고, 전체 운영 체제를 업그레이드하는 데 사용됩니다. apt – 고급 패키징 도구를 나타냅니다.

$ apt-get update
$ apt-get install apache2
$ apt-get remove tomcat9
$ apt-cache stats

20. reboot 


Linux 시스템을 정지, 전원 끄기 또는 재부팅하는 데 사용할 수 있습니다

[root@dscan log]# reboot --help
reboot [OPTIONS...] [ARG]

Reboot the system.

     --help      Show this help
     --halt      Halt the machine
  -p --poweroff  Switch off the machine
     --reboot    Reboot the machine
  -f --force     Force immediate halt/power-off/reboot
  -w --wtmp-only Don't halt/power-off/reboot, just write wtmp record
  -d --no-wtmp   Don't write wtmp record
     --no-wall   Don't send wall message before halt/power-off/reboot

이 글 공유하기:

  • 페이스북에 공유하려면 클릭하세요. (새 창에서 열림) Facebook
  • 클릭하여 X에서 공유 (새 창에서 열림) X
  • 인쇄하기 (새 창에서 열림) 인쇄
  • 클릭하여 친구에게 이메일로 링크 보내기 (새 창에서 열림) 전자우편
  • Telegram에 공유하려면 클릭하세요. (새 창에서 열림) Telegram
  • WhatsApp에 공유하려면 클릭하세요. (새 창에서 열림) WhatsApp

이것이 좋아요:

좋아하기 가져오는 중...

관련

답글 남기기 응답 취소

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

Category

  • Article (66)
  • Uncategorized (178)
  • 게임 소식 (13)
  • 기술 정보 & 테크 소식 (260)
  • 꿀팁정리 & 자기계발 (317)
  • 블로그 (26)
  • 사건 사고 (64)
  • 역사 (35)
  • 영화 & 드라마 & 애니메이션 (27)
  • 이슈 뉴스 정리 (207)
  • 정치 인물 사회 (122)
  • 주식 경제 (119)

Recent Posts

  • 위고비(Wegovy) 효능과 가격(1펜) 정리

    위고비(Wegovy) 효능과 가격(1펜) 정리

    2월 16, 2025
  • 도메인 URL 주소 단축하는 사이트 모음

    도메인 URL 주소 단축하는 사이트 모음

    1월 30, 2025
  • 5년전 정혜수 MBC 기상캐스터가 해고당하면서 올린 글

    5년전 정혜수 MBC 기상캐스터가 해고당하면서 올린 글

    1월 28, 2025
  • MBC 기상캐스터 오요안나 자살과 집단 괴롭힘 가해자

    MBC 기상캐스터 오요안나 자살과 집단 괴롭힘 가해자

    1월 27, 2025
  • 홍장원 전 국정원 1차장 좌파이력 정리

    홍장원 전 국정원 1차장 좌파이력 정리

    1월 22, 2025

Popular Posts

©2025 minority opinions | Design: Newspaperly WordPress Theme
%d