CompTIA Linux+ (XK0-004)
Red Hat Enterprise Linux
Git and Github
Learn Docker and Kubernates
Tips and Tricks

1. Using Essentials Tools

Seven Basic Commands

  • whoami - showing the name of the current user

  • hostname - showing the name of the host

  • uname -a - information about the kernel, build and platform

  • passwd - manage password

  • touch - create a new file and change the timestamp

  • date - shows the current date and time and you can also set the current date and time.

  • last - all the users that have logged into your system last.

Getting help from man pages

Command summary: shows how to use command

  • Items between [brackets] are optional

  • If you see { a | b }, you must choose one of them

  • And, ... means you may have more of the preceding items

Man pages have sections

  • 1 is for end-user commands

  • 5 is for configuration files

  • 8 is for administrator (root) commands

Many man pages have examples towards the end. Otherwise, they will have related items sometimes.

  • User /searchtext to search for text inside the man page

  • Use q to get out of the man page

  • Press small g to go top in the man page and press capital G to go down.

For example:

whoami command
  • [OPTIONS] - Though optional because it is inside the square brackets, you can replace them by the options such as --help, --version

  • ... shows you can give more than one option at a time(, it didn't work though in this case).

Help Systems Overview

  • man is the primary source

  • command --help provides short usage overview

  • /user/share/doc contains additional help from some commands

  • pinfo shows usage information for some commands

How to find the command

Many a times, you want to do something but you don't know the command you want to use. This method might help drill down the command you want to use. This example shows how you can find the right command if you want to add/create a user:

If you can't find a command that should exist in your system, try sudo mandb.

Globbing (Wildcards)

  • * => for everything

  • ? => for one single character

  • [a-z] => for range

  • Remember, they can be combined together

Examples:

  • ls -d a* => all directories with the name a.

  • ls *a => all files that ends with a.

  • ls -d a?s* => directories that starts with a, then any single character, then s and then any number of any characters

  • ls -d [a-z]? => directories whose first character would be between a and z and the second character would be anything.

Find Command

Archiving Files with Tar

  • Tar is Tape ARchiver and was created a long time ago.

  • Basic use is to compress, extract, or list

    • tar -cvf my_archive.tar /home

      • Creates tar archive of home directory.

    • tar -xvf my_archive

      • Notice this extracts to the current directory

      • Use -C to switch the output path

    • tar -tvf my_archive.tar will show the contents of an archive without extracting it.

  • Add compression using -z (gzip) or -j (bzip)

Example 0: Checking File type

  • file utility helps us identify the file type without touching it.

  • Linux doesn't have a special usage of a file extension but it does

Example 1: Archiving Files:

  • In the first example, archiving files in the current working directory.

  • In the second example, looking into the tar archive without extracting it.

Example 2: Extracting files in a different directory:

Example 3: Compressing files with -z (gzip tool)

tar -czvf the_file_name.tgz archive.tar

Understanding Compression Utilities

  • gzip -(z) is the most common compression utility

  • bzip2 (-j) is an alternative utility

  • zip can be used as well, and has a Windows-compatible syntax.

  • Some other compression utilities exit as well. (xz)