Giter Site home page Giter Site logo

realbjornroden / unix Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 542 KB

work in progress

License: MIT License

Shell 53.51% Python 30.33% Fortran 0.39% C 5.24% COBOL 0.19% C++ 8.39% Go 0.10% Haskell 0.04% HTML 0.18% Java 0.15% JavaScript 0.04% OpenEdge ABL 0.08% PHP 0.21% Ruby 0.03% Vala 0.06% Elm 0.08% Assembly 0.37% Makefile 0.14% TypeScript 0.45%
unix linux codesamples

unix's Introduction

Proper Desktop Unix

darwin aka macosx
darwin-xnu kernel
Shell and Utilities volume of IEEE POSIX.1-2017

Proper Command Line SHELL

Install Homebrew on macosx

$ curl -fsSL -o install.sh https://raw.githubusercontent.com/Homebrew/install/master/install.sh
$ chmod +x ./install.sh
$ ./install.sh

Install KornShell on macosx

$ brew install ksh

Enable ksh as default shell for the user

$ chsh -s /bin/ksh

Configure ~/.profile

export PS1="\${PWD#*/*/*/} \$ "
export VISUAL=/usr/bin/vi
export EDITOR=/usr/bin/vi

Proper visual EDITOR

vi & vim

Proper TOOLS

gnu tool packages

How To

Copy-Paste text in Terminal

  1. Select text to copy > CTRL-C > Put cursor at insertion point > CTRL-V, and the text is copy-pasted to the insertion point
  2. Put cursor at insertion point > Select text to copy, and then release the mouse/trackpad pressure > Select the marked text and "pull" it slightly until the colored circle with "+" sign appear (direction not important) > Release the mouse/trackpad pressure, and the text is copy-pasted to the insertion point

Configuring a minimalistic but most useful command line prompt

  • For workstation only, don't need username, hostname or wasting a separate line with color time and other non-important information at each and every ENTER

  • For directory structures, in a hierarchical organized filesystems, consider using Partial Relative Path display instead of Absolute Path display (when confused pwd)

    $ pwd
    /home/bjro
    $ export "PS1="\${PWD#*/*/*/} \$ "
    /home/bjro $ code/unix
    code/unix $ pwd
    /home/bjro/code/unix
    code/unix $ cd -
    /home/bjro $ pwer
    /home/bjro
    
  • For multi-user hosts only, where it is common to slip around/jump between hosts over TCP connections, and substitute/change user id (and real rooters don't clobber "/")

    $ export "PS1="$LOGNAME@$(hostname -s):\${PWD#*/*/*/} \$ "
    bjro@server123:code/unix $ ssh honeyp321
    bjro@honeyp321:code/unix $ su - root
    root@honeyp321:/ $ echo $LOGNAME $(hostname -s) $PWD
    root honeyp321 /
    

    For ZSH, PS1 can be defined similarly (~/.zshrc)

    $ export PS1="%n@%m:%2~%(!.#.\$) "
    
  • Defaulting command line editor and command line visual editor (invoked with ESC-v to edit long command line code), add to ~/.profile

    export VISUAL=/usr/bin/vi
    export EDITOR=/usr/bin/vi
    
  • Load environment variables and aliases etc

    • use dot . not source to load, too much to type without functional difference and thus contradict the "unix ethos"
      $ grep PS1 ~/.profile
      export "PS1="\${PWD#*/*/*/} \$ "
      $ . ~/.profile
      code/unix $
      
  • Rename a file with spaces in the name, if it's the only file in the directory (NB. on some shell's need to escape each space separately)

    $ mv * $(echo *|tr ' ' '_')
    

VI editor tips & trix

posix-vi and command line editing features (ESC one time to enter command mode, until insert/append/substitute/change command, then ESC again to get back to command mode). In interactive shell, ESC-v will enter into $VISUAL editor for the command line (save & exit will execute the edited command).
. - Repeat last command
k - Up one line
j - Down one line
w - Right one word
b - Left one word
l - Right one character
h - Left one character
Y - Copy one line
p - Paste copy buffer to after cursor line
P - Paste copy buffer to before cursor line
i - Insert at cursor
I - Insert at begining of line
a - Append after cursor
A - Append after end of line
s - Substitute one character at cursor
S - Substitute the whole line
u - Undo last command
x - Delete one character at cursor
X - Delete one character at cursor move left
dw - Delete one word from cursor forward
db - Delete one word from cursor backward
cw - Change one word from cursor forward
cb - Change one word from cursor backward
. - Repeat the last command, such as change the case of the current charcter
~ - Change the case of the current chararcter to the opposite (UPPER > lower || lower > UPPER)
ZZ - Save file and exit
/ - Enter search mode (down)
? - Enter search mode (up)
: - Enter line command mode
:w - Enter line command mode, and save file
:wq - Enter line command mode, and save file and exit
:wq! - Enter line command mode, and write quit forced
:r /etc/motd - Enter line command mode, and read the content of the file "/etc/motd" into the editor (at the cursor)
:!ls - Enter line command mode, and run the "ls" command in a subshell
:r!ls - Enter line command mode, and run the "ls" command in a subshell, and read the the output into the editor (at the cursor)
:%!sort - Enter line command mode, and for all lines in the file "%", run the "sort" command in a subshell and replace the content of the file
:%s/^XXX/YYY/g - Enter line command mode, and for all lines in the file "%", change all "XXX" on all lines which start with "XXX" to "YYY"
:%s/$/;/g - Enter line command mode, and for all lines in the file "%", add a ";" at the end of each line
:2,$!sort - Enter line command mode, and for all lines from 2 until end of file "2,$", run the "sort" command in a subshell and replace the content of the file (if the file has a header line)
:!rm % - Enter line command mode, and run the "rm" command on the edited filename "%"
:e /etc/motd - Enter line command mode, and open the file /etc/motd into the editor
:n - Enter line command mode, and switch the visual editor to the next file (when editing multiple files)
:e# - Enter line command mode, and switch the visual editor to the previous file (when editing multiple files), toggling :e# flips the editor between two files
:set - Enter line command mode, and show editor configuration settings
:map - Enter line command mode, and show editor key-action mapping

  • Optional initialization command file ~/.exrc, in this case set the tabstop to 4 instead of default 8
set tabstop=4
set expandtab " this is for Python & YAML, to expand each tab to spaces

unix's People

Contributors

realbjornroden avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.