• Linux & Server Administration

    Finding files

    $ grep -rnw '/path/to/somewhere/' -e 'pattern'
    
    • -r or -R is recursive,
    • -n adds line numbers,
    • -w stands for match the whole word,
    • -l (lower-case L) can be added to just give the file name of matching files

    Ref: How do I find all files containing specific text on Linux? - https://stackoverflow.com/questions/16956810/how-do-i-find-all-files-containing-specific-text-on-linux

    Network

    Show ports based on PID of a process

    $ sudo netstat -tulpn | grep ${PID}
    

    Show information about CPU

    $ cat /proc/cpuinfo
    

    Check the connection to the server and open port on a specific remote computer

    $ telnet SERVER_ADDRESS PORT
    

    Connect to a remote server, the best way through the command 'ssh'

    $ ssh USER@SERVER_ADDRESS
    

    Less

    Less is a program similar to more (1), but which allows backward movement in the file as well as forward movement. Useful commands when browsing logs:

    • Waiting for latest lines at EOF - SHIFT + F
    • Finish of waiting at EOF - CTRL + C
    • Search for a specific text - /${TEXT}
    • Leave or finish - Q

    Nano

    GNU nano is a small and friendly text editor. Besides basic text editing, nano offers many extra features like an interactive search and replace, go to line and column number, auto-indentation, feature toggles, internationalization support, and filename tab completion.

    • Search for a specific text - CTRL + W

    Grep

    grep is a command-line utility for searching plain-text data sets for lines that match a regular expression. Its name comes from the ed command g/re/p (globally search a regular expression and print), which has the same effect: doing a global search with the regular expression and printing all matching lines. Grep was originally developed for the Unix operating system, but later available for all Unix-like systems.

    grep -E option is for extended regexp. If you use the grep command with -E option, you just need to use | to separate multiple patterns for the or condition.

    $ ps aux | grep -E 'ssh|PID'
    

    It is useful for the showing the title of listing processes when filter for a specific command.