Let’s start out with something fun. My favorite Linux commands!

nc (or netcat)

This command is great for testing if a port is open on a server. The -t and -u flags indicate if the TCP or UDP protocol should be used. This example tests if port 80 is open to TCP connections on the google.com server.

$ nc -tzv google.com 80
Connection to google.com (172.217.164.110) 80 port [tcp/http] succeeded!

tree

I find the tree command very useful. It’s such a neat way to get an overview of a directory.

$ tree .
.
├── subdir1
│   └── file1.txt
├── subdir2
│   └── file2.txt
└── subdir3
    └── file3.txt

The tree command has a flag -L that allows you specify the max display depth of the directory tree.

$ tree -L 1 .
.
├── subdir1
├── subdir2
└── subdir3

shred

shred is a great way to make sure that a file is “destroyed” when you delete it, making recovery much more difficult.

$ shred -u /path/to/file.txt
NAME
       shred - overwrite a file to hide its contents, and optionally delete it

SYNOPSIS
       shred [OPTION]... FILE...

DESCRIPTION
       Overwrite  the  specified FILE(s) repeatedly, in order to make it harder for even very ex‐pensive hardware probing to recover the data.

       -n, --iterations=N
              overwrite N times instead of the default (3)

       -u     deallocate and remove file after overwriting

watch

If you ever find yourself hitting the up arrow and re-running commands, then watch might make your life a lot easier.

For instance, let’s say I want to see the current system timestamp.

$ watch date

This will execute the date command every 2 seconds (default interval is 2 seconds). The interval can be changed with -n <seconds>.

NAME
       watch - execute a program periodically, showing output fullscreen

SYNOPSIS
       watch [options] command

DESCRIPTION
       watch  runs  command  repeatedly, displaying its output and errors (the first screenfull).
       This allows you to watch the program output change over time.  By default, command is  run every 2 seconds and watch will run until interrupted.

OPTIONS

       -n, --interval seconds
              Specify update interval.  The command will not allow quicker than 0.1 second inter‐ val,  in  which the smaller values are converted. Both '.' and ',' work for any lo‐ cales. The WATCH_INTERVAL environment can be used to persistently set a non-default interval (following the same rules and formatting).

at

Sometimes you just need to run a program or script once, but at a later time. The at command will do this. at will allow you to queue and schedule jobs.

Here’s an example. Let’s reboot a system at 4 in the morning.

$ at 4am
warning: commands will be executed using /bin/sh
at Mon Dec 20 04:00:00 2021
at> reboot
at>

JohnBiz.net

Technophile and outdoor enthusiast