Skip to content

Instantly share code, notes, and snippets.

@LeCoupa
Last active October 23, 2025 20:35
Show Gist options
  • Save LeCoupa/122b12050f5fb267e75f to your computer and use it in GitHub Desktop.
Save LeCoupa/122b12050f5fb267e75f to your computer and use it in GitHub Desktop.

Revisions

  1. LeCoupa revised this gist Nov 11, 2017. No changes.
  2. LeCoupa revised this gist Nov 9, 2017. No changes.
  3. Julien Le Coupanec revised this gist Nov 5, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -36,8 +36,8 @@ CTRL+V # makes the next character typed verbatim
    CTRL+W # kills the word behind the cursor
    CTRL+X # lists the possible filename completefions of the current word
    CTRL+Y # retrieves (yank) last item killed
    CTRL+Z # stops the current command, resume with fg in the foreground or bg in the background

    CTRL+z # stops the current command, resume with fg in the foreground or bg in the background
    DELETE # deletes one character backward
    !! # repeats the last command
    exit # logs out of current session
  4. Julien Le Coupanec revised this gist Nov 5, 2014. 1 changed file with 16 additions and 6 deletions.
    22 changes: 16 additions & 6 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -17,18 +17,28 @@
    CTRL+A # move to beginning of line
    CTRL+B # moves backward one character
    CTRL+C # halts the current command
    CTRL+D # deletes one character backward
    CTRL+D # deletes one character backward or logs out of current session, similar to exit
    CTRL+E # moves to end of line
    CTRL+F # moves forward one character
    CTRL+G # aborts the current editing command and ring the terminal bell
    CTRL+J # same as RETURN
    CTRL+K # deletes (kill) forward to end of line
    CTRL+L # clears screen and redisplay the line

    ctrl+z # stops the current command, resume with fg in the foreground or bg in the background
    ctrl+d # logs out of current session, similar to exit
    ctrl+w # erases one word in the current line
    ctrl+u # erases the whole line
    CTRL+M # same as RETURN
    CTRL+N # next line in command history
    CTRL+O # same as RETURN, then displays next line in history file
    CTRL+P # previous line in command history
    CTRL+R # searches backward
    CTRL+S # searches forward
    CTRL+T # transposes two characters
    CTRL+U # kills backward from point to the beginning of line
    CTRL+V # makes the next character typed verbatim
    CTRL+W # kills the word behind the cursor
    CTRL+X # lists the possible filename completefions of the current word
    CTRL+Y # retrieves (yank) last item killed

    CTRL+z # stops the current command, resume with fg in the foreground or bg in the background
    DELETE # deletes one character backward
    !! # repeats the last command
    exit # logs out of current session

  5. Julien Le Coupanec revised this gist Nov 5, 2014. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,12 @@ CTRL+A # move to beginning of line
    CTRL+B # moves backward one character
    CTRL+C # halts the current command
    CTRL+D # deletes one character backward
    CTRL+E # moves to end of line
    CTRL+F # moves forward one character
    CTRL+G # aborts the current editing command and ring the terminal bell
    CTRL+J # same as RETURN
    CTRL+K # deletes (kill) forward to end of line
    CTRL+L # clears screen and redisplay the line

    ctrl+z # stops the current command, resume with fg in the foreground or bg in the background
    ctrl+d # logs out of current session, similar to exit
  6. Julien Le Coupanec revised this gist Nov 5, 2014. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,22 @@
    #####################################################


    # 0. Shortcuts.


    CTRL+A # move to beginning of line
    CTRL+B # moves backward one character
    CTRL+C # halts the current command
    CTRL+D # deletes one character backward

    ctrl+z # stops the current command, resume with fg in the foreground or bg in the background
    ctrl+d # logs out of current session, similar to exit
    ctrl+w # erases one word in the current line
    ctrl+u # erases the whole line
    !! # repeats the last command
    exit # logs out of current session


    # 1. Bash Basics.


  7. Julien Le Coupanec revised this gist Nov 5, 2014. 1 changed file with 0 additions and 14 deletions.
    14 changes: 0 additions & 14 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -374,17 +374,3 @@ function returntrap {

    trap returntrap RETURN # is executed each time a shell function or a script executed with the . or source commands finishes executing


    # 8. Shortcuts.

    CTRL+A # move to beginning of line
    CTRL+B # moves backward one character
    CTRL+C # halts the current command
    CTRL+D # deletes one character backward

    ctrl+z # stops the current command, resume with fg in the foreground or bg in the background
    ctrl+d # logs out of current session, similar to exit
    ctrl+w # erases one word in the current line
    ctrl+u # erases the whole line
    !! # repeats the last command
    exit # logs out of current session
  8. Julien Le Coupanec revised this gist Nov 5, 2014. 1 changed file with 14 additions and 12 deletions.
    26 changes: 14 additions & 12 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -100,18 +100,6 @@ dig -x <host> # reverses lookup host
    wget <file> # downloads file


    # 1.4. Shortcuts.


    ctrl+c # halts the current command
    ctrl+z # stops the current command, resume with fg in the foreground or bg in the background
    ctrl+d # logs out of current session, similar to exit
    ctrl+w # erases one word in the current line
    ctrl+u # erases the whole line
    !! # repeats the last command
    exit # logs out of current session


    # 2. Basic Shell Programming.


    @@ -386,3 +374,17 @@ function returntrap {

    trap returntrap RETURN # is executed each time a shell function or a script executed with the . or source commands finishes executing


    # 8. Shortcuts.

    CTRL+A # move to beginning of line
    CTRL+B # moves backward one character
    CTRL+C # halts the current command
    CTRL+D # deletes one character backward

    ctrl+z # stops the current command, resume with fg in the foreground or bg in the background
    ctrl+d # logs out of current session, similar to exit
    ctrl+w # erases one word in the current line
    ctrl+u # erases the whole line
    !! # repeats the last command
    exit # logs out of current session
  9. Julien Le Coupanec revised this gist Nov 4, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -169,7 +169,7 @@ $(UNIX command) # command substitution: runs the command and return

    # 2.2. Functions.
    # The function refers to passed arguments by position (as if they were positional parameters), that is, $1, $2, and so forth.
    # $@ is equal to "$1" "$2"... "$N", where N is the number of positional paramaters. $# holds the number of positional parameters.
    # $@ is equal to "$1" "$2"... "$N", where N is the number of positional parameters. $# holds the number of positional parameters.


    functname() {
  10. Julien Le Coupanec revised this gist Nov 4, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    #####################################################
    # Name: Bash CheatSheet for Mac OSX
    #
    # A little overlook of all the things you can do
    # A little overlook of the Bash basics
    #
    # Usage:
    #
  11. Julien Le Coupanec revised this gist Nov 4, 2014. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,14 @@
    # Bash CheatSheet for Mac OSX
    # http://www.gnu.org/software/bash/manual/bashref.html
    #!/bin/bash
    #####################################################
    # Name: Bash CheatSheet for Mac OSX
    #
    # A little overlook of all the things you can do
    #
    # Usage:
    #
    # Author: J. Le Coupanec
    # Date: 2014/11/04
    #####################################################


    # 1. Bash Basics.
  12. Julien Le Coupanec revised this gist Oct 31, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -112,7 +112,7 @@ exit # logs out of current session
    varname=value # defines a variable
    varname=value command # defines a variable to be in the environment of a particular subprocess
    echo $varname # checks a variable's value
    echp $$ # prints process ID of the current shell
    echo $$ # prints process ID of the current shell
    echo $! # prints process ID of the most recently invoked background job
    echo $? # displays the exit status of the last command
    export VARNAME=value # defines an environment variable (will be available in subprocesses)
  13. Julien Le Coupanec revised this gist Oct 30, 2014. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -370,3 +370,10 @@ function dbgtrap {
    trap dbgtrap DEBUG # causes the trap code to be executed before every statement in a function or script
    # ...section of code in which the problem occurs...
    trap - DEBUG # turn off the DEBUG trap

    function returntrap {
    echo "A return occured"
    }

    trap returntrap RETURN # is executed each time a shell function or a script executed with the . or source commands finishes executing

  14. Julien Le Coupanec revised this gist Oct 30, 2014. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -362,3 +362,11 @@ function errtrap {
    }

    trap 'errtrap $LINENO' ERR # is run whenever a command in the surrounding script or function exists with non-zero status

    function dbgtrap {
    echo "badvar is $badvar"
    }

    trap dbgtrap DEBUG # causes the trap code to be executed before every statement in a function or script
    # ...section of code in which the problem occurs...
    trap - DEBUG # turn off the DEBUG trap
  15. Julien Le Coupanec revised this gist Oct 30, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -356,7 +356,6 @@ set -o xtrace # alternative (set option in script)

    trap 'echo $varname' EXIT # useful when you want to print out the values of variables at the point that your script exits


    function errtrap {
    es=$?
    echo "ERROR line $1: Command exited with status $es."
  16. Julien Le Coupanec revised this gist Oct 30, 2014. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -355,3 +355,11 @@ bash -x scriptname # echo commands after command-line processing
    set -o xtrace # alternative (set option in script)

    trap 'echo $varname' EXIT # useful when you want to print out the values of variables at the point that your script exits


    function errtrap {
    es=$?
    echo "ERROR line $1: Command exited with status $es."
    }

    trap 'errtrap $LINENO' ERR # is run whenever a command in the surrounding script or function exists with non-zero status
  17. Julien Le Coupanec revised this gist Oct 30, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -354,4 +354,4 @@ set -o verbose # alternative (set option in script)
    bash -x scriptname # echo commands after command-line processing
    set -o xtrace # alternative (set option in script)

    trap 'echo $varname' EXIT # useful when you want to print out the values of variable at the point that your script exits
    trap 'echo $varname' EXIT # useful when you want to print out the values of variables at the point that your script exits
  18. Julien Le Coupanec revised this gist Oct 30, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -354,3 +354,4 @@ set -o verbose # alternative (set option in script)
    bash -x scriptname # echo commands after command-line processing
    set -o xtrace # alternative (set option in script)

    trap 'echo $varname' EXIT # useful when you want to print out the values of variable at the point that your script exits
  19. Julien Le Coupanec revised this gist Oct 30, 2014. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -340,3 +340,17 @@ cd; nano .bashrc

    source .bashrc
    cd websites


    # 7. Debugging Shell Programs.


    bash -n scriptname # don't run commands; check for syntax errors only
    set -o noexec # alternative (set option in script)

    bash -v scriptname # echo commands before running them
    set -o verbose # alternative (set option in script)

    bash -x scriptname # echo commands after command-line processing
    set -o xtrace # alternative (set option in script)

  20. Julien Le Coupanec revised this gist Oct 29, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -323,6 +323,8 @@ trap - sig1 sig2 # resets the action taken when the signal is received to the

    disown <PID|JID> # removes the process from the list of jobs

    wait # waits until all background jobs have finished


    # 6. Tips and Tricks.

  21. Julien Le Coupanec revised this gist Oct 29, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -319,6 +319,7 @@ ps -a # selects all processes with a tty except session leaders

    trap cmd sig1 sig2 # executes a command when a signal is received by the script
    trap "" sig1 sig2 # ignores that signals
    trap - sig1 sig2 # resets the action taken when the signal is received to the default

    disown <PID|JID> # removes the process from the list of jobs

  22. Julien Le Coupanec revised this gist Oct 29, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -322,6 +322,7 @@ trap "" sig1 sig2 # ignores that signals

    disown <PID|JID> # removes the process from the list of jobs


    # 6. Tips and Tricks.


  23. Julien Le Coupanec revised this gist Oct 29, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -320,6 +320,7 @@ ps -a # selects all processes with a tty except session leaders
    trap cmd sig1 sig2 # executes a command when a signal is received by the script
    trap "" sig1 sig2 # ignores that signals

    disown <PID|JID> # removes the process from the list of jobs

    # 6. Tips and Tricks.

  24. Julien Le Coupanec revised this gist Oct 29, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -318,6 +318,7 @@ ps # prints a line of information about the current running login shel
    ps -a # selects all processes with a tty except session leaders

    trap cmd sig1 sig2 # executes a command when a signal is received by the script
    trap "" sig1 sig2 # ignores that signals


    # 6. Tips and Tricks.
  25. Julien Le Coupanec revised this gist Oct 29, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -112,6 +112,8 @@ exit # logs out of current session
    varname=value # defines a variable
    varname=value command # defines a variable to be in the environment of a particular subprocess
    echo $varname # checks a variable's value
    echp $$ # prints process ID of the current shell
    echo $! # prints process ID of the most recently invoked background job
    echo $? # displays the exit status of the last command
    export VARNAME=value # defines an environment variable (will be available in subprocesses)

    @@ -298,7 +300,6 @@ n<&- # closes the input from file descripor n
    # This is slightly different from CTRL+Z in that the process is only stopped when it attempts to read input from terminal.
    # Of course, to interupt a job, type CTRL+C.


    myCommand & # runs job in the background and prompts back the shell

    jobs # lists all jobs (use with -l to see associated PID)
  26. Julien Le Coupanec revised this gist Oct 29, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -316,6 +316,8 @@ kill PID # terminates process with specified PID
    ps # prints a line of information about the current running login shell and any processes running under it
    ps -a # selects all processes with a tty except session leaders

    trap cmd sig1 sig2 # executes a command when a signal is received by the script


    # 6. Tips and Tricks.

  27. Julien Le Coupanec revised this gist Oct 29, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,8 @@ echo $BASH_VERSION # displays bash version
    bash # if you want to use bash (type exit to go back to your normal shell)
    whereis bash # finds out where bash is on your system

    clear # clears content on window (hide displayed lines)


    # 1.1. File Commands.

  28. Julien Le Coupanec revised this gist Oct 29, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -312,6 +312,7 @@ kill -l # returns a list of all signals on the system, by name and number
    kill PID # terminates process with specified PID

    ps # prints a line of information about the current running login shell and any processes running under it
    ps -a # selects all processes with a tty except session leaders


    # 6. Tips and Tricks.
  29. Julien Le Coupanec revised this gist Oct 29, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -311,6 +311,8 @@ fg %?string # brings job whose command contains string
    kill -l # returns a list of all signals on the system, by name and number
    kill PID # terminates process with specified PID

    ps # prints a line of information about the current running login shell and any processes running under it


    # 6. Tips and Tricks.

  30. Julien Le Coupanec revised this gist Oct 29, 2014. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions bash-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -299,7 +299,7 @@ n<&- # closes the input from file descripor n

    myCommand & # runs job in the background and prompts back the shell

    jobs # lists all jobs (use with -l to see associated PID)
    jobs # lists all jobs (use with -l to see associated PID)

    fg # brings a background job into the foreground
    fg %+ # brings most recently invoked background job
    @@ -308,7 +308,8 @@ fg %N # brings job number N
    fg %string # brings job whose command begins with string
    fg %?string # brings job whose command contains string


    kill -l # returns a list of all signals on the system, by name and number
    kill PID # terminates process with specified PID


    # 6. Tips and Tricks.