pyratelog

personal blog
git clone git://git.pyratebeard.net/pyratelog.git
Log | Files | Refs | README

20221223-a_mark_of_ecphoneme.md (1209B)


      1 Have you ever created a directory in a long file path, then have to type out the long file path again with `cd`?  Well no more!
      2 ```
      3 mkdir /a/super/long/file/path/to/my/new/directory/
      4 cd !$
      5 ```
      6 
      7 _Note: does not work with all shells. I know bash and zsh work._ 
      8 
      9 In some shells the exclamation mark (!) can be used as an event designator to reference the command history.  A lot of users have probably come across this for running the last command again, maybe if they forgot to use `sudo`
     10 ```
     11 $ pacman -Syu
     12 error: you cannot perform this operation unless you are root.
     13 $ sudo !!
     14 ```
     15 
     16 It can also be used with a number to run that command from the history, for example to run the very first command in your history incant
     17 ```
     18 !1
     19 ```
     20 
     21 Something I use quite a lot is the ability to reference a field from the last command, mostly the last field (`$`).  As shown above you can use it to navigate to a directory you have just created, or anything requiring the last field of the previous command.
     22 
     23 You can also reference the first argument using `!^` or the command word using `!:0`.  Note the colon before the zero.
     24 
     25 These event and word designators are quite extensive so check the manpages for more information.