grimoire

personal wiki
git clone git://git.pyratebeard.net/grimoire.git
Log | Files | Refs

bash.md (1007B)


      1 # bash
      2 
      3 use parameter of previous command ([ref 1][1])
      4 ```
      5 mkdir test
      6 cd $_
      7 ```
      8 or
      9 ```
     10 mkdir test
     11 cd !$
     12 ```
     13 
     14 ## `find` examples
     15 ```
     16 find . -type f -iname "*regex*" -exec rm -f {} \;
     17 ```
     18 
     19 ## when was user created ([ref_2][2])
     20 - if user has never logged in after account creation
     21     ```
     22     ls -l /home/<user>/.bash_logout
     23     ```
     24 
     25 ## run bg job and log out
     26 after 'ctrl-z'
     27 ```
     28 disown -h %1
     29 bg 1
     30 logout
     31 ```
     32 _where 1 is the job number_
     33 
     34 ;  Command 1 ; Command 2  Run command 1 first and then command 2
     35 && Command 1 && Command 2 Run command 2 only if command 1 ends sucessfully
     36 || Command 1 || Command 2 Run command 2 only if command 1 fails
     37 
     38 ## sneaky workarounds
     39 * disable logoug timeout ([stackexchange][3])
     40 ```
     41 if [ ! -z "$TMOUT" ]; then
     42   env -i bash --init-file ~/.bash_profile
     43 fi
     44 ```
     45 
     46 ## ref
     47 [1]: https://unix.stackexchange.com/questions/125385/combined-mkdir-and-cd
     48 [2]: https://it.toolbox.com/question/how-to-find-out-when-a-user-is-created-in-linux-030612
     49 [3]: https://unix.stackexchange.com/a/222311