Shortcuts

Fore notes

Hi, this is the first part of the “Linux CLI for Dummies” seri.

FK YOU, GO EXPLORE YOURSELF!” – this is the most effective way

Sorry, didn’t mean to scare you 🙂 !

We’re gonna talk about some good mindset (as well as some misunderstanding) when someone starts learning to use Linux CLI.

Also, some common tools / tips & tricks will be listed so you can start to explore the Linux CLI world on your own!

Targeted audiences

developers / (pen)testers, Linux lovers, etc. literally everyone.

Prerequisites

  • Know the existence of CLI and want to use them at work
  • Using Unix or Unix-like OS on daily basis
    • Linux (applied to almost any distributions, including WSL, etc.)
    • Mac OS
    • etc.

TL;DR (not really) – for the seri

Beside of tips and tricks, this sharing will provide you some foundational logic of Linux Command-Line (or command line in general).

For example, when to use CLI, its benefits and other basic knowledge so you can level yourself up when using CLI.

To achieve that, this talk only focus on:

  • things you need to know before using any Linux commands
  • commands that being used on daily basis of my development / operation work (more on development), which mostly relates to:
    • text manipulation
    • I/O handling
    • file transfer
  • only talk about commands / utilities that are widely used (can work on most servers, PC, etc.) – most of them are built-in command (i.e. pre-installed with your OS default setup).

And in the last section, we will take a look at some popular commands + their common practical options.

Again, the final and most important goal of this page is to provide knowledge, so you can:

  • learn + expand CLI knowledge by yourself
  • contribute back to this page (so it benefits author)

Mindset & Approach

Mindset

There are always mis-perception about using CLI (or Linux in general) that you should throw away before continue reading:

  • using CLI is ‘nerdy’, tricky
  • CLI is hard to learn
  • UI can get almost all the jobs done, so why CLI?
  • etc.

In fact CLI is:

  • easy to learn – depends on what level you want to achieve, but for developer’s daily tasks, it’s a piece of cake!
  • yes, most CLI tasks can be done in UI, except:
    • working environment: you works a lot with servers
    • lightweight: you don’t want to install so many things / heavy stuffs and open them, just to complete a quick simple task (search things in file, extract things from file, etc.)
    • flexibility: you want to combine many simple steps for one tasks, but don’t want to copy things from one tool to another.
    • etc.

Learning a new command

exploration, curiosity!

First and foremost, try to explore by yourself (in an safe sandbox environment) to see what we can do with a specific command and its arguments/options.

Try reading man page, help instruction (below) to see what else can be combined in your command to make it better.

tldr command / web

Although this is not a built-in command / tool on linux (like man pages or help options), tldr  is pretty user-friendly, it will provide some common combination of command’s options.

https://tldr.sh/

You can either install it or try the online version first.

Below is the tldr  output of ls  command, for example.

ChatGPT

Why are we mentioning ChatGPT?

Seriously, why not?

The good point of this method is that ChatGPT will explain to use what really happens when you run suggested script. Try to read them carefully though (if you intend to run it on your production server :> )

man pages

Man page is a built in tool in every linux distribution, which provides manual page for a lot of common command.

If you want to use an online version of man page (don’t do that please), check this out:

In case you want to know how to use a specific command, simply run man COMMAND . For example, below is how to use zgrep .

ZGREP(1)                                                                          General Commands Manual                                                                         ZGREP(1)

NAME
       zgrep - search possibly compressed files for a regular expression

SYNOPSIS
       zgrep [ grep_options ] [ -e ] pattern filename...

DESCRIPTION
       Zgrep  invokes grep on compressed or gzipped files.  All options specified are passed directly to grep.  If no file is specified, then the standard input is decompressed if neces‐
       sary and fed to grep.  Otherwise the given files are uncompressed if necessary and fed to grep.

       If the GREP environment variable is set, zgrep uses it as the grep program to be invoked.

EXIT STATUS
       Exit status is 0 for a match, 1 for no matches, and 2 if trouble.

BUGS
       The following grep options are not supported: --dereference-recursive (-R), --directories (-d), --exclude, --exclude-from, --exclude-dir, --include, --null (-Z), --null-data (-z),
       and --recursive (-r).

AUTHOR
       Charles Levert (charles@comm.polymtl.ca)

SEE ALSO
       grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1)

                                                                                                                                                                                  ZGREP(1)
 Manual page zgrep(1) line 1/28 (END) (press h for help or q to quit)

💡 Tips: man page of man page

Man page has so many other useful options of its own, that can be used to looking for specific manual part of a command.

Don’t know how to use man ??:)

man man

help options

Most command line tool will come with help  options.

# high level
# COMMAND -h
# COMMAND --help
# COMMAND help
grep --help
netstat -h

# help of specific option
# COMMAND <options> -h
az vm list -h

# often try this last one when I'm lazy :) -> it's not 100% safe though.
# COMMAND <random options that you're sure that they don't exist>
netstat -aksenfajekf

Output of the last one:

netstat -aksenfajekf

netstat: invalid option -- 'k'
usage: netstat [-vWeenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}
       netstat [-vWnNcaeol] [<Socket> ...]
       netstat { [-vWeenNac] -i | [-cnNe] -M | -s [-6tuw] }

        -r, --route              display routing table
        -i, --interfaces         display interface table
        -g, --groups             display multicast group memberships
        -s, --statistics         display networking statistics (like SNMP)
        -M, --masquerade         display masqueraded connections

        -v, --verbose            be verbose
        -W, --wide               don't truncate IP addresses
        -n, --numeric            don't resolve names
        --numeric-hosts          don't resolve host names
        --numeric-ports          don't resolve port names
        --numeric-users          don't resolve user names
        -N, --symbolic           resolve hardware names
        -e, --extend             display other/more information
        -p, --programs           display PID/Program name for sockets
        -o, --timers             display timers
        -c, --continuous         continuous listing

        -l, --listening          display listening server sockets
        -a, --all                display all sockets (default: connected)
        -F, --fib                display Forwarding Information Base (default)
        -C, --cache              display routing cache instead of FIB
        -Z, --context            display SELinux security context for sockets

  <Socket>={-t|--tcp} {-u|--udp} {-U|--udplite} {-S|--sctp} {-w|--raw}
           {-x|--unix} --ax25 --ipx --netrom
  <AF>=Use '-6|-4' or '-A <af>' or '--<af>'; default: inet
  List of possible address families (which support routing):
    inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)
    netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)
    x25 (CCITT X.25)

What’s next?

Hopefully this part can give you a good-enough mindset and approach to step on the path of a CLI geeky.

In upcoming post, we will see what are common parts of every command, so you can get familiar with a new command quicker.

Link will be updated in this post.

Tagged in:

, , ,