Skip to content

Instantly share code, notes, and snippets.

@alexandre-delaloy
Last active March 16, 2023 12:25
Show Gist options
  • Save alexandre-delaloy/b05a8bf28eaef095c47d7d9c788fce61 to your computer and use it in GitHub Desktop.
Save alexandre-delaloy/b05a8bf28eaef095c47d7d9c788fce61 to your computer and use it in GitHub Desktop.

Revisions

  1. alexandre-delaloy revised this gist Mar 16, 2023. 1 changed file with 280 additions and 42 deletions.
    322 changes: 280 additions & 42 deletions bash-command-line-cheatsheet.txt
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,15 @@
    ------------------------------------------------------------------------------------------------
    | BASH COMMAND LINE CHEATSHEET |
    | BASH COMMAND LINE CHEATSHEET |
    | |
    | by Alexandre Delaloy - @blyndusk |
    | by Alexandre Delaloy - @blyndusk |
    ------------------------------------------------------------------------------------------------


    MY NOTATION
    ---- ----
    [1] - GENERAL & SYSTEM


    [1.0] - MY NOTATION
    ----
    [D] Directory
    [D...] Directory, directories
    [F] File
    @@ -15,95 +18,211 @@ MY NOTATION
    [FD...] File, files, directory, directories


    GETTING HELP
    ---- ----
    man [command] Read the manual for a given command
    [command] -h | --help Ask the command for help
    [1.1] - GETTING HELP
    ----
    man [cmd] Read the manual for a given command
    [cmd] -h | --help Ask the command for help
    E.G.
    man chmod
    chmod -h


    LISTING FILE(S) AND DIRECTOR(Y/IES) CONTENT
    ---- ----
    [1.2] - GET INFORMATIONS
    ----
    uname -archive Display system and kernel
    date Display system date
    uptime Display uptime
    top Display live informations about currently processes
    whoami Display your username
    clear Clear the current terminal


    [1.3] - SHUTDOWN THE SYSTEM AT A GIVEN TIME
    ----
    shutdown [TIME] Shutdown the system at [TIME]
    -- --
    shutdown -s [TIME] The system is put to sleep at [TIME]
    shutdown -r [TIME] The system is rebooted at [TIME]
    shutdown -h [TIME] The system is halted at [TIME]
    E.G.
    shutdown -h now
    shutdown -r 8:00


    [1.4] - ENVIRONMENT VARIABLES
    ----
    env Display all environment variables
    -- --
    $USERNAME The name of the user
    $HOSTNAME The name of your computer
    $HOME The home directory of the current user
    $PWD The path to workdir directory
    $OLDPWD The path to the previous workdir directory
    $PS1 The prompt settings
    $SHELL The path to default shell
    $EDITOR The path to default text editor


    [1.5] - WILDCARDS AND REGULAR EXPRESSIONS
    ----
    STANDARD WILDCARDS (GLOBBING PATTERNS)
    ? Represent any single character
    * Represent any number of character
    [] Specifies a range
    {} Terms are separated by commas
    [!] Logical NOT
    REGULAR EXPRESSIONS
    . Match any single character
    ? Match between 0 and 1 of the precending token
    * Match 0 or more of the precending token
    + Match 1 or more of the precending token
    .* Match any string, similar to * in standard
    ^ Match the beginging of a string / a line
    $ Match the end of a string / a line
    \ Used to escape character
    | Logical OR
    [] Specifies a range
    [^] Logical NOT
    CATEGORIES OF CHARACTERS
    [:upper:] | A-Z Uppercase letters
    [:lower:] | a-z Lowercase letters
    [:alpha:] | A-z [:upper:] + [:lower:]
    [:digit:] | 0-9 Numbers in decimal, 0 to 9
    [:alnum:] | A-z0-9 [:upper:] + [:lower:] + [:digit:]
    [:space:] Whitespace


    [1.6] - RERUN COMMANDS AND REUSE ARGUMENTS
    ----
    COMMAND RUN => [du -h /], [ls $HOME]
    ![a-z] Rerun the command matching the [a-z] string
    !! Rerun the last command
    !* All arguments of the last command
    !^ First argument of the last command
    !$ Last argument of the last command
    E.G.
    !d => du -h /
    !ls => ls $HOME
    !! => ls $HOME
    !! | grep 'bar' => ls $HOME | grep 'bar'
    adduser john => Permission denied
    sudo !! => ok
    touch /bin/hello-world.sh => ok
    vim !* => vim /bin/hello-world.sh
    chmod +x !* => chmod +x /bin/hello-world.sh
    touch foo.txt bar.txt => ok
    ls !* => ls foo.txt bar.txt
    ls !$ => ls bar.txt


    [1.7] - INPUT / OUTPUT HANDLING
    ----
    [CMD] > [FILE] Standard output (stdout) of [CMD] to [FILE]
    [CMD] >> [FILE] Append the output of [CMD] into [FILE]
    [CMD1] | [CMD1] Stdout of [CMD1] to [CMD2]
    [CMD] > /dev/null Discard stdout of [CMD]
    E.G.
    ls -la > foo.txt
    pwd >> bar.txt
    cat ~/.bash_history | grep 'docker' | less


    [2] - FILES AND DIRECTORIES MANIPULATION, NAVIGATION AND DISPLAY


    [2.1] - LISTING FILE(S) AND DIRECTOR(Y/IES) CONTENT
    ----
    ls [FD...] List file(s) or director(y/ies) at [FD...]
    -- --
    ls [FD1...] [FD2...] List both [FD1...] and [FD2...]
    ls -l [FD...] Long listing format
    ls -a [FD...] Show all files, including hidden files
    ls -l [FD...] Long listing format
    ls -t [FD...] Sort by last modified
    ls -S [FD...] Sort by file size
    ls -R [FD...] Recursive listing
    ls -F [FD...] Show type of each file
    (/=directory, *=executable, @=link)
    E.G.
    ls ~/foo
    ls -la $HOME ./bar
    ls -laS $HOME ./bar


    CHANGING DIRECTORY
    ---- ----
    [2.2] - CHANGING DIRECTORY
    ----
    cd [D] Change into the directory at [D]
    -- --
    cd Change into your home directory ($HOME)
    cd .. Go to the parent directory
    cd ../../ n times Go up n parent directories
    (cd ../../../ => 3 parents directories)
    cd - Change to the previous directory
    cd ~n Change into n directory (see dirs command)
    pwd Return working directory fullname
    E.G.
    cd ~/foo
    cd ../../../../
    cd ~0


    CREATING FILE(S) AND DIRECTOR(Y/IES)
    ---- ----
    [2.3] - CREATING FILE(S) AND DIRECTOR(Y/IES)|
    ----
    mkdir [D...] Create director(y/ies) at [D...]
    -- --
    mkdir -p [D...] Create one or more parents directories if needed
    (mkdir -p foo/bar => 2 parents directories)
    touch [F...] Create file(s) if doesn't exist
    touch [F...] Create file(s) if does not exist
    E.G.
    mkdir ./bar
    mkdir -p ~/foo/bar ./bar
    touch ~/foo/bar/foobar.txt
    touch foo.txt ~/foo/bar.txt


    REMOVING FILE(S) AND DIRECTOR(Y/IES)
    ---- ----
    [2.4] - REMOVING FILE(S) AND DIRECTOR(Y/IES)
    ----
    rmdir [D...] Remove director(y/ies) at [D...] (it must be empty)
    rm [F...] Remove file(s) at [F...]
    -- --
    rm -r [FD...] Recursively remove all files, subdirectories and
    files into subdirectories starting at [FD...]
    rm -i [F...] Run in interactive mode
    rm -f [F...] Remove regardless of the [F...]'s permissions
    rm -f [F...] Remove regardless of the [F...] permissions
    E.G.
    rmdir ~/foo ./bar
    rm -f ~/foo/bar/foobar.txt
    rm -ri ~/foo/bar
    rm -rf ~/foo ./bar


    COPYING, MOVING AND RENAMING FILE(S) AND DIRECTOR(Y/IES)
    ---- ----

    [cp/mv] [F...] [D] Copy/Move file(s) to [D]
    [2.5] - COPYING, MOVING AND RENAMING FILE(S) AND DIRECTOR(Y/IES)
    ----
    [cp/mv] [F...] [D] Copy/Move file(s) at [F...] to directory at [D]
    -- --
    cp -r [FD...] [D] Copy file(s) and director(y/ies) recursively to [D]
    (directory, files, subdir and subfiles)
    mv [OLDFILE] [NEWFILE] Rename [OLDFILE] to [NEWFILE]

    E.G.
    [cp/mv] foo.txt bar.txt ~/bar/
    cp -r ~/foo/ ~/bar/
    mv foo.txt bar.txt


    VIEWING FILE(S)
    ---- ----
    cat [F...] Display the content of file(s)
    less [F...] Browse throught a text file(s)
    head [F...] Output the top portion of file(s)
    tail [F...] Output the bottom of file(s)
    [2.6] - DISPLAYING LIST OD CURRENTLY REMEMBERED DIRECTORIES
    ----
    dirs [D...] Display the history of directories at [D...]
    -- --
    dirs -l Long list format
    E.G.
    dirs -l
    dirs ~


    [2.7] - VIEWING FILE(S)
    ----
    cat [F...] Display the content of file(s) at [F...]
    less [F...] Browse throught a text file(s) at [F...]
    head [F...] Output the top portion of file(s) at [F...]
    tail [F...] Output the bottom of file(s) at [F...]
    --
    cat -n [F...] Display with line numbers output
    [head/tail] -n [F...] Display n number of lines (10 by default)
    @@ -112,18 +231,18 @@ E.G.
    head -6 foo.txt


    EDITING FILE(S)
    ---- ----
    vim [F...] Use the vim editor to view and modify a file(s)
    nano [F...] Use the nano editor to view and modify a file(s)
    [2.8] - EDITING FILE(S)
    ----
    vim [F...] Use vim editor to view/modify a file(s) at [F...]
    nano [F...] Use nano editor to view/modify a file(s) at [F...]
    E.G.
    vim foo.txt
    nano bar.txt


    SORTING FILE(S) CONTENT
    ---- ----
    sort [F...] Sort or merge lines of text and binary file(s)
    [2.9] - SORTING FILE(S) CONTENT
    ----
    sort [F...] Sort/merge lines of text/binary file(s) at [F...]
    -- --
    sort -r [F...] Sort in reverse order
    sort -u [F...] Suppress all lines that is equal to another
    @@ -134,8 +253,69 @@ E.G.
    sort -k 2 foo.txt


    MANIPULATING TAR ARCHIVE(S)
    ---- ----
    [2.10] - SEARCH PATTERN IN FILE AND STRING
    ----
    grep [PATTERN] [F...] Search [PATTERN] in file(s) at [F...]
    -- --
    grep -E [PATTERN] [F...] Search with extended regex
    grep -f [PATTERN_FILE] [F...] Search with a file pattern using [PATTERN_FILE]
    grep -i [PATTERN] [F...] Search with case insensitive
    grep -o [PATTERN] [F...] Output only the match, not the entire line
    grep -n [PATTERN] [F...] Prefix output with line number
    E.G.
    ls -la | grep '[[:digit:]]'
    cat foo.txt | grep -nio 'foo'
    grep -E '^[A-Z]+*[0-9]' foo.txt
    grep -f patterns.txt foo.txt


    [2.11] - STREAM EDIT AND TEXT TRANSFORMATION
    ----
    sed 's/[FIND]/[REPLACE]/[FLAGS]' [F...] Output the file with [FIND] pattern replaced with
    [REPLACE], with optional [FLAGS] at [F...]
    -- --
    sed 's///' [F...] > [F] Create a new file with the output of original file
    sed -i.bak 's///' [F...] Create a backup file (foo.txt.bak), rewrite foo.txt
    sed -e 's///' -e 's///' [F...] Using multiple expressions
    sed -E 's///' [F...] Search with extended regex
    sed -f [PATTERN_FILE] [F...] Search with a file pattern using [PATTERN_FILE]
    E.G.
    cat foo.txt | sed 's/foo/bar/'
    sed -i.backup -f foo.sed foo.txt
    sed -E 's/^[A-Z]+[^0-9]/bar' foo.txt


    [2.12] - FINDING FILES IN DIRECTOR(Y/IES)
    ----
    find [D...] -name [NAME] Find files matching the [NAME] in director(y/ies)
    at [D...]
    -- --
    find [D...] -name [NAME] -type [TYPE] Find files with specific type
    find [D...] -name [NAME] -delete Find files and delete them
    find [D...] -path [EXPR] Find files matching a pattern
    E.G.
    find ~/foo -name 'foo'
    find ./bar -type f -delete
    find -path '*Library*' -type d -name 'bar'


    [2.13] - CHANGE FILE MODE, ACCESS, PREMISSIONS AND OWNER
    ----
    chmod [MODE] [F...] Change mode of file(s) at [F...]
    chown [OWNER]:[GROUP] [F...] Change owner and group of file(s) at [F...]
    -- --
    chmod -R [MODE] [D...] Change permission of director(y/ies), subfile(s)
    and subdirector(y/ies)
    chown -R [OWNER]:[GROUP] [D...] Change owner and group of director(y/ies),
    subfile(s) and subdirector(y/ies)
    E.G.
    chmod +x-rw foo.sh
    chmod -R 600 ~/foo ./bar
    chown user1 foo.sh


    [2.14] - MANIPULATING TAR ARCHIVE(S)
    ----
    tar -[ctx]f [OUTPUT_FILE] [FD...] Manipulate archive from file(s) and director(y/ies)
    OPTIONS
    -c Create a tar archive
    @@ -151,13 +331,71 @@ E.G.
    tar -xzf foo.gz Extract 'foo.gz' content in the workdir


    DISPLAYING DISK USAGE STATE
    ---- ----
    [2.15] - DISPLAYING DISK USAGE STATE
    ----
    du Estimate file(s) usage (all files in workdir)
    -- --
    du [FD...] Estimate file(s) usage at [FD...]
    du -h Display size in human readable format (octets)
    du -k Display size in Kilobytes
    E.G.
    du ~/foo ./bar
    du -h /


    [3] - NETWORK


    [3.1] - REMOTE LOGIN TO A HOST OR INSTANCE
    ----
    ssh [USER]@[HOST] Establish a SSH connection to the [HOST] with user [USER]
    --
    ssh -i [SSHKEY] [USER]@[HOST] Connect using the provided private SSH key
    ssh -p [PORT] [USER]@[HOST] Connect with a specific port
    E.G.
    ssh [email protected]
    ssh -i ~/.ssh/foo_key [email protected]
    ssh -p 666 [email protected]


    [3.2] - STATUS OF A HOST
    ----
    ping [HOST] Ping [HOST] and display STATUS
    -- --
    ping -c n [HOST] Stop after receiving n packets
    ping -i n [HOST] Wait n seconds between sending each packet
    ping -v [HOST] Show verbose output
    E.G.
    ping google.com
    ping -c 6 -i 2 -v reddit.com


    [3.3] - TRANSFER A URL
    ----
    curl [URL] Output the response of the URL
    -- --
    curl [URL] > [F] Output written in file at [F]
    curl -sS [URL] Silent mode, only show errors
    curl -sS [URL] | [LANGUAGE] Execute the response with a specific [LANGUAGE]
    E.G.
    curl localhost:80
    curl localhost:80 > foo.sh
    curl -sS localhost:80 | sh


    [3.4] - GET INFORMATION ABOUT A DOMAIN
    ----
    whois [DOMAIN] Get all informations about a [DOMAIN]
    -- --
    whois -h [HOST] Use specific [HOST]
    whois -p [PORT] Use specific [PORT]
    E.G.
    whois reddit.com
    whois -p 666


    ------------------------------------------------------------------------------------------------
    | BASH COMMAND LINE CHEATSHEET |
    | |
    | by Alexandre Delaloy - @blyndusk |
    ------------------------------------------------------------------------------------------------
  2. alexandre-delaloy revised this gist May 6, 2020. No changes.
  3. alexandre-delaloy revised this gist May 6, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bash-command-line-cheatsheet.txt
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@


    MY NOTATION
    ---- --
    ---- ----
    [D] Directory
    [D...] Directory, directories
    [F] File
  4. alexandre-delaloy revised this gist May 6, 2020. 1 changed file with 11 additions and 11 deletions.
    22 changes: 11 additions & 11 deletions bash-command-line-cheatsheet.txt
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ MY NOTATION


    GETTING HELP
    ---- -- -
    ---- ----
    man [command] Read the manual for a given command
    [command] -h | --help Ask the command for help
    E.G.
    @@ -25,7 +25,7 @@ E.G.


    LISTING FILE(S) AND DIRECTOR(Y/IES) CONTENT
    ---- -- -
    ---- ----
    ls [FD...] List file(s) or director(y/ies) at [FD...]
    -- --
    ls [FD1...] [FD2...] List both [FD1...] and [FD2...]
    @@ -40,7 +40,7 @@ E.G.


    CHANGING DIRECTORY
    ---- -- -
    ---- ----
    cd [D] Change into the directory at [D]
    cd Change into your home directory ($HOME)
    cd .. Go to the parent directory
    @@ -54,7 +54,7 @@ E.G.


    CREATING FILE(S) AND DIRECTOR(Y/IES)
    ---- -- -
    ---- ----
    mkdir [D...] Create director(y/ies) at [D...]
    -- --
    mkdir -p [D...] Create one or more parents directories if needed
    @@ -68,7 +68,7 @@ E.G.


    REMOVING FILE(S) AND DIRECTOR(Y/IES)
    ---- -- -
    ---- ----
    rmdir [D...] Remove director(y/ies) at [D...] (it must be empty)
    rm [F...] Remove file(s) at [F...]
    -- --
    @@ -84,7 +84,7 @@ E.G.


    COPYING, MOVING AND RENAMING FILE(S) AND DIRECTOR(Y/IES)
    ---- -- -
    ---- ----

    [cp/mv] [F...] [D] Copy/Move file(s) to [D]
    -- --
    @@ -99,7 +99,7 @@ E.G.


    VIEWING FILE(S)
    ---- -- -
    ---- ----
    cat [F...] Display the content of file(s)
    less [F...] Browse throught a text file(s)
    head [F...] Output the top portion of file(s)
    @@ -113,7 +113,7 @@ E.G.


    EDITING FILE(S)
    ---- -- -
    ---- ----
    vim [F...] Use the vim editor to view and modify a file(s)
    nano [F...] Use the nano editor to view and modify a file(s)
    E.G.
    @@ -122,7 +122,7 @@ E.G.


    SORTING FILE(S) CONTENT
    ---- -- -
    ---- ----
    sort [F...] Sort or merge lines of text and binary file(s)
    -- --
    sort -r [F...] Sort in reverse order
    @@ -135,7 +135,7 @@ E.G.


    MANIPULATING TAR ARCHIVE(S)
    ---- -- -
    ---- ----
    tar -[ctx]f [OUTPUT_FILE] [FD...] Manipulate archive from file(s) and director(y/ies)
    OPTIONS
    -c Create a tar archive
    @@ -152,7 +152,7 @@ E.G.


    DISPLAYING DISK USAGE STATE
    ---- -- -
    ---- ----
    du Estimate file(s) usage (all files in workdir)
    du [FD...] Estimate file(s) usage at [FD...]
    du -h Display size in human readable format (octets)
  5. alexandre-delaloy revised this gist May 6, 2020. 1 changed file with 12 additions and 12 deletions.
    24 changes: 12 additions & 12 deletions bash-command-line-cheatsheet.txt
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@


    MY NOTATION
    ----
    ---- --
    [D] Directory
    [D...] Directory, directories
    [F] File
    @@ -16,7 +16,7 @@ MY NOTATION


    GETTING HELP
    ----
    ---- -- -
    man [command] Read the manual for a given command
    [command] -h | --help Ask the command for help
    E.G.
    @@ -25,7 +25,7 @@ E.G.


    LISTING FILE(S) AND DIRECTOR(Y/IES) CONTENT
    ----
    ---- -- -
    ls [FD...] List file(s) or director(y/ies) at [FD...]
    -- --
    ls [FD1...] [FD2...] List both [FD1...] and [FD2...]
    @@ -40,7 +40,7 @@ E.G.


    CHANGING DIRECTORY
    ----
    ---- -- -
    cd [D] Change into the directory at [D]
    cd Change into your home directory ($HOME)
    cd .. Go to the parent directory
    @@ -54,7 +54,7 @@ E.G.


    CREATING FILE(S) AND DIRECTOR(Y/IES)
    ----
    ---- -- -
    mkdir [D...] Create director(y/ies) at [D...]
    -- --
    mkdir -p [D...] Create one or more parents directories if needed
    @@ -68,7 +68,7 @@ E.G.


    REMOVING FILE(S) AND DIRECTOR(Y/IES)
    ----
    ---- -- -
    rmdir [D...] Remove director(y/ies) at [D...] (it must be empty)
    rm [F...] Remove file(s) at [F...]
    -- --
    @@ -84,7 +84,7 @@ E.G.


    COPYING, MOVING AND RENAMING FILE(S) AND DIRECTOR(Y/IES)
    ----
    ---- -- -

    [cp/mv] [F...] [D] Copy/Move file(s) to [D]
    -- --
    @@ -99,7 +99,7 @@ E.G.


    VIEWING FILE(S)
    ----
    ---- -- -
    cat [F...] Display the content of file(s)
    less [F...] Browse throught a text file(s)
    head [F...] Output the top portion of file(s)
    @@ -113,7 +113,7 @@ E.G.


    EDITING FILE(S)
    ----
    ---- -- -
    vim [F...] Use the vim editor to view and modify a file(s)
    nano [F...] Use the nano editor to view and modify a file(s)
    E.G.
    @@ -122,7 +122,7 @@ E.G.


    SORTING FILE(S) CONTENT
    ----
    ---- -- -
    sort [F...] Sort or merge lines of text and binary file(s)
    -- --
    sort -r [F...] Sort in reverse order
    @@ -135,7 +135,7 @@ E.G.


    MANIPULATING TAR ARCHIVE(S)
    ----
    ---- -- -
    tar -[ctx]f [OUTPUT_FILE] [FD...] Manipulate archive from file(s) and director(y/ies)
    OPTIONS
    -c Create a tar archive
    @@ -152,7 +152,7 @@ E.G.


    DISPLAYING DISK USAGE STATE
    ----
    ---- -- -
    du Estimate file(s) usage (all files in workdir)
    du [FD...] Estimate file(s) usage at [FD...]
    du -h Display size in human readable format (octets)
  6. alexandre-delaloy revised this gist May 6, 2020. 1 changed file with 12 additions and 12 deletions.
    24 changes: 12 additions & 12 deletions bash-command-line-cheatsheet.txt
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ MY NOTATION
    [F...] Files
    [FD] File, directory
    [FD...] File, files, directory, directories
    ---------------------------------------------------------------------------------------------------


    GETTING HELP
    ----
    @@ -22,7 +22,7 @@ GETTING HELP
    E.G.
    man chmod
    chmod -h
    ---------------------------------------------------------------------------------------------------


    LISTING FILE(S) AND DIRECTOR(Y/IES) CONTENT
    ----
    @@ -37,7 +37,7 @@ LISTING FILE(S) AND DIRECTOR(Y/IES) CONTENT
    E.G.
    ls ~/foo
    ls -la $HOME ./bar
    ---------------------------------------------------------------------------------------------------


    CHANGING DIRECTORY
    ----
    @@ -51,7 +51,7 @@ CHANGING DIRECTORY
    E.G.
    cd ~/foo
    cd ../../../../
    ---------------------------------------------------------------------------------------------------


    CREATING FILE(S) AND DIRECTOR(Y/IES)
    ----
    @@ -65,7 +65,7 @@ E.G.
    mkdir -p ~/foo/bar ./bar
    touch ~/foo/bar/foobar.txt
    touch foo.txt ~/foo/bar.txt
    ---------------------------------------------------------------------------------------------------


    REMOVING FILE(S) AND DIRECTOR(Y/IES)
    ----
    @@ -81,7 +81,7 @@ E.G.
    rm -f ~/foo/bar/foobar.txt
    rm -ri ~/foo/bar
    rm -rf ~/foo ./bar
    ---------------------------------------------------------------------------------------------------


    COPYING, MOVING AND RENAMING FILE(S) AND DIRECTOR(Y/IES)
    ----
    @@ -96,7 +96,7 @@ E.G.
    [cp/mv] foo.txt bar.txt ~/bar/
    cp -r ~/foo/ ~/bar/
    mv foo.txt bar.txt
    ---------------------------------------------------------------------------------------------------


    VIEWING FILE(S)
    ----
    @@ -110,7 +110,7 @@ VIEWING FILE(S)
    E.G.
    cat -n foo.txt
    head -6 foo.txt
    ---------------------------------------------------------------------------------------------------


    EDITING FILE(S)
    ----
    @@ -119,7 +119,7 @@ EDITING FILE(S)
    E.G.
    vim foo.txt
    nano bar.txt
    ---------------------------------------------------------------------------------------------------


    SORTING FILE(S) CONTENT
    ----
    @@ -132,7 +132,7 @@ SORTING FILE(S) CONTENT
    E.G.
    sort -ru -o bar.txt foo.txt
    sort -k 2 foo.txt
    ---------------------------------------------------------------------------------------------------


    MANIPULATING TAR ARCHIVE(S)
    ----
    @@ -149,7 +149,7 @@ E.G.
    using verbose and compression
    tar -tf foo.gz List 'foo.gz' files in archive
    tar -xzf foo.gz Extract 'foo.gz' content in the workdir
    ---------------------------------------------------------------------------------------------------


    DISPLAYING DISK USAGE STATE
    ----
    @@ -160,4 +160,4 @@ DISPLAYING DISK USAGE STATE
    E.G.
    du ~/foo ./bar
    du -h /
    ---------------------------------------------------------------------------------------------------

  7. alexandre-delaloy revised this gist May 6, 2020. 1 changed file with 28 additions and 66 deletions.
    94 changes: 28 additions & 66 deletions bash-command-line-cheatsheet.txt
    Original file line number Diff line number Diff line change
    @@ -5,33 +5,27 @@
    ------------------------------------------------------------------------------------------------


    Notation
    MY NOTATION
    ----
    [D] Directory
    [D...] Directory, directories
    [F] File
    [F...] Files
    [FD] File, directory
    [FD...] File, files, directory, directories

    ---------------------------------------------------------------------------------------------------


    Getting help:
    GETTING HELP
    ----

    man [command] Read the manual for a given command
    [command] -h | --help Ask the command for help

    e.g.
    E.G.
    man chmod
    chmod -h

    ---------------------------------------------------------------------------------------------------


    Listing directory content
    LISTING FILE(S) AND DIRECTOR(Y/IES) CONTENT
    ----

    ls [FD...] List file(s) or director(y/ies) at [FD...]
    -- --
    ls [FD1...] [FD2...] List both [FD1...] and [FD2...]
    @@ -40,70 +34,56 @@ Listing directory content
    ls -R [FD...] Recursive listing
    ls -F [FD...] Show type of each file
    (/=directory, *=executable, @=link)
    e.g.
    E.G.
    ls ~/foo
    ls -la $HOME ./bar

    ---------------------------------------------------------------------------------------------------


    Changing directories
    CHANGING DIRECTORY
    ----

    cd [D] Change into the directory at [D]
    cd Change into your home directory ($HOME)
    cd .. Go to the parent directory
    cd ../../ n times Go up n parent directories
    (cd ../../../ => 3 parents directories)
    cd - Change to the previous directory
    pwd Return working directory fullname

    e.g.
    E.G.
    cd ~/foo
    cd ../../../../

    ---------------------------------------------------------------------------------------------------


    Creating files and directories
    CREATING FILE(S) AND DIRECTOR(Y/IES)
    ----

    mkdir [D...] Create director(y/ies) at [D...]
    -- --
    mkdir -p [D...] Create one or more parents directories if needed
    (mkdir -p foo/bar => 2 parents directories)
    touch [F...] Create file(s) if doesn't exist

    e.g.
    E.G.
    mkdir ./bar
    mkdir -p ~/foo/bar ./bar
    touch ~/foo/bar/foobar.txt
    touch foo.txt ~/foo/bar.txt

    ---------------------------------------------------------------------------------------------------


    Removing files and directories
    REMOVING FILE(S) AND DIRECTOR(Y/IES)
    ----

    rmdir [D...] Remove director(y/ies) at [D...] (it must be empty)
    rm [F...] Remove file(s) at [F...]
    -- --
    rm -r [FD...] Recursively remove all files, subdirectories and
    files into subdirectories starting at [FD...]
    rm -i [F...] Run in interactive mode
    rm -f [F...] Remove regardless of the [F...]'s permissions

    e.g.
    E.G.
    rmdir ~/foo ./bar
    rm -f ~/foo/bar/foobar.txt
    rm -ri ~/foo/bar
    rm -rf ~/foo ./bar

    ---------------------------------------------------------------------------------------------------


    Copying, moving and renaming files and directories
    COPYING, MOVING AND RENAMING FILE(S) AND DIRECTOR(Y/IES)
    ----

    [cp/mv] [F...] [D] Copy/Move file(s) to [D]
    @@ -112,90 +92,72 @@ Copying, moving and renaming files and directories
    (directory, files, subdir and subfiles)
    mv [OLDFILE] [NEWFILE] Rename [OLDFILE] to [NEWFILE]

    e.g.
    E.G.
    [cp/mv] foo.txt bar.txt ~/bar/
    cp -r ~/foo/ ~/bar/
    mv foo.txt bar.txt

    ---------------------------------------------------------------------------------------------------


    Viewing files
    VIEWING FILE(S)
    ----

    cat [F...] Display the content of file(s)
    less [F...] Browse throught a text file(s)
    head [F...] Output the top portion of file(s)
    tail [F...] Output the bottom of file(s)
    --
    cat -n [F...] Display with line numbers output
    [head/tail] -n [F...] Display n number of lines (10 by default)

    e.g.
    E.G.
    cat -n foo.txt
    head -6 foo.txt

    ---------------------------------------------------------------------------------------------------


    Editing files
    EDITING FILE(S)
    ----

    vim [F...] Use the vim editor to view and modify a file(s)
    nano [F...] Use the nano editor to view and modify a file(s)

    e.g.
    E.G.
    vim foo.txt
    nano bar.txt

    ---------------------------------------------------------------------------------------------------


    Sorting files content
    SORTING FILE(S) CONTENT
    ----

    sort [F...] Sort or merge lines of text and binary file(s)
    -- --
    sort -r [F...] Sort in reverse order
    sort -u [F...] Suppress all lines that is equal to another
    sort -o [OUTPUT_FILE] [F...] Print the output to [OUTPUT_FILE]
    sort -k n [F...] Sort by key (n is the field number)

    e.g.
    E.G.
    sort -ru -o bar.txt foo.txt
    sort -k 2 foo.txt

    ---------------------------------------------------------------------------------------------------


    Manipulating tar archive(s)
    MANIPULATING TAR ARCHIVE(S)
    ----

    tar -[ctx]f [OUTPUT_FILE] [FD...] Manipulate archive from file(s) and director(y/ies)

    Options
    OPTIONS
    -c Create a tar archive
    -x Extract files from the archive
    -t Display the table of contents (list)
    -v Be verbose
    -z Use compression
    -f [OUTPUT_FILE] Output archive file to [OUTPUT_FILE]

    e.g.
    E.G.
    tar -czvf foo.gz ~/foo Create a archive named 'foo.gz' from the 'foo' dir
    using verbose and compression
    tar -tf foo.gz List 'foo.gz' files in archive
    tar -xzf foo.gz Extract 'foo.gz' content in the workdir

    ---------------------------------------------------------------------------------------------------


    Displaying disk usage stats
    DISPLAYING DISK USAGE STATE
    ----

    du Estimate file(s) usage (all files in workdir)
    du [FD...] Estimate file(s) usage at [FD...]
    du -h Display size in human readable format (octets)
    du -k Display size in Kilobytes

    ---------------------------------------------------------------------------------------------------
    E.G.
    du ~/foo ./bar
    du -h /
    ---------------------------------------------------------------------------------------------------
  8. alexandre-delaloy revised this gist May 6, 2020. 1 changed file with 111 additions and 68 deletions.
    179 changes: 111 additions & 68 deletions bash-command-line-cheatsheet.txt
    Original file line number Diff line number Diff line change
    @@ -1,158 +1,201 @@
    -----------------------------------------
    | BASH COMMAND LINE CHEATSHEET |
    | |
    | by Alexandre Delaloy - @blyndusk |
    -----------------------------------------
    ------------------------------------------------------------------------------------------------
    | BASH COMMAND LINE CHEATSHEET |
    | |
    | by Alexandre Delaloy - @blyndusk |
    ------------------------------------------------------------------------------------------------


    Notation
    [D] Directory
    [D...] Directory, directories
    [F] File
    [F...] Files
    [FD] File, directory
    [FD...] File, files, directory, directories

    ---------------------------------------------------------------------------------------------------


    Getting help:
    ----

    man [command] Read the manual for a given command
    [command] -h || --help Ask the command for help
    man [command] Read the manual for a given command
    [command] -h | --help Ask the command for help

    e.g.
    man chmod
    chmod -h

    ---------------------------------------------------------------------------------------------------

    --------------------------------------------------------------------------------------------------

    Listing directory content
    ----

    ls [PATH] List the files or directory at [PATH]
    --
    ls [PATH1] [PATH2] List both [PATH1] and [PATH2]
    ls -l [PATH] Long listing format
    ls -a [PATH] Show all files, including hidden files
    ls -R [PATH] Recursive listing
    ls -F [PATH] Show type of each file
    (/=directory, *=executable, @=link)
    ls [FD...] List file(s) or director(y/ies) at [FD...]
    -- --
    ls [FD1...] [FD2...] List both [FD1...] and [FD2...]
    ls -l [FD...] Long listing format
    ls -a [FD...] Show all files, including hidden files
    ls -R [FD...] Recursive listing
    ls -F [FD...] Show type of each file
    (/=directory, *=executable, @=link)
    e.g.
    ls ~/foo
    ls -la $HOME
    ls -la $HOME ./bar

    ---------------------------------------------------------------------------------------------------

    --------------------------------------------------------------------------------------------------

    Changing directories
    ----

    cd [DIR] Change into the directory at [DIR]
    cd Change into your home directory ($HOME)
    cd .. Go to the parent directory
    cd ../../ n times Go up n parent directories
    (cd ../../../ => 3 parents directories)
    cd - Change to the previous directory
    pwd Return working directory fullname
    cd [D] Change into the directory at [D]
    cd Change into your home directory ($HOME)
    cd .. Go to the parent directory
    cd ../../ n times Go up n parent directories
    (cd ../../../ => 3 parents directories)
    cd - Change to the previous directory
    pwd Return working directory fullname

    e.g.
    cd ~/foo
    cd ../../../../


    --------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------


    Creating files and directories
    ----

    mkdir [DIR] Create a directory at [DIR]
    --
    mkdir -p [DIR] Create one or more parents directories if needed
    (mkdir -p foo/bar => 2 parents directories)
    touch [NEWFILE] Create a [NEWFILE] if doesn't exist
    mkdir [D...] Create director(y/ies) at [D...]
    -- --
    mkdir -p [D...] Create one or more parents directories if needed
    (mkdir -p foo/bar => 2 parents directories)
    touch [F...] Create file(s) if doesn't exist

    e.g.
    mkdir -p ~/foo/bar
    mkdir ./bar
    mkdir -p ~/foo/bar ./bar
    touch ~/foo/bar/foobar.txt
    touch foo.txt ~/foo/bar.txt


    --------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------


    Removing files and directories
    ----

    rmdir [DIR] Remove directory at [DIR] (it must be empty)
    rm [FILE] Remove a file
    --
    rm -r [DIR] Recursively remove all files, subdirectories and
    files into subdirectories starting at [DIR]
    rm -i [FILE/DIR] Run in interactive mode
    rm -f [FILE/DIR] Remove regardless of the [FILE/DIR]'s permissions
    rmdir [D...] Remove director(y/ies) at [D...] (it must be empty)
    rm [F...] Remove file(s) at [F...]
    -- --
    rm -r [FD...] Recursively remove all files, subdirectories and
    files into subdirectories starting at [FD...]
    rm -i [F...] Run in interactive mode
    rm -f [F...] Remove regardless of the [F...]'s permissions

    e.g.
    rmdir ~/foo ./bar
    rm -f ~/foo/bar/foobar.txt
    rm -ri ~/foo/bar
    rm -rf ~/foo
    rm -rf ~/foo ./bar

    ---------------------------------------------------------------------------------------------------

    --------------------------------------------------------------------------------------------------

    Copying, moving and renaming files and directories
    ----

    [cp/mv] [FILE] [DEST_DIR] Copy/Move [FILE] to [DEST_DIR]
    --
    cp -r [SRC_DIR] [DEST_DR] Copy [SRC_DIR] recursively to [DEST_DIR]
    (directory, files, subdir and subfiles)
    mv [OLDFILE] [NEWFILE] Rename [OLDFILE] to [NEWFILE]
    [cp/mv] [F...] [D] Copy/Move file(s) to [D]
    -- --
    cp -r [FD...] [D] Copy file(s) and director(y/ies) recursively to [D]
    (directory, files, subdir and subfiles)
    mv [OLDFILE] [NEWFILE] Rename [OLDFILE] to [NEWFILE]

    e.g.
    [cp/mv] foo.txt ~/bar/
    [cp/mv] foo.txt bar.txt ~/bar/
    cp -r ~/foo/ ~/bar/
    mv foo.txt bar.txt

    ---------------------------------------------------------------------------------------------------

    --------------------------------------------------------------------------------------------------

    Viewing files
    ----

    cat [FILE] Display the content of [FILE]
    less [FILE] Browse throught a text [FILE]
    head [FILE] Output the top portion of [FILE]
    tail [FILE] Output the bottom of [FILE]
    cat [F...] Display the content of file(s)
    less [F...] Browse throught a text file(s)
    head [F...] Output the top portion of file(s)
    tail [F...] Output the bottom of file(s)
    --
    cat -n [FILE] Display with line numbers output
    [head/tail] -n [FILE] Display n number of lines (10 by default)
    cat -n [F...] Display with line numbers output
    [head/tail] -n [F...] Display n number of lines (10 by default)

    e.g.
    cat -n foo.txt
    head -6 foo.txt

    ---------------------------------------------------------------------------------------------------

    --------------------------------------------------------------------------------------------------

    Editing files
    ----

    vim [FILE] Use the vim editor to view and modify [FILE]
    nano [FILE] Use the nano editor to view and modify [FILE]
    vim [F...] Use the vim editor to view and modify a file(s)
    nano [F...] Use the nano editor to view and modify a file(s)

    e.g.
    vim foo.txt
    nano bar.txt

    ---------------------------------------------------------------------------------------------------

    --------------------------------------------------------------------------------------------------

    Sorting files content
    ----

    sort [FILE] Sort or merge lines of text and binary files
    --
    sort -r [FILE] Sort in reverse order
    sort -u [FILE] Suppress all lines that is equal to another
    sort -o [OUTPUT_FILE] [FILE] Print the output to [OUTPUT_FILE]
    sort -k n [FILE] Sort by key (n is the field number)
    sort [F...] Sort or merge lines of text and binary file(s)
    -- --
    sort -r [F...] Sort in reverse order
    sort -u [F...] Suppress all lines that is equal to another
    sort -o [OUTPUT_FILE] [F...] Print the output to [OUTPUT_FILE]
    sort -k n [F...] Sort by key (n is the field number)

    e.g.
    sort -ru -o bar.txt foo.txt
    sort -k 2 foo.txt

    ---------------------------------------------------------------------------------------------------


    Manipulating tar archive(s)
    ----

    tar -[ctx]f [OUTPUT_FILE] [FD...] Manipulate archive from file(s) and director(y/ies)

    Options
    -c Create a tar archive
    -x Extract files from the archive
    -t Display the table of contents (list)
    -v Be verbose
    -z Use compression
    -f [OUTPUT_FILE] Output archive file to [OUTPUT_FILE]

    e.g.
    tar -czvf foo.gz ~/foo Create a archive named 'foo.gz' from the 'foo' dir
    using verbose and compression
    tar -tf foo.gz List 'foo.gz' files in archive
    tar -xzf foo.gz Extract 'foo.gz' content in the workdir

    ---------------------------------------------------------------------------------------------------


    Displaying disk usage stats
    ----

    du Estimate file(s) usage (all files in workdir)
    du [FD...] Estimate file(s) usage at [FD...]
    du -h Display size in human readable format (octets)
    du -k Display size in Kilobytes

    --------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------
  9. alexandre-delaloy revised this gist May 5, 2020. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions bash-command-line-cheatsheet.txt
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    --------------------------------------------------------
    | BASH COMMAND LINE CHEATSHEET |
    | |
    | by Alexandre Delaloy - @blyndusk |
    --------------------------------------------------------
    -----------------------------------------
    | BASH COMMAND LINE CHEATSHEET |
    | |
    | by Alexandre Delaloy - @blyndusk |
    -----------------------------------------



  10. alexandre-delaloy revised this gist May 5, 2020. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions bash-command-line-cheatsheet.txt
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    ------------------------------------------------------------------------------------------------
    | BASH COMMAND LINE CHEATSHEET |
    | |
    | by Alexandre Delaloy - @blyndusk |
    ------------------------------------------------------------------------------------------------
    --------------------------------------------------------
    | BASH COMMAND LINE CHEATSHEET |
    | |
    | by Alexandre Delaloy - @blyndusk |
    --------------------------------------------------------



  11. alexandre-delaloy created this gist May 5, 2020.
    158 changes: 158 additions & 0 deletions bash-command-line-cheatsheet.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,158 @@
    ------------------------------------------------------------------------------------------------
    | BASH COMMAND LINE CHEATSHEET |
    | |
    | by Alexandre Delaloy - @blyndusk |
    ------------------------------------------------------------------------------------------------



    Getting help:
    ----

    man [command] Read the manual for a given command
    [command] -h || --help Ask the command for help

    e.g.
    man chmod
    chmod -h


    --------------------------------------------------------------------------------------------------

    Listing directory content
    ----

    ls [PATH] List the files or directory at [PATH]
    --
    ls [PATH1] [PATH2] List both [PATH1] and [PATH2]
    ls -l [PATH] Long listing format
    ls -a [PATH] Show all files, including hidden files
    ls -R [PATH] Recursive listing
    ls -F [PATH] Show type of each file
    (/=directory, *=executable, @=link)
    e.g.
    ls ~/foo
    ls -la $HOME


    --------------------------------------------------------------------------------------------------

    Changing directories
    ----

    cd [DIR] Change into the directory at [DIR]
    cd Change into your home directory ($HOME)
    cd .. Go to the parent directory
    cd ../../ n times Go up n parent directories
    (cd ../../../ => 3 parents directories)
    cd - Change to the previous directory
    pwd Return working directory fullname

    e.g.
    cd ~/foo
    cd ../../../../


    --------------------------------------------------------------------------------------------------


    Creating files and directories
    ----

    mkdir [DIR] Create a directory at [DIR]
    --
    mkdir -p [DIR] Create one or more parents directories if needed
    (mkdir -p foo/bar => 2 parents directories)
    touch [NEWFILE] Create a [NEWFILE] if doesn't exist

    e.g.
    mkdir -p ~/foo/bar
    touch ~/foo/bar/foobar.txt


    --------------------------------------------------------------------------------------------------


    Removing files and directories
    ----

    rmdir [DIR] Remove directory at [DIR] (it must be empty)
    rm [FILE] Remove a file
    --
    rm -r [DIR] Recursively remove all files, subdirectories and
    files into subdirectories starting at [DIR]
    rm -i [FILE/DIR] Run in interactive mode
    rm -f [FILE/DIR] Remove regardless of the [FILE/DIR]'s permissions

    e.g.
    rm -f ~/foo/bar/foobar.txt
    rm -ri ~/foo/bar
    rm -rf ~/foo


    --------------------------------------------------------------------------------------------------

    Copying, moving and renaming files and directories
    ----

    [cp/mv] [FILE] [DEST_DIR] Copy/Move [FILE] to [DEST_DIR]
    --
    cp -r [SRC_DIR] [DEST_DR] Copy [SRC_DIR] recursively to [DEST_DIR]
    (directory, files, subdir and subfiles)
    mv [OLDFILE] [NEWFILE] Rename [OLDFILE] to [NEWFILE]

    e.g.
    [cp/mv] foo.txt ~/bar/
    cp -r ~/foo/ ~/bar/
    mv foo.txt bar.txt


    --------------------------------------------------------------------------------------------------

    Viewing files
    ----

    cat [FILE] Display the content of [FILE]
    less [FILE] Browse throught a text [FILE]
    head [FILE] Output the top portion of [FILE]
    tail [FILE] Output the bottom of [FILE]
    --
    cat -n [FILE] Display with line numbers output
    [head/tail] -n [FILE] Display n number of lines (10 by default)

    e.g.
    cat -n foo.txt
    head -6 foo.txt


    --------------------------------------------------------------------------------------------------

    Editing files
    ----

    vim [FILE] Use the vim editor to view and modify [FILE]
    nano [FILE] Use the nano editor to view and modify [FILE]

    e.g.
    vim foo.txt
    nano bar.txt


    --------------------------------------------------------------------------------------------------

    Sorting files content
    ----

    sort [FILE] Sort or merge lines of text and binary files
    --
    sort -r [FILE] Sort in reverse order
    sort -u [FILE] Suppress all lines that is equal to another
    sort -o [OUTPUT_FILE] [FILE] Print the output to [OUTPUT_FILE]
    sort -k n [FILE] Sort by key (n is the field number)

    e.g.
    sort -ru -o bar.txt foo.txt
    sort -k 2 foo.txt


    --------------------------------------------------------------------------------------------------