Linux 명령 기호 !ls 의미

Linux 명령 기호 !ls 의미

의 의미는 무엇입니까! 명령으로? 예를 들어 ls 명령을 입력한 후의 출력은 무엇입니까(!ls)?

답변1

ls이는 나에게 지적된 대로 시작하는 기록 목록의 마지막 명령을 실행하는 것을 의미합니다 . 마지막으로 명령을 실행한 경우 lsb_release해당 명령이 실행됩니다. 명령만 실행하면 ls디렉토리 목록이 표시됩니다. 지정한 내용으로 시작하는 마지막 또는 가장 최근 명령을 실행합니다.

시스템에서 실행하면 history실행한 모든 명령이 표시됩니다. 그리고 기록에서 특정 명령을 원한다면 이전 명령 !#인 .!1990cd

기록 출력 예:

 1990  cd
 1991  sync
 1992  ssh [email protected]
 1993  sync
 1994  sync
 1995  sudo apt autoremove
 1996  reboot
 1997  sudo apt remove nvidia-driver-430
 1998  sudo apt install nvidia-driver-435
 1999  sudo apt autoremove
 2000  reboot
 2001  ./intrepid_check.bsh 
 2002  ssh intrepid
 2003  ls -al
 2004  ls
 2005  ls -al
 2006  history
terrance@terrance-ubuntu:~$

그리고 해당 목록의 마지막 명령을 실행하려면 ssh다음과 같이 입력합니다.

!ssh

예:

terrance@terrance-ubuntu:~$ !ssh
ssh intrepid
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 5.0.0-29-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

 * Congrats to the Kubernetes community on 1.16 beta 1! Now available
   in MicroK8s for evaluation and testing, with upgrades to RC and GA

     snap info microk8s

 * Canonical Livepatch is enabled.
   - All available patches applied.

0 packages can be updated.
0 updates are security updates.

Your Hardware Enablement Stack (HWE) is supported until April 2023.
You have mail.
Last login: Wed Sep 25 21:38:55 2019 from 10.0.0.100
-------------------------------------------------------------- 09/25/19 21:43:36
terrance@Intrepid:~$ 

도움이 되었기를 바랍니다!

답변2

읽다 man bash. 부분적으로는 다음과 같이 말합니다.

Event Designators
   An  event  designator  is a reference to a command line entry in the history list.  Unless
   the reference is absolute, events are relative to the  current  position  in  the  history
   list.

   !      Start  a  history  substitution, except when followed by a blank, newline, carriage
          return, = or ( (when the extglob shell option is enabled using the shopt builtin).
   !n     Refer to command line n.
   !-n    Refer to the current command minus n.
   !!     Refer to the previous command.  This is a synonym for `!-1'.
   !string
          Refer to the most recent command preceding the current position in the history list
          starting with string.
   !?string[?]
          Refer to the most recent command preceding the current position in the history list
          containing string.  The trailing ? may be omitted if string is followed immediately
          by a newline.
   ^string1^string2^
          Quick  substitution.   Repeat the previous command, replacing string1 with string2.
          Equivalent to ``!!:s/string1/string2/'' (see Modifiers below).
   !#     The entire command line typed so far.

관련 정보