backend/ubuntu

[book] The linux command line: working with commands - type, which, man, alias

seul chan 2020. 12. 12. 15:15

5. Working with commands

type: 특정 명령어가 어떤 종류인지 보여주는 명령어

명령어 종류

  • executable program
  • built into the shell itself
  • shell function
  • alias
root@37ba9ce1e69f:/# type ls
ls is aliased to `ls --color=auto'
root@37ba9ce1e69f:/# type type
type is a shell builtin
root@37ba9ce1e69f:/# type cp
cp is /usr/bin/cp

which: display an executable's location

command's documentation

bash는 빌트인 help 도구를 가지고 있음.

root@37ba9ce1e69f:/# help cd
cd: cd [-L|[-P [-e]] [-@]] [dir]
    Change the shell working directory.
    ...

대괄호는 optional item을 얘기함.

--help

많은 executable program은 --help 옵션을 제공한다

man: 프로그램의 manual page

섹션별로 인터페이스가 제공됨.

  • 1: User command
  • 2: Programming interfaces for kernel system calls
  • 3: Programming interfaces to the C library
  • 4: Special files such as device nodes and drivers
  • 5: File formats
  • 6: Games and amusements such as screen savers
  • 7: Miscellaneous
  • 8: System administration commands

위 섹션에서 필요한 부분만 찾을 수 있음

root@37ba9ce1e69f:/# man 5 passwd

apropos: 적절한 명령어를 보여줌

검색어로 특정 man page의 리스트를 볼 수 있다. (요새는 인터넷 검색이 활성화되어서 잘 쓰이지는 않을듯 하지만..)

root@37ba9ce1e69f:/# apropos partition
addpart (8)          - tell the kernel about the existence of a partition
cfdisk (8)           - display or manipulate a disk partition table
delpart (8)          - tell the kernel to forget about a partition
fdisk (8)            - manipulate disk partition table
partx (8)            - tell the kernel about the presence and numbering of on-disk partitions
resizepart (8)       - tell the kernel about the new size of a partition
sfdisk (8)           - display or manipulate a disk partition table

whatis: 한줄로 된 man page

root@37ba9ce1e69f:/# whatis ls
ls (1)               - list directory contents

info: GNU 프로젝트에서 제공하는 man page같은 프로그램.

  • 하이퍼링크 제공
  • info 내부 명령어 써야됨 (?, space, n, p, ENTER, Q 등...)

Creating our own command with alias

alias 명령어를 사용하여 새로운 커맨드를 만들 수 있음.

root@37ba9ce1e69f:/# cd /usr; ls; cd -
bin  games  include  lib  lib32  lib64  libx32  local  sbin  share  src
/
root@37ba9ce1e69f:/# pwd
/
root@37ba9ce1e69f:/# type test
test is a shell builtin
root@37ba9ce1e69f:/# type foo
bash: type: foo: not found
root@37ba9ce1e69f:/# alias foo='cd /usr; ls; cd -'
root@37ba9ce1e69f:/# foo
bin  games  include  lib  lib32  lib64  libx32  local  sbin  share  src
/
root@37ba9ce1e69f:/# type foo
foo is aliased to `cd /usr; ls; cd -'
root@37ba9ce1e69f:/# unalias foo
root@37ba9ce1e69f:/# type foo
bash: type: foo: not found