SECURITY ::/Linux

Linux 명령어 사전

bbombi 2024. 2. 27. 11:28

 

추가중..

 

 

0. 

 

* help : 

* man [옵션] : 도움말 보기

[root@localhost ~]# man clear

// 설명 뜸 (빠져나올땐 q)
clear(1)                    General Commands Manual                   clear(1)
NAME
       clear - clear the terminal screen

 

* clear : 터미널 내용 삭제

root@ubuntu:~# clear

 

* 시스템 최신화 및 업데이트

 1) apt update : Debian 계열 및 Debian 기반 배포판인 Ubuntu 등에서 사용

 2) yum update : CentOS, RHEL 및 Fedora와 같은 Red Hat 계열의 배포판에서 사용

 

* 구성요소 추가 설치 / 삭제

 1) apt install / remove [패키지명]

 2) yum install / remove [패키지명]

 

* shutdown now : 시스템 즉시 종료

 

 

 

1. 확인/검색/생성/삭제/복사 등

 

* pwd : 현재 경로 확인

vboxbibi@ubuntu:~$ pwd
/home/vboxbibi

 

* cd : 이동

 

* tree : 구조 확인

vboxbibi@ubuntu:/home$ tree

-- vboxbibi
    |-- A
    |   |-- B
    |   |   `-- C
    |   |       `-- test03
    |   `-- test01

 

 

* ls  : 파일 목록 확인

 ls -l : 파일/디렉토리 자세한 정보까지 출력

 ls -a : dot(.)로 시작하는 숨겨진 파일까지 모두 출력

 ls -R : 하위 디렉토리까지 모두 출력

 ls -d : 디렉토리 내용이 아닌 디렉토리 자체를 출력

 ls -lh : 용량 단위도 출력

 

* touch : 파일 생성 -> touch [옵션] 파일이름 or 디렉토리 이름

 touch -a : 기존 파일 access time 수정

 touch -m : 존재하는 파일의 modification time 수정

 touch -t : 특정 시간으로 설정 [[CC]YY]MMDDhhmm[.ss]

 

* mkdir : 디렉토리 생성

cf) 파일과 디렉토리 동시 생성하기

vboxbibi@ubuntu:~$ mkdir -p A/B/C && touch A/B/C/tmp{01..02}
vboxbibi@ubuntu:~$ tree

 

* Wildcard : 파일이름 매칭

 1) {..}

[root@localhost bibi]# ls
공개  다운로드  문서  바탕화면  비디오  사진  서식  음악
[root@localhost bibi]# touch test{01..05}
[root@localhost bibi]# ls
test01  test03  test05  다운로드  바탕화면  사진  음악
test02  test04  공개    문서      비디오    서식

 2) [..]

[root@localhost bibi]# ls test0[1-3]
test01  test02  test03

 

* find : 찾기, 검색

 cf) 파일 size 필터링 해서 찾기

[root@localhost ~]# find /etc -size +500k -size -5M
/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
/etc/ssh/moduli
/etc/services
/etc/selinux/targeted/contexts/files/file_contexts.bin
/etc/selinux/targeted/policy/policy.31
/etc/selinux/targeted/active/policy.kern
/etc/selinux/targeted/active/policy.linked
/etc/brltty/zh-tw.ctb

 

* find -exec : 

ex) -exec 옵션: find 명령어로 찾은 결과 대상에 대해 원하는 명령어 수행

// 홈디렉터리에 1M 이상 파일을 크기까지 나오게 검색
vboxbibi@ubuntu:~$ find ~/ -size +1M -exec ls -lh {} \;

-rw-r--r-- 1 vboxbibi vboxbibi 1.3M  2월 26 12:15 /home/vboxbibi/.cache/mesa_shader_cache/index
-rw-r--r-- 1 vboxbibi vboxbibi 1.3M  2월 26 11:16 /home/vboxbibi/.cache/tracker3/files/http%3A%2F%2Ftracker.api.gnome.org%2Fontology%2Fv3%2Ftracker%23Video.db

 

* mv : 파일 이동

cf)

// A 디렉토리 내의 파일
vboxbibi@ubuntu:~/A/B/C$ ls
tmp01  tmp02

// 상대경로를 사용하여 tmp01을 A 디렉토리에 옮기기
vboxbibi@ubuntu:~/A/B/C$ pwd
/home/vboxbibi/A/B/C
vboxbibi@ubuntu:~/A/B/C$ mv tmp01 ../../

// 절대경로를 사용하여 tmp02를 A 디렉토리에 옮기기
vboxbibi@ubuntu:~/A/B/C$ ls
tmp02
vboxbibi@ubuntu:~/A/B/C$ mv tmp02 /home/vboxbibi/A

// 결과
vboxbibi@ubuntu:~/A$ ls
B  tmp01  tmp02

 

* cp : 복사

 cf) mv 로 tmp 파일 이름을 tmp01로 변경, cp 로 tmp01 을 복제하고 이름은 tmp02로 변경

 

* rm : 삭제

rm -r : 디렉토리 삭제

rm -f : 삭제 확인 메시지 무시하고 강제 삭제

 

 

 

2. 사용자 관리

 

* 계정 정보 확인

 1) whoami : 내 계정 확인

 2) id : 내 권한/그룹 확인 

 3) users

 4) groups

 

* su - : 관리자 계정 전환

vboxbibi@ubuntu:~$ su -
Password: 
root@ubuntu:~#

 

*  su - [username] : 유저 계정으로 전환

root@ubuntu:~# su - vboxbibi
vboxbibi@ubuntu:~$

// 위의 방법보다는 아래처럼 exit 후 전환하는 방법 추천
// 필요하지 않은 쉘 세션은 종료하여 자원 낭비를 방지하기 위함
root@ubuntu:~# exit
logout

 

* users : 현재 로그인한 사용자 목 확인

 

*  sudo adduser [username] : 유저 계정 생성

// ex) userHo 생성
root@ubuntu:~# sudo adduser userHo

// 패스워드 생성, 확인
New password: 
Retype new password: 

// 유저 정보 입력
Enter the new value, or press ENTER for the default
	Full Name []: Ho
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] y

// 유저 생성 확인
root@ubuntu:~# cat /etc/passwd | tail -1
userho:x:1003:1003:Ho,,,:/home/userho:/bin/bash

 

* groups [username] : 유저가 소속된 그룹 확인

root@ubuntu:~# groups userho
userho : userho

 

* sudo groupadd [groupname] : 그룹 생성

root@ubuntu:~# sudo groupadd usergroup

// 생성한 그룹 확인
root@ubuntu:~# cat /etc/group | tail -1
usergroup:x:1004:

 

* sudo gpasswd -a [username] [groupname] : 그룹에 사용자 추가

 

* sudo gpasswd -d [username] [groupname] : 그룹에 사용자 제거

 

* sudo groupdel [그룹명] : 그룹 제거

 

* getent group [groupname] : 그룹 별 사용자 목록 확인

[root@localhost ~]# getent group dev
dev:x:1001:user1,user2

 

 

 

 

3. 파일 및 디렉토리 관리

 

* find / -user [username] : 특정 사용자별 소유 디렉토리와 파일을 확인할 수 있는 명령

// ho 유저가 home 디렉토리 내에서 소유한 것만 검색
[root@localhost bibi]# find /home -user ho
/home/bibi/testdir
/home/bibi/testdir/test1
/home/ho
/home/ho/.mozilla
...

 

* chmod [파일접근권한] [파일명] : 파일의 접근 권한을 변경할 수 있는 명령

* chown [소유자명] [파일명] : 파일의 소유자를 변경할 수 있는 명령

* chown [소유자명].[그룹명] [파일명] : 파일의 소유자와 그룹을 한번에 변경 

[root@localhost bibi]# ls -la
drwxr-xr-x.  2 root root   19  2월 27 11:02 testdir

[root@localhost bibi]# chown -R ho:mine testdir
[root@localhost bibi]# ls -l testdir
합계 0
-rw-r--r--. 1 ho mine 0  2월 27 11:02 test1
[root@localhost bibi]#

 

* chgrp [그룹명] [파일명] : 파일의 그룹을 변경할 수 있는 명령

 

 

 

4. 텍스트 편집기

 

* cat : 파일 내용 출력

* cat [filename] 내용입력 Ctrl+d

[root@localhost bibi]# cat > cattest
// 내용입력
test!!!!!
// ctrl+d

[root@localhost bibi]# cat cattest 
test!!!!!

 

* echo : 문자 출력

* echo "내용입력"> [filename] :

[root@localhost bibi]# echo "HI" > test01
[root@localhost bibi]# cat test01
HI

 

* vi 

cf) $ vimtutor : 다국적 지원 vim 편집기 튜토리얼

     $ vimtutor -g ko