본문 바로가기

linux

리눅스 기본 명령어 정리

728x90
반응형

Command Structure

> command -options arguments

명령어의 대부분(전부X)은 위와 같은 형태로 되어있다.

  • arguments : 파라미터, 피연산자로 명령어가 작업할 값을 제시해줌
# echo는 입력한 argument를 그대로 출력한다. 
> echo test
test

# ncal 2021 < 2021년 모든 달력을 출력 
# ncal july 2021 < 2021년 7월 출력 (순서가 중요함)
  • options : 명령어를 실행할 때 같이 줄 수 있는 다양한 옵션, - 가 붙어야함(대소문자 구분)
# 강조 표시를 끄려고할 때 
> ncal -h 
July 2022
Su     3 10 17 24 31
Mo     4 11 18 25
Tu     5 12 19 26
We     6 13 20 27
Th     7 14 21 28
Fr  1  8 15 22 29
Sa  2  9 16 23 30

# 앞 뒤 달까지 함께 출력 
> ncal -3
    June 2022         July 2022         August 2022
Su     5 12 19 26        3 10 17 24 31     7 14 21 28
Mo     6 13 20 27        4 11 18 25     1  8 15 22 29
Tu     7 14 21 28        5 12 19 26     2  9 16 23 30
We  1  8 15 22 29        6 13 20 27     3 10 17 24 31
Th  2  9 16 23 30        7 14 21 28     4 11 18 25
Fr  3 10 17 24        1  8 15 22 29     5 12 19 26
Sa  4 11 18 25        2  9 16 23 30     6 13 20 27

옵션은 여러가지를 같이 쓸 수 있다.

# 강조를 없애고 앞뒤달까지 포함해서 출력 
>ncal -3 -h

date - 현재 날짜 출력

태평양 표준시로 표시

대소문자를 구분하기 때문에 date라고 정확히 입력해야 한다. (MAC은 구분하지 x)

> date
Fri Jul  1 11:43:22 KST 2022

clear - 터미널 지우기

터미널에 있는 내용을 지우는 명령어

명령어가 취소되는 건 아니고 단지 화면을 지우는 용도

> clear

ncal, cal - 달력 출력

오늘 날짜에 하이라이트 표시

> ncal
    July 2022
Su     3 10 17 24 31
Mo     4 11 18 25
Tu     5 12 19 26
We     6 13 20 27
Th     7 14 21 28
Fr  **1**  8 15 22 29
Sa  2  9 16 23 30

> cal
     July 2022
Su Mo Tu We Th Fr Sa
                **1**  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

man - 매뉴얼 (명령어에 대한 문서)

# q를 누르면 빠져나올 수 있다. 
# 방향키를 눌러서 확인 가능
# /-w 같은 형태로 검색가능
> man date
NAME
       date - print or set the system date and time

SYNOPSIS
			# []<- 안에 있는 값들은 선택 요소
			# ... 1개 이상을 쓸 수 있음 
       date [OPTION]... [+FORMAT]
       date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

DESCRIPTION
       Display the current time in the given FORMAT, or set the system date.

       Mandatory arguments to long options are mandatory for short options too.

       -d, --date=STRING
              display time described by STRING, not 'now'

       --debug
              annotate the parsed date, and warn about questionable usage to stderr

       -f, --file=DATEFILE
              like --date; once for each line of DATEFILE

       -I[FMT], --iso-8601[=FMT]
              output date/time in ISO 8601 format.  FMT='date' for date only (the default), 'hours', 'minutes', 'sec‐
              onds', or 'ns' for date and time to the indicated precision.  Example: 2006-08-14T02:34:56-06:00

       -R, --rfc-email
              output date and time in RFC 5322 format.  Example: Mon, 14 Aug 2006 02:34:56 -0600
 Manual page date(1) line 1 (press h for help or q to quit)

help - 쉘 커맨드는 man 명령어를 사용 X,

> help cd
cd: cd [-L|[-P [-e]] [-@]] [dir]
    Change the shell working directory.

    Change the current directory to DIR.  The default DIR is the value of the
    HOME shell variable.

    The variable CDPATH defines the search path for the directory containing
    DIR.  Alternative directory names in CDPATH are separated by a colon (:).
    A null directory name is the same as the current directory.  If DIR begins
    with a slash (/), then CDPATH is not used.

    If the directory is not found, and the shell option `cdable_vars' is set,
    the word is assumed to be  a variable name.  If that variable has a value,
    its value is used for DIR.

    Options:
      -L        force symbolic links to be followed: resolve symbolic
                links in DIR after processing instances of `..'
      -P        use the physical directory structure without following
                symbolic links: resolve symbolic links in DIR before
                processing instances of `..'
      -e        if the -P option is supplied, and the current working
                directory cannot be determined successfully, exit with
                a non-zero status
      -@        on systems that support it, present a file with extended
                attributes as a directory containing the file attributes

    The default is to follow symbolic links, as if `-L' were specified.
    `..' is processed by removing the immediately previous pathname component
    back to a slash or the beginning of DIR.

    Exit Status:
    Returns 0 if the directory is changed, and if $PWD is set successfully when
    -P is used; non-zero otherwise.

❓/bin 에 있는 바이너리 커맨드와 쉘 커맨드 확인하는 방법은 type 명령어를 써서 확인할 수 있다.

> type date
date is hashed (/usr/bin/date)   # man date 로 확인 

> type cd
cd is a shell builtin  # help cd 로 확인

 

728x90
반응형