Set Date and Time for Each Command You Execute in Bash History

By default, all commands executed by Bash on the command line are stored in history buffer or recorded in a file called ~/.bash_history. This means that a system administrator can view a list of commands executed by users on the system or a user can view his/her command history using the history command like so.

$ history

Linux History Command

Linux History Command

From the output of the history command above, the date and time when a command was executed is not shown. This is the default setting on most if not all Linux distributions.

In this article, we will explain how you can configure time stamp information when each command in the Bash history was executed to be displayed.

The date and time associated with each history entry can be written to the history file, marked with the history comment character by setting the HISTTIMEFORMAT variable.

There are two possible ways of doing this: one does it temporarily while the other makes it permanent.

To set HISTTIMEFORMAT variable temporarily, export it as below on the command line:

$ export HISTTIMEFORMAT='%F %T'

In the export command above, the time stamp format:

  1. %F – expands to full date same, as %Y-%m-%d (year-month-date).
  2. %T – expands to time; same as %H:%M:%S (hour:minute:seconds).

Read through the date command man page for additional usage information:

$ man date

Then check your command history as follows:

$ history 

Display Linux Command History with Date and Time

Display Linux Command History with Date and Time

However, if you want to configure this variable permanently, open the file ~/.bashrc with your favorite editor:

$ vi ~/.bashrc

And add the line below in it (you mark it with a comment as your own configuration):

#my config
export HISTTIMEFORMAT='%F %T'

Save the file and exit, afterwards, run the command below to effect the changes made to the file:

$ source ~/.bashrc

That’s all! Do share with us any interesting history command tips and tricks or your thoughts about this guide via the comment section below.

Source

zstd – A Fast Data Compression Algorithm Used By Facebook

Zstandard (also known as zstd) is a free open source, fast real-time data compression program with better compression ratios, developed by Facebook. It is a lossless compression algorithm written in C (there is a re-implementation in Java) – its thus a native Linux program.

Read Also10 7zip (Data Comperssion) Command Examples in Linux

When required, it can trade compression speed for stronger compression ratios (compression speed vs compression ratio trade-off can be configured by small increments), vice versa. It has a special mode for small data compression, known as dictionary compression, and can build dictionaries from any sample set provided. It comes with a command line utility for creating and decoding .zst.gz.xz and .lz4 files.

Importantly, Zstandard has a rich collection of APIs, supports almost all popular programming languages including Python, Java, JavaScript, Nodejs, Perl, Ruby, C#, Go, Rust, PHP, Switft, and lots more.

It is actively used to compress large volumes of data in multiple formats and use cases in Facebook; services such as Amazon Redshift data warehousing; databases such as Hadoop and Redis; the Tor network and many other applications including games.

The following results are obtained by doing several fast compression algorithms tests on a server running Linux Debian using lzbench, an open-source in-memory benchmark tool.

Zstandard Compression Testing

Zstandard Compression Testing

How to Install Zstandard Compression Tool in Linux

To install Zstandard on a Linux distribution, you need to compile it from sources, but before that first you need to install the necessary development tools on your system using your distribution package manager as shown.

$ sudo apt update && sudo apt install build-essential		#Ubuntu/Debian
# yum group install "Development Tools" 			#CentOS/REHL
# dnf groupinstall "C Development Tools and Libraries"		#Fedora 22+

Once all the needed development tools installed, now you can download the source package, move into the local repo directory, build the binary and install it as shown.

$ cd ~/Downloads
$ git clone https://github.com/facebook/zstd.git
$ cd zstd
$ make
$ sudo make install 

Once Zstandard installed, now we can move further to learn some basic usage of Zstd command examples in the following section.

Learn 10 Zstd Command Usage Examples in Linux

Zstd’s command line syntax is generally similar to that of gzip and xz tools, with a few differences.

1. To create a .zst compression file, simply provide a filename to compress it or use the -z flag also means compress, which is the default action.

$ zstd etcher-1.3.1-x86_64.AppImage 
OR
$ zstd -z etcher-1.3.1-x86_64.AppImage 

2. To decompress a .zst compression file, use the -d flag or the unzstd utility as shown.

$ zstd -d etcher-1.3.1-x86_64.AppImage.zst 
OR
$ unzstd etcher-1.3.1-x86_64.AppImage.zst 

3. To remove source file after an operation, by default, the source file is not deleted after successful compression or decompression, to delete it, use the --rm option.

$ ls etcher-1.3.1-x86_64.AppImage
$ zstd --rm  etcher-1.3.1-x86_64.AppImage
$ ls etcher-1.3.1-x86_64.AppImage

4. To set a compression level, zstd has a number of operation modifiers, for instance you can specify a compression level as -6(a number 1-19, default is 3) as shown.

$ zstd -6 --rm etcher-1.3.1-x86_64.AppImage

5. To set a compression speed, zstd has a compression speed ratio 1-10, the default compression speed is 1. You can trade compression ratio for compression speed with the --fast option, the higher the number the faster the compression speed.

$ zstd --fast=10 etcher-1.3.1-x86_64.AppImage

6. To display information about a compressed file, use the -l flag, which is used to display information about a compressed file, for example.

$ zstd -l etcher-1.3.1-x86_64.AppImage.zst

7. To test the integrity of a compressed files, use the -t flag as shown.

$ zstd -t etcher-1.3.1-x86_64.AppImage.zst

8. To enable verbose mode, use the -v option.

$ zstd -v -5 etcher-1.3.1-x86_64.AppImage

9. To use other file compression or decompression formats such as gzip, xz, lzma, and lz4, using the --format=FORMAT as shown.

$ zstd -v --format=gzip etcher-1.3.1-x86_64.AppImage
$ zstd -v --format=xz  etcher-1.3.1-x86_64.AppImage

10. To set a zstd process priority to real-time, you can use the option –priority=rt as shown.

$zstd --priority=rt etcher-1.3.1-x86_64.AppImage

The -r flag instructs zstd to operate recursively on dictionaries. You can find lots of useful and advanced options, how to read or create dictionaries by consulting the zstd man page.

$ man zstd

Zstandard Github Repositoryhttps://github.com/facebook/zstd

Zstandard is a fast real-time, lossless data compression algorithm and compression tool which offers high compression ratios. Try it out and share your thoughts about it or ask questions via the feedback form below.

Source

8 Linux ‘Parted’ Commands to Create, Resize and Rescue Disk Partitions

Parted is a famous command line tool that allows you to easily manage hard disk partitions. It can help you add, delete, shrink and extend disk partitions along with the file systems located on them. Parted has gone a long way from when it first came out. Some of it’s functions have been removed, others have been added.

Parted Command to Manage Linux Disk Partitions

Parted Command to Manage Linux Disk Partitions

In this tutorial you will learn the basics of parted and we will show you some practical examples. If you don’t have any previous experience with parted, please be aware that parted writes the changes immediately to your disk, so be careful if you try to modify your disk partitions.

If you plan on testing parted, the better option would be to simply use a virtual machine or old computer/laptop without any valuable information on it. To make modifications on a disk partition it must not be in use. If you need to work on primary partition, you may boot into rescue mode.

Note: You will need to have root access to the machine you will be working on in order to use parted.

How to Install Parted on Linux

On many Linux distributions, parted comes pre-installed. If it is not included in your distro, you can install it with:

$ sudo apt-get install parted           [On Debian/Ubuntu systems]
# yum install parted                    [On RHEL/CentOS and Fedora]
# dnf install parted                    [On Fedora 22+ versions]

Once you have make sure that parted is installed, you can proceed further to check out some real world examples of parted command in the rest of this article.

1. Check Parted Version

Run the following command, you see message similar to the one shown on the image below. Don’t worry if your parted version is different. Unless specified otherwise, parted will use your primary drive, which in most cases will be /dev/sda.

$ parted

Check Parted Command Version

Check Parted Command Version

If you want to exit parted, simply type:

$ quit

2. List Linux Disk Partitions

Now that parted is started, let’s list the partitions of the selected hard disk. As mentioned earlier, parted chooses your first drive by default. To see the disk partitions run print.

(parted) print

Check Linux Partitions

Check Linux Partitions

When running print, it will also display the hard disk information and model. Here is example from a real hard disk (not virtual as shown on the image above) :

(parted) print

Model: ATA TOSHIBA MQ01ACF0 (scsi)
Disk /dev/sda: 320GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos

Number  Start   End    Size   Type      File system  Flags

 1      1049kB  256MB  255MB  primary   ext2         boot
 2      257MB   320GB  320GB  extended
 5      257MB   320GB  320GB  logical                lvm

In the example above, you can see the disk model, capacity sector size and partition table.

3. List or Switch to Different Disk

If you have more than one hard disk, you can easily switch between disks, by using the “select” command. In the example below, I will switch from /dev/sda to /dev/sdb which is a secondary drive on my system.

To easily switch between disks you can use:

(parted) select /dev/sdX

Select Different Disk

Select Different Disk

Change "X" with the letter of the disk to which you wish to switch.

4. Create Primary or Logical Partition in Linux

Parted can be used to create primary and logical disk partitions. In this example, I will show you how to create primary partition, but the steps are the same for logical partitions.

To create new partition, parted uses “mkpart“. You can give it additional parameters like "primary" or "logical" depending on the partition type that you wish to create.

Before you start creating partitions, it’s important to make sure that you are using (you have selected) the right disk.

Start by using print:

(parted) print

Show Current Linux Disk

Show Current Linux Disk

As shown on the above image, we are using a virtual drive of 34 GB. First we will give the new disk a label and then create a partition and set a file system on it.

Now the first step is to give the new disk a label name with:

(parted) mklabel msdos

Now create the new partition with  mkpart. The listed units are in megabytes (MB). We will create a 10 GBpartition starting from 1 to 10000:

(parted) mkpart
 
Partition type?  primary/extended? primary
File system type?  [ext2]?
Start? 1
End? 10000
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 34.4GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 
Number  Start   End     Size    Type     File system  Flags
 1      1049kB  10.0GB  9999MB  primary  ext2         lba

Create Primary or Logical Linux Partitions

Create Primary or Logical Linux Partitions

Next,  exit parted with "quit" command. We will format our new partition in ext4 file system using mkfs. To make this happen run the following command:

# mkfs.ext4 /dev/sdb1

Note: It’s important to select the right disk and partition when executing the above command!

Now let’s verify our results, by printing the partition table on our secondary disk. Under file system column, you should see ext4 or the file system type that you have decided to use for your partition:

Verify Disk Partition Filesystem

Verify Disk Partition Filesystem

5. Resize Linux Disk Partition

Parted includes multiple useful functions and one of them is "resizepart". As you have probably figured this out by now, "resizepart" helps you resize a partition.

In the example below, you will see how to resize an existing partition. For the purpose of this example, we will be using the earlier created partition.

First you will need to know the number of the partition that you will be resizing. This can be easily found by using "print":

(parted) print

Find Linux Partition Number

Find Linux Partition Number

In our example, the partition number is "1". Now run the resizepart command:

(parted) resizepart

You will be asked for the number of the partition that you will resize. Enter it’s number. After that, you will be asked to set the new ending point for this partition. Remember that by default the units are in MB. In our example, we have set the new partition size to 15 GB:

(parted) resizepart 
Partition number? 1
End?  [10.0GB]? 15000

Now verify the results with "print":

(parted) print

Verify Linux Resize Partition

Verify Linux Resize Partition

6. Delete Linux Partition

The next thing you will learn is how to delete a partition from your hard drive. To do this, you will need to use the "rm" command within parted. To delete a disk partition you will need to know it’s number.

As mentioned earlier, you can easily obtain this number by using "print". In our example, we will delete the partition with number 1 from our secondary drive /dev/sdb1:

(parted) rm 1

Verify the results by printing the partitions table:

Delete a Linux Partition

Delete a Linux Partition

7. Rescue Linux Disk Partition

Parted supports a “rescue" utility that helps you recover a lost partition between a starting and ending point. If a partition is found within that range, it will attempt to restore it.

Here is an example:

(parted) rescue
Start? 1
End? 15000
(parted) print
Model: Unknown (unknown)
Disk /dev/sdb1: 15.0GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number Start End Size File system Flags
1 0.00B 15.0GB 15.0GB ext4

8 Change Linux Partition Flag

Using parted, you can change the state of a flag for disk partitions. The supported flags are:

  1. boot
  2. root
  3. swap
  4. hidden
  5. raid
  6. lvm
  7. lba
  8. legacy_boot
  9. irst
  10. esp
  11. palo

The states can be either "on" or "off". To change a flag simply run "set" command within parted:

(parted) set 2 lba on

The above command sets lba flag to on for second partition. Verify the results with print:

Change Partition Flag

Change Partition Flag

Conclusion

Parted is a useful and powerful utility that can help you manage your disk partitions in Linux systems. As always, when working with disk partitions you need to be extra careful. It is strongly recommend to go through parted man pages to learn how you can customize it’s output and find more information about its capabilities.

If you have any questions or comments, please do not hesitate to use the comment section below.

Source

Cheat – An Ultimate Command Line ‘Cheat-Sheet’ for Linux Beginners and Administrators

What you do when you are not sure of the command you are running especially in case of complex commands which uses a lot of options. We use man pages to get some help in such situation. Some of the other options may include commands like ‘help‘, ‘whereis‘ and ‘whatis‘. But all has their Pros and Cons.

While going through man pages for options and help, the description in man pages are too lengthy to understand specially in short span of time.

Linux Man Pages

Linux Man Pages

Similarly, ‘help‘ command may not give you desired output.

Linux help command

Help Command

A ‘whereis‘ command hardly tells anything other than the location of Installed Binaries (May be Important at time).

Linux Whereis Command

Whereis Command

A ‘whatis‘ command gives strict and one liner answer which is not much helpful other than acknowledging the purpose of the command, Moreover it never says a single word about the available options.

Linux Whatis Command

Whatis Command

We have used all these options till date to solve our issue in the dilemma but here comes an interactive cheat-sheet application ‘cheat‘ which is going to lead all the rest.

What is cheat?

Cheat is an interactive cheat-sheet application released under GNU General Public License for Linux Command line users which serves the purpose of showing, use cases of a Linux command with all the options and their short yet understandable function.

Install Cheat in Linux

Cheat: Provides Easy Command Options

Installing ‘Cheat’ in Linux Systems

Cheat‘ has two major dependency – ‘python‘ and ‘pip‘. Make sure you have installed python and pip before installing ‘cheat‘ on the system.

Install Python
# apt-get install Python	(On Debian based Systems)
# yum install python		(On RedHat based Systems)
Install Pip
# apt-get install python-pip 	(On Debian based Systems)
# yum install python-pip 	(On RedHat based Systems)

NOTE: pip is an easy install replacement and is intended to be an improved Python package installer.

Download and Install Cheat

We will be downloading ‘cheat’ from Git. Make sure you have package ‘git’ installed, if not better install this first.

# apt-get install git	(On Debian based Systems)
# yum install git	(On RedHat based Systems)

Next, install the required python dependencies by running following command.

# pip install docopt pygments

Now, clone the Git repository of cheat.

# git clone https://github.com/chrisallenlane/cheat.git

Move to the cheat directory and run ‘setup.py‘ (a python script).

# cd cheat
# python setup.py install

If installation goes smoothly, you should be able to see a cheat version installed on the system.

# cheat -v 

cheat 2.0.9

Required Configuration for Cheat

You must have an ‘EDITOR‘ environment variable set in ‘~/.bashrc’ file. Open the user ‘.bashrc‘ file and add the following line to it.

export EDITOR=/usr/bin/nano

You can use your favourite editor here in place of ‘nano‘. Save the file and logout. Again Login to make the changes taken into effect.

Next, add the cheat autocompletion feature to enable command-line autocompletion for different shells. To enable autocompletion, simply clone the ‘cheat.bash‘ script and copy the script to the appropriate path in your system.

# wget https://github.com/chrisallenlane/cheat/raw/master/cheat/autocompletion/cheat.bash 
# mv cheat.bash /etc/bash_completion.d/

NOTE: The team has uploaded other shell’s auto completion scrip to Git, which may be cloned and used in case of respective Shell. Use the following link for other shell’s auto completion script.

  1. Auto Completion Script for Various Shells

Optionally, you can also enable syntax highlighting, if desired. To active syntax highlighting feature, add a CHEATCOLORS environment variable in your ‘.bashrc‘ file.

export CHEATCOLORS=true

The Cheat application default program only serves the basic and most used commands. The content of cheat-sheet resides at location ~/.cheat/. Manual Cheatsheets can be added to this location to make the application rich.

# cheat -e xyz

This will open xyz cheat-sheet if available. If not it will create one. The cheat-sheet will be opened in the default EDITOR, we set in .bashrc in the configuration stage, above.

Usage of Cheat with Some Commands

A tarball may be *.gz or *.bz2 or *.zip or *.xz. So, what option to be used where?

Linux Tar Command

tar command options

I never run dd command, no matter how much sure I am about the command before consulting and cross checking it at more than one location. The things seems to be easy now.

Linux dd Command

dd command options

A ‘uname‘ command help.

Linux uname Command

uname command options

A short ifconfig command line tutorial, in action.

Linux ifconfig Command

ifconfig command options

A ‘top‘ command, one of the most important command for Admin and Normal User.

Linux top Command

top command options

How about Cheating the cheat command (though the other sense)? Get a list of available commands, the cheat-sheet of which is installed in the System.

List All Linux Commands

List All Linux Commands

Search Cheat-sheet with specific keyword.

Search Cheat Sheet

Search Cheat Sheet

See the location of built-in cheat-sheets for all the commands.

$ cheat -d 

/home/avi/.cheat 
/usr/local/lib/python2.7/dist-packages/cheat/cheatsheets

Copy the in-built cheat-sheet to your native directory.

# cp /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/* /home/avi/.cheat/

Conclusion

This wonderful project is a life Saviour in many-a-situation. It just gives you information that is required, nothing extra, nothing vague and to the point. This is a must tool for everyone. Easy to build, easy to install, easy to run and easy to understand, this project seems promising.

This Git project has added a wonderful gag which I am not going to explain but leave on you to interpret.

Linux Gag

Linux Gag

That’s all for now. I’ll be here again with another interesting article you people will love to read. Till then stay tuned and connected to Tecmint. Don’t forget to provide us with your valuable feedback in the comment section below.

Don’t MissUnderstanding Shell Commands Easily Using “Explain Shell” Script

Source

Boxes – Draws ASCII Art Boxes and Shapes in Linux Terminal

Boxes is a simple, configurable command line program which can draw any kind of box around its input text. It filters text and draws shapes around it – it’s practically a text filter. In fact it is designed to be integrated with your editor as a text filter (supports Vim default). It can draw shapes ranging from simple boxes to complex ASCII art.

In this article, we will learn how to use the boxes utility to draw shapes in the Linux terminal.

How to Install Boxes Utility in Linux

To install the boxes utility in Linux, use the appropriate command for your distribution.

$ sudo apt install boxes  [On Debian/Ubuntu]
$ sudo yum install boxes  [On CentOS/RHEL]
$ sudo dnf install boxes  [On Fedora]

Now that you have boxes installed, note that it uses the $HOME/.boxes user specific configuration file or the /etc/boxes/boxes-config system-wide configuration file.

Let’s have some Linux terminal fun.

To see the default boxes design, simply provide some input text to it as shown.

$ echo "Hey, this is Tecmint.com! Thanks for following us." | boxes

/******************************************************/
/* Hey, this is Tecmint.com! Thanks for following us. */
/******************************************************/

To specify another design, use the -d flag as shown.

$ echo "Hey, this is Tecmint.com! Thanks for following us." | boxes -d boy

                        .-"""-.
                       / .===. \
                       \/ 6 6 \/
                       ( \___/ )
  _________________ooo__\_____/_____________________
 /                                                  \
| Hey, this is Tecmint.com! Thanks for following us. |
 \______________________________ooo_________________/
                       |  |  |
                       |_ | _|
                       |  |  |
                       |__|__|
                       /-'Y'-\
                      (__/ \__)

To align or position text inside the box, use the -a flag. Let’s demonstrate how this works with the following example (where the c means center).

$ echo "Hey, this is Tecmint.com! Thanks for following us." | boxes -d diamonds

       /\          /\          /\          /\          /\
    /\//\/\    /\//\/\    /\//\/\    /\//\/\    /\//\/\
 /\//\\///\/\//\\///\/\//\\///\/\//\\///\/\//\\///\/\
//\\//\/\///\\//\/\///\\//\/\///\\//\/\///\\//\/\///\
\//\/Hey, this is Tecmint.com! Thanks for following us.  \/\//
 \/                                                          \/
 /\                                                          /\
//\                                                        //\
\//                                                        \//
 \/                                                          \/
 /\                                                          /\
//\/\                                                    /\//\
\///\/\//\\///\/\//\\///\/\//\\///\/\//\\///\/\//\\//
 \/\///\\//\/\///\\//\/\///\\//\/\///\\//\/\///\\//\/
    \/\//\/    \/\//\/    \/\//\/    \/\//\/    \/\//\/
       \/          \/          \/          \/          \/
$ echo "Hey, this is Tecmint.com! Thanks for following us." | boxes -d diamonds -a c

       /\          /\          /\          /\          /\
    /\//\/\    /\//\/\    /\//\/\    /\//\/\    /\//\/\
 /\//\\///\/\//\\///\/\//\\///\/\//\\///\/\//\\///\/\
//\\//\/\///\\//\/\///\\//\/\///\\//\/\///\\//\/\///\
\//\/                                                    \/\//
 \/                                                          \/
 /\                                                          /\
//\   Hey, this is Tecmint.com! Thanks for following us.   //\
\//                                                        \//
 \/                                                          \/
 /\                                                          /\
//\/\                                                    /\//\
\///\/\//\\///\/\//\\///\/\//\\///\/\//\\///\/\//\\//
 \/\///\\//\/\///\\//\/\///\\//\/\///\\//\/\///\\//\/
    \/\//\/    \/\//\/    \/\//\/    \/\//\/    \/\//\/
       \/          \/          \/          \/          \/

In the Christmas season, you can use the santa design to send your family and friends happy holiday messages, for example.

$ echo "Tecmint.com wishes you a Merry Christmas and a Happy New Year 2019" | boxes -d santa

                                 .-"``"-.
                                /______; \
                               {_______}\|
                               (/ a a \)(_)
                               (.-.).-.)
  _______________________ooo__(    ^    )___________________________
 /                             '-.___.-'                            \
| Tecmint.com wishes you a Merry Christmas and a Happy New Year 2019 |
 \________________________________________ooo_______________________/
                               |_  |  _|  jgs
                               \___|___/
                               {___|___}
                                |_ | _|
                                /-'Y'-\
                               (__/ \__)

To list all available designs/styles, run the following command.

$ boxes -l

59 Available Styles in "/etc/boxes/boxes-config":
-------------------------------------------------

ada-box
(public domain), coded by Neil Bird <neil.bird@rdel.co.uk>:

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


ada-cmt
(public domain), coded by Neil Bird <neil.bird@rdel.co.uk>:

    --
    -- regular Ada
    -- comments
...

It supports line justification, box size specification, text padding, indentation, use of regular expressions and much more.

Valentine’s day coming closer, and you wanted to impress your girlfriend or wife in a Linux way, then use boxes as shown.

$ echo -e "\n\tMe: Will you be my Valentine?\n\tGirl: No way\n\tMe: sudo will you be my Valentine?\n\tGirl: Yes..yes..yes! Let's go!" | boxes -d boy

                        .-"""-.
                       / .===. \
                       \/ 6 6 \/
                       ( \___/ )
          _________ooo__\_____/_____________
         /                                  \
        |                                    |
        | Me: Will you be my Valentine?      |
        | Girl: No way                       |
        | Me: sudo will you be my Valentine? |
        | Girl: Yes..yes..yes! Let's go!     |
         \______________________ooo_________/
                       |  |  |
                       |_ | _|
                       |  |  |
                       |__|__|
                       /-'Y'-\
                      (__/ \__)

For more information and examples, go to http://boxes.thomasjensen.com/examples.html.

Boxes is a command line utility that draws a box around its input text. In this article, we will learn how to install and use boxes utility to draw shapes in the Linux terminal. Use the feedback form below to share your thoughts about it.

Source

How to Use ‘at’ Command to Schedule a Task on Given or Later Time in Linux

As an alternative to cron job scheduler, the at command allows you to schedule a command to run once at a given time without editing a configuration file.

The only requirement consists of installing this utility and starting and enabling its execution:

# yum install at              [on CentOS based systems]
$ sudo apt-get install at     [on Debian and derivatives]

Next, start and enable the at service at the boot time.

--------- On SystemD ---------
# systemctl start atd
# systemctl enable atd

--------- On SysVinit ---------
# service atd start
# chkconfig --level 35 atd on

Once atd is running, you can schedule any command or task as follows. We want to send 4 ping probes to www.google.com when the next minute starts (i.e. if it’s 22:20:13, the command will be executed at 22:21:00) and report the result through an email (-m, requires Postfix or equivalent) to the user invoking the command:

# echo "ping -c 4 www.google.com" | at -m now + 1 minute

If you choose to not use the -m option, the command will be executed but nothing will be printed to standard output. You can, however, choose to redirect the output to a file instead.

In addition, please note that at not only allows the following fixed times: now, noon (12:00), and midnight (00:00), but also custom 2-digit (representing hours) and 4-digit times (hours and minutes).

For example,

To run updatedb at 11 pm today (or tomorrow if the current date is greater than 11 pm), do:

# echo "updatedb" | at -m 23

To shutdown the system at 23:55 today (same criteria as in the previous example applies):

# echo "shutdown -h now" | at -m 23:55

You can also delay the execution by minutes, hours, days, weeks, months, or years using the + sign and the desired time specification as in the first example.

Time specifications are subject to the POSIX standard.

Summary

As a rule of thumb, use at instead of cron job scheduler whenever you want to run a command or execute a given task at a well-defined time only once. For other scenarios, use cron.

Source

Breaking News! Microsoft is Creating Linux-based Smartphone OS

Breaking News! Microsoft is Creating Linux-based Smartphone OS

Last updated April 1, 2019

Microsoft, the king of desktop operating systems, haven’t had much luck with the mobile operating systems. It’s Windows-based mobile operating systems Windows Mobile and Windows Phone, both failed miserably and have been discontinued.

But that hasn’t deterred Microsoft from trying its hands in the lucrative mobile market again.

Microsoft’s yet another attempt on mobile OS

Microsoft's Linux-based mobile OS

The unconfirmed news is that Microsoft is creating a Linux-based mobile operating system with a special focus on protecting users’ privacy.

We have put special attention on user privacy. There will be no data collection through Cortana. The OS will not be updated without user permission and above all, the updates won’t require you to restart your system several times. That itself is our biggest achievement till date.

Don Jhoe, Microsoft Product Manager

Reports are not confirmed but the project is internally called “Mazure”. The name could be changed as the project progresses.

The Mazure OS will be completely open source. This shows the firm commitment to open source development from Microsoft. This is another effort from Microsoft to give back to the community by open sourcing essential tools like Windows calculator app.

Targeting 4 billion strong mobile OS market

There are over 4 billion mobile devices in the world. A tech-giant like Microsoft cannot simply give up on this big a market.

The world of mobile operating systems is dominated by Android and iOS and many experts think that it is saturated and a new player doesn’t stand a chance.

But Linux-based KaiOS came into the market in 2017 and created a niche for itself in just one year.

This moderate success of KaiOS perhaps gave Microsoft the idea to launch its own mobile operating system based on Linux.

Lately, a number of open source mobile operating system projects have come up. Almost all of them use Linux kernel underneath.

Linux-based smartphones are also a hot-topic in tech world. Librem5 and Necuno have already announced Linux-based smartphones with focus on privacy.

Microsoft has taken the same idea and started its own Linux-based mobile OS “Mazure” with a promise to protect user’s privacy.

You can find more information about this project on its extremely confidential website below.

Source

A Linux Sysadmin’s Guide to Network Management, Troubleshooting and Debugging

A system administrator’s routine tasks include configuring, maintaining, troubleshooting, and managing servers and networks within data centers. There are numerous tools and utilities in Linux designed for the administrative purposes.

In this article, we will review some of the most used command-line tools and utilities for network management in Linux, under different categories. We will explain some common usage examples, which will make network management much easier in Linux.

Table of Contents
ifconfig Command ip Command ifup Command ethtool Command ping Command
traceroute Command mtr Command route Command nmcli Command netstat Command
ss Command nc Command nmap Command host Command dig Command
nslookup Command tcpdump Command Wireshark Utility bmon Tool iptables Firewall
firewalld UFW Firewall

This list is equally useful to full-time network engineers.

Network Configuration, Troubleshooting and Debugging Tools

1. ifconfig Command

ifconfig is a command line interface tool for network interface configuration and also used to initialize an interfaces at system boot time. Once a server is up and running, it can be used to assign an IP Address to an interface and enable or disable the interface on demand.

It is also used to view the status IP Address, Hardware / MAC address, as well as MTU (Maximum Transmission Unit) size of the currently active interfaces. ifconfig is thus useful for debugging or performing system tuning.

Here is an example to display status of all active network interfaces.

$ ifconfig

enp1s0    Link encap:Ethernet  HWaddr 28:d2:44:eb:bd:98  
          inet addr:192.168.0.103  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::8f0c:7825:8057:5eec/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:169854 errors:0 dropped:0 overruns:0 frame:0
          TX packets:125995 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:174146270 (174.1 MB)  TX bytes:21062129 (21.0 MB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:15793 errors:0 dropped:0 overruns:0 frame:0
          TX packets:15793 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:2898946 (2.8 MB)  TX bytes:2898946 (2.8 MB)

To list all interfaces which are currently available, whether up or down, use the -a flag.

$ ifconfig -a 	

To assign an IP address to an interface, use the following command.

$ sudo ifconfig eth0 192.168.56.5 netmask 255.255.255.0

To activate an network interface, type.

$ sudo ifconfig up eth0

To deactivate or shut down an network interface, type.

$ sudo ifconfig down eth0

Note: Although ifconfig is a great tool, it is now obsolete (deprecated), its replacement is ip command which is explained below.

2. IP Command

ip command is another useful command line utility for displaying and manipulating routing, network devices, interfaces. It is a replacement for ifconfig and many other networking commands. (Read our article “What’s Difference Between ifconfig and ip Command” to learn more about it.)

The following command will show the IP address and other information about an network interface.

$ ip addr show

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 28:d2:44:eb:bd:98 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.103/24 brd 192.168.0.255 scope global dynamic enp1s0
       valid_lft 5772sec preferred_lft 5772sec
    inet6 fe80::8f0c:7825:8057:5eec/64 scope link 
       valid_lft forever preferred_lft forever
3: wlp2s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 38:b1:db:7c:78:c7 brd ff:ff:ff:ff:ff:ff
...

To temporarily assign IP Address to a specific network interface (eth0), type.

$ sudo ip addr add 192.168.56.1 dev eth0

To remove an assigned IP address from an network interface (eth0), type.

$ sudo ip addr del 192.168.56.15/24 dev eth0

To show the current neighbour table in kernel, type.

$ ip neigh

192.168.0.1 dev enp1s0 lladdr 10:fe:ed:3d:f3:82 REACHABLE

3. ifup, ifdown, and ifquery command

ifup command actives a network interface, making it available to transfer and receive data.

$ sudo ifup eth0

ifdown command disables a network interface, keeping it in a state where it cannot transfer or receive data.

$ sudo ifdown eth0

ifquery command used to parse the network interface configuration, enabling you to receive answers to query about how it is currently configured.

$ sudo ifquery eth0

4. Ethtool Command

ethtool is a command line utility for querying and modifying network interface controller parameters and device drivers. The example below shows the usage of ethtool and a command to view the parameters for the network interface.

$ sudo ethtool enp0s3

Settings for enp0s3:
	Supported ports: [ TP ]
	Supported link modes:   10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Full 
	Supported pause frame use: No
	Supports auto-negotiation: Yes
	Advertised link modes:  10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Full 
	Advertised pause frame use: No
	Advertised auto-negotiation: Yes
	Speed: 1000Mb/s
	Duplex: Full
	Port: Twisted Pair
	PHYAD: 0
	Transceiver: internal
	Auto-negotiation: on
	MDI-X: off (auto)
	Supports Wake-on: umbg
	Wake-on: d
	Current message level: 0x00000007 (7)
			       drv probe link
	Link detected: yes

5. Ping Command

ping (Packet INternet Groper) is a utility normally used for testing connectivity between two systems on a network (Local Area Network (LAN) or Wide Area Network (WAN)). It use ICMP (Internet Control Message Protocol) to communicate to nodes on a network.

To test connectivity to another node, simply provide its IP or host name, for example.

$ ping 192.168.0.103

PING 192.168.0.103 (192.168.0.103) 56(84) bytes of data.
64 bytes from 192.168.0.103: icmp_seq=1 ttl=64 time=0.191 ms
64 bytes from 192.168.0.103: icmp_seq=2 ttl=64 time=0.156 ms
64 bytes from 192.168.0.103: icmp_seq=3 ttl=64 time=0.179 ms
64 bytes from 192.168.0.103: icmp_seq=4 ttl=64 time=0.182 ms
64 bytes from 192.168.0.103: icmp_seq=5 ttl=64 time=0.207 ms
64 bytes from 192.168.0.103: icmp_seq=6 ttl=64 time=0.157 ms
^C
--- 192.168.0.103 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5099ms
rtt min/avg/max/mdev = 0.156/0.178/0.207/0.023 ms

You can also tell ping to exit after a specified number of ECHO_REQUEST packets, using the -c flag as shown.

$ ping -c 4 192.168.0.103

PING 192.168.0.103 (192.168.0.103) 56(84) bytes of data.
64 bytes from 192.168.0.103: icmp_seq=1 ttl=64 time=1.09 ms
64 bytes from 192.168.0.103: icmp_seq=2 ttl=64 time=0.157 ms
64 bytes from 192.168.0.103: icmp_seq=3 ttl=64 time=0.163 ms
64 bytes from 192.168.0.103: icmp_seq=4 ttl=64 time=0.190 ms

--- 192.168.0.103 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3029ms
rtt min/avg/max/mdev = 0.157/0.402/1.098/0.402 ms

6. Traceroute Command

Traceroute is a command line utility for tracing the full path from your local system to another network system. It prints number of hops (router IP’s) in that path you travel to reach the end server. It is an easy-to-use network troubleshooting utility after ping command.

In this example, we are tracing the route packets take from the local system to one of Google’s servers with IP address 216.58.204.46.

$ traceroute 216.58.204.46

traceroute to 216.58.204.46 (216.58.204.46), 30 hops max, 60 byte packets
 1  gateway (192.168.0.1)  0.487 ms  0.277 ms  0.269 ms
 2  5.5.5.215 (5.5.5.215)  1.846 ms  1.631 ms  1.553 ms
 3  * * *
 4  72.14.194.226 (72.14.194.226)  3.762 ms  3.683 ms  3.577 ms
 5  108.170.248.179 (108.170.248.179)  4.666 ms 108.170.248.162 (108.170.248.162)  4.869 ms 108.170.248.194 (108.170.248.194)  4.245 ms
 6  72.14.235.133 (72.14.235.133)  72.443 ms 209.85.241.175 (209.85.241.175)  62.738 ms 72.14.235.133 (72.14.235.133)  65.809 ms
 7  66.249.94.140 (66.249.94.140)  128.726 ms  127.506 ms 209.85.248.5 (209.85.248.5)  127.330 ms
 8  74.125.251.181 (74.125.251.181)  127.219 ms 108.170.236.124 (108.170.236.124)  212.544 ms 74.125.251.181 (74.125.251.181)  127.249 ms
 9  216.239.49.134 (216.239.49.134)  236.906 ms 209.85.242.80 (209.85.242.80)  254.810 ms  254.735 ms
10  209.85.251.138 (209.85.251.138)  252.002 ms 216.239.43.227 (216.239.43.227)  251.975 ms 209.85.242.80 (209.85.242.80)  236.343 ms
11  216.239.43.227 (216.239.43.227)  251.452 ms 72.14.234.8 (72.14.234.8)  279.650 ms  277.492 ms
12  209.85.250.9 (209.85.250.9)  274.521 ms  274.450 ms 209.85.253.249 (209.85.253.249)  270.558 ms
13  209.85.250.9 (209.85.250.9)  269.147 ms 209.85.254.244 (209.85.254.244)  347.046 ms 209.85.250.9 (209.85.250.9)  285.265 ms
14  64.233.175.112 (64.233.175.112)  344.852 ms 216.239.57.236 (216.239.57.236)  343.786 ms 64.233.175.112 (64.233.175.112)  345.273 ms
15  108.170.246.129 (108.170.246.129)  345.054 ms  345.342 ms 64.233.175.112 (64.233.175.112)  343.706 ms
16  108.170.238.119 (108.170.238.119)  345.610 ms 108.170.246.161 (108.170.246.161)  344.726 ms 108.170.238.117 (108.170.238.117)  345.536 ms
17  lhr25s12-in-f46.1e100.net (216.58.204.46)  345.382 ms  345.031 ms  344.884 ms

7. MTR Network Diagnostic Tool

MTR is a modern command-line network diagnostic tool that combines the functionality of ping and traceroute into a single diagnostic tool. Its output is updated in real-time, by default until you exit the program by pressing q.

The easiest way of running mtr is to provide it a host name or IP address as an argument, as follows.

$ mtr google.com
OR
$ mtr 216.58.223.78
Sample Output
tecmint.com (0.0.0.0)                                   Thu Jul 12 08:58:27 2018
First TTL: 1

 Host                                                   Loss%   Snt   Last   Avg  Best  Wrst StDev
 1. 192.168.0.1                                         0.0%    41    0.5   0.6   0.4   1.7   0.2
 2. 5.5.5.215                                           0.0%    40    1.9   1.5   0.8   7.3   1.0
 3. 209.snat-111-91-120.hns.net.in                      23.1%    40    1.9   2.7   1.7  10.5   1.6
 4. 72.14.194.226                                       0.0%    40   89.1   5.2   2.2  89.1  13.7
 5. 108.170.248.193                                     0.0%    40    3.0   4.1   2.4  52.4   7.8
 6. 108.170.237.43                                      0.0%    40    2.9   5.3   2.5  94.1  14.4
 7. bom07s10-in-f174.1e100.net                          0.0%    40    2.6   6.7   2.3  79.7  16.

You can limit the number of pings to a specific value and exit mtr after those pings, using the -c flag as shown.

$ mtr -c 4 google.com

8. Route Command

route is a command line utility for displaying or manipulating the IP routing table of a Linux system. It is mainly used to configure static routes to specific hosts or networks via an interface.

You can view Kernel IP routing table by typing.

$ route

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    100    0        0 enp0s3
192.168.0.0     0.0.0.0         255.255.255.0   U     100    0        0 enp0s3
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

There are numerous commands you can use to configure routing. Here are some useful ones:

Add a default gateway to the routing table.

$ sudo route add default gw <gateway-ip>

Add a network route to the routing table.

$ sudo route add -net <network ip/cidr> gw <gateway ip> <interface>

Delete a specific route entry from the routing table.

$ sudo route del -net <network ip/cidr>

9. Nmcli Command

Nmcli is an easy-to-use, scriptable command-line tool to report network status, manage network connections, and control the NetworkManager.

To view all your network devices, type.

$ nmcli dev status

DEVICE      TYPE      STATE      CONNECTION         
virbr0      bridge    connected  virbr0             
enp0s3      ethernet  connected  Wired connection 1 

To check network connections on your system, type.

$ nmcli con show

Wired connection 1  bc3638ff-205a-3bbb-8845-5a4b0f7eef91  802-3-ethernet  enp0s3 
virbr0              00f5d53e-fd51-41d3-b069-bdfd2dde062b  bridge          virbr0 

To see only the active connections, add the -a flag.

$ nmcli con show -a

Network Scanning and Performance Analysis Tools

10. Netstat Command

netstat is a command line tool that displays useful information such as network connections, routing tables, interface statistics, and much more, concerning the Linux networking subsystem. It is useful for network troubleshooting and performance analysis.

Additionally, it is also a fundamental network service debugging tool used to check which programs are listening on what ports. For instance, the following command will show all TCP ports in listening mode and what programs are listening on them.

$ sudo netstat -tnlp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:587             0.0.0.0:*               LISTEN      1257/master         
tcp        0      0 127.0.0.1:5003          0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN      1015/dovecot        
tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN      1015/dovecot        
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 0.0.0.0:465             0.0.0.0:*               LISTEN      1257/master         
tcp        0      0 0.0.0.0:53              0.0.0.0:*               LISTEN      1404/pdns_server    
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      1064/pure-ftpd (SER 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      972/sshd            
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      975/cupsd           
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      1257/master         
tcp        0      0 0.0.0.0:8090            0.0.0.0:*               LISTEN      636/lscpd (lscpd -  
tcp        0      0 0.0.0.0:993             0.0.0.0:*               LISTEN      1015/dovecot        
tcp        0      0 0.0.0.0:995             0.0.0.0:*               LISTEN      1015/dovecot        
tcp6       0      0 :::3306                 :::*                    LISTEN      1053/mysqld         
tcp6       0      0 :::3307                 :::*                    LISTEN      1211/mysqld         
tcp6       0      0 :::587                  :::*                    LISTEN      1257/master         
tcp6       0      0 :::110                  :::*                    LISTEN      1015/dovecot        
tcp6       0      0 :::143                  :::*                    LISTEN      1015/dovecot        
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::80                   :::*                    LISTEN      990/httpd           
tcp6       0      0 :::465                  :::*                    LISTEN      1257/master         
tcp6       0      0 :::53                   :::*                    LISTEN      1404/pdns_server    
tcp6       0      0 :::21                   :::*                    LISTEN      1064/pure-ftpd (SER 
tcp6       0      0 :::22                   :::*                    LISTEN      972/sshd            
tcp6       0      0 ::1:631                 :::*                    LISTEN      975/cupsd           
tcp6       0      0 :::25                   :::*                    LISTEN      1257/master         
tcp6       0      0 :::993                  :::*                    LISTEN      1015/dovecot        
tcp6       0      0 :::995                  :::*                    LISTEN      1015/dovecot        

To view kernel routing table, use the -r flag (which is equivalent to running route command above).

$ netstat -r

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         gateway         0.0.0.0         UG        0 0          0 enp0s3
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 enp0s3
192.168.122.0   0.0.0.0         255.255.255.0   U         0 0          0 virbr0

Note: Although Netstat is a great tool, it is now obsolete (deprecated), its replacement is ss command which is explained below.

11. ss Command

ss (socket statistics) is a powerful command line utility to investigate sockets. It dumps socket statistics and displays information similar to netstat. In addition, it shows more TCP and state information compared to other similar utilities.

The following example show how to list all TCP ports (sockets) that are open on a server.

$ ss -ta

State      Recv-Q Send-Q                                        Local Address:Port                                                         Peer Address:Port                
LISTEN     0      100                                                       *:submission                                                              *:*                    
LISTEN     0      128                                               127.0.0.1:fmpro-internal                                                          *:*                    
LISTEN     0      100                                                       *:pop3                                                                    *:*                    
LISTEN     0      100                                                       *:imap                                                                    *:*                    
LISTEN     0      128                                                       *:sunrpc                                                                  *:*                    
LISTEN     0      100                                                       *:urd                                                                     *:*                    
LISTEN     0      128                                                       *:domain                                                                  *:*                    
LISTEN     0      9                                                         *:ftp                                                                     *:*                    
LISTEN     0      128                                                       *:ssh                                                                     *:*                    
LISTEN     0      128                                               127.0.0.1:ipp                                                                     *:*                    
LISTEN     0      100                                                       *:smtp                                                                    *:*                    
LISTEN     0      128                                                       *:8090                                                                    *:*                    
LISTEN     0      100                                                       *:imaps                                                                   *:*                    
LISTEN     0      100                                                       *:pop3s                                                                   *:*                    
ESTAB      0      0                                             192.168.0.104:ssh                                                         192.168.0.103:36398                
ESTAB      0      0                                                 127.0.0.1:34642                                                           127.0.0.1:opsession-prxy       
ESTAB      0      0                                                 127.0.0.1:34638                                                           127.0.0.1:opsession-prxy       
ESTAB      0      0                                                 127.0.0.1:34644                                                           127.0.0.1:opsession-prxy       
ESTAB      0      0                                                 127.0.0.1:34640                                                           127.0.0.1:opsession-prxy       
LISTEN     0      80                                                       :::mysql                                                                  :::*             
...

To display all active TCP connections together with their timers, run the following command.

$ ss -to

12 NC Command

NC (NetCat) also referred to as the “Network Swiss Army knife”, is a powerful utility used for almost any task related to TCP, UDP, or UNIX-domain sockets. It is used open TCP connections, listen on arbitrary TCP and UDP ports, perform port scanning plus more.

You can also use it as a simple TCP proxies, for network daemon testing, to check if remote ports are reachable and much more. Furthermore, you can employ nctogether with pv command to transfer files between two computers.

The following example, will show how to scan a list of ports.

$ nc -zv server2.tecmint.lan 21 22 80 443 3000

You can also specify a range of ports as shown.

$ nc -zv server2.tecmint.lan 20-90

The following example shows how to use nc to open a TCP connection to port 5000 on server2.tecmint.lan, using port 3000 as the source port, with a timeout of 10 seconds.

$ nc -p 3000 -w 10 server2.tecmint.lan 5000 

13. Nmap Command

Nmap (Network Mapper) is a powerful and extremely versatile tool for Linux system/network administrators. It is used gather information about a single host or explore networks an entire network. Nmap is also used to perform security scans, network audit and finding open ports on remote hosts and so much more.

You can scan a host using its host name or IP address, for instance.

$ nmap google.com 

Starting Nmap 6.40 ( http://nmap.org ) at 2018-07-12 09:23 BST
Nmap scan report for google.com (172.217.166.78)
Host is up (0.0036s latency).
rDNS record for 172.217.166.78: bom05s15-in-f14.1e100.net
Not shown: 998 filtered ports
PORT    STATE SERVICE
80/tcp  open  http
443/tcp open  https

Nmap done: 1 IP address (1 host up) scanned in 4.92 seconds

Alternatively, use an IP address as shown.

$ nmap 192.168.0.103

Starting Nmap 6.40 ( http://nmap.org ) at 2018-07-12 09:24 BST
Nmap scan report for 192.168.0.103
Host is up (0.000051s latency).
Not shown: 994 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
25/tcp   open  smtp
902/tcp  open  iss-realsecure
4242/tcp open  vrml-multi-use
5900/tcp open  vnc
8080/tcp open  http-proxy
MAC Address: 28:D2:44:EB:BD:98 (Lcfc(hefei) Electronics Technology Co.)

Nmap done: 1 IP address (1 host up) scanned in 0.13 seconds

Read our following useful articles on nmap command.

  1. How to Use Nmap Script Engine (NSE) Scripts in Linux
  2. A Practical Guide to Nmap (Network Security Scanner) in Kali Linux
  3. Find Out All Live Hosts IP Addresses Connected on Network in Linux

DNS Lookup Utilities

14. host Command

host command is a simple utility for carrying out DNS lookups, it translates host names to IP addresses and vice versa.

$ host google.com

google.com has address 172.217.166.78
google.com mail is handled by 20 alt1.aspmx.l.google.com.
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.

15. dig Command

dig (domain information groper) is also another simple DNS lookup utility, that is used to query DNS related information such as A Record, CNAME, MX Record etc, for example:

$ dig google.com

; <<>> DiG 9.9.4-RedHat-9.9.4-51.el7 <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 23083
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 13, ADDITIONAL: 14

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;google.com.			IN	A

;; ANSWER SECTION:
google.com.		72	IN	A	172.217.166.78

;; AUTHORITY SECTION:
com.			13482	IN	NS	c.gtld-servers.net.
com.			13482	IN	NS	d.gtld-servers.net.
com.			13482	IN	NS	e.gtld-servers.net.
com.			13482	IN	NS	f.gtld-servers.net.
com.			13482	IN	NS	g.gtld-servers.net.
com.			13482	IN	NS	h.gtld-servers.net.
com.			13482	IN	NS	i.gtld-servers.net.
com.			13482	IN	NS	j.gtld-servers.net.
com.			13482	IN	NS	k.gtld-servers.net.
com.			13482	IN	NS	l.gtld-servers.net.
com.			13482	IN	NS	m.gtld-servers.net.
com.			13482	IN	NS	a.gtld-servers.net.
com.			13482	IN	NS	b.gtld-servers.net.

;; ADDITIONAL SECTION:
a.gtld-servers.net.	81883	IN	A	192.5.6.30
b.gtld-servers.net.	3999	IN	A	192.33.14.30
c.gtld-servers.net.	14876	IN	A	192.26.92.30
d.gtld-servers.net.	85172	IN	A	192.31.80.30
e.gtld-servers.net.	95861	IN	A	192.12.94.30
f.gtld-servers.net.	78471	IN	A	192.35.51.30
g.gtld-servers.net.	5217	IN	A	192.42.93.30
h.gtld-servers.net.	111531	IN	A	192.54.112.30
i.gtld-servers.net.	93017	IN	A	192.43.172.30
j.gtld-servers.net.	93542	IN	A	192.48.79.30
k.gtld-servers.net.	107218	IN	A	192.52.178.30
l.gtld-servers.net.	6280	IN	A	192.41.162.30
m.gtld-servers.net.	2689	IN	A	192.55.83.30

;; Query time: 4 msec
;; SERVER: 192.168.0.1#53(192.168.0.1)
;; WHEN: Thu Jul 12 09:30:57 BST 2018
;; MSG SIZE  rcvd: 487

16. NSLookup Command

Nslookup is also a popular command line utility to query DNS servers both interactively and non-interactively. It is used to query DNS resource records (RR). You can find out “A” record (IP address) of a domain as shown.

$ nslookup google.com

Server:		192.168.0.1
Address:	192.168.0.1#53

Non-authoritative answer:
Name:	google.com
Address: 172.217.166.78

You can also perform a reverse domain lookup as shown.

$ nslookup 216.58.208.174

Server:		192.168.0.1
Address:	192.168.0.1#53

Non-authoritative answer:
174.208.58.216.in-addr.arpa	name = lhr25s09-in-f14.1e100.net.
174.208.58.216.in-addr.arpa	name = lhr25s09-in-f174.1e100.net.

Authoritative answers can be found from:
in-addr.arpa	nameserver = e.in-addr-servers.arpa.
in-addr.arpa	nameserver = f.in-addr-servers.arpa.
in-addr.arpa	nameserver = a.in-addr-servers.arpa.
in-addr.arpa	nameserver = b.in-addr-servers.arpa.
in-addr.arpa	nameserver = c.in-addr-servers.arpa.
in-addr.arpa	nameserver = d.in-addr-servers.arpa.
a.in-addr-servers.arpa	internet address = 199.180.182.53
b.in-addr-servers.arpa	internet address = 199.253.183.183
c.in-addr-servers.arpa	internet address = 196.216.169.10
d.in-addr-servers.arpa	internet address = 200.10.60.53
e.in-addr-servers.arpa	internet address = 203.119.86.101
f.in-addr-servers.arpa	internet address = 193.0.9.1

Linux Network Packet Analyzers

17. Tcpdump Command

Tcpdump is a very powerful and widely used command-line network sniffer. It is used to capture and analyze TCP/IP packets transmitted or received over a network on a specific interface.

To capture packets from a given interface, specify it using the -i option.

$ tcpdump -i eth1

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes
09:35:40.287439 IP tecmint.com.ssh > 192.168.0.103.36398: Flags [P.], seq 4152360356:4152360552, ack 306922699, win 270, options [nop,nop,TS val 2211778668 ecr 2019055], length 196
09:35:40.287655 IP 192.168.0.103.36398 > tecmint.com.ssh: Flags [.], ack 196, win 5202, options [nop,nop,TS val 2019058 ecr 2211778668], length 0
09:35:40.288269 IP tecmint.com.54899 > gateway.domain: 43760+ PTR? 103.0.168.192.in-addr.arpa. (44)
09:35:40.333763 IP gateway.domain > tecmint.com.54899: 43760 NXDomain* 0/1/0 (94)
09:35:40.335311 IP tecmint.com.52036 > gateway.domain: 44289+ PTR? 1.0.168.192.in-addr.arpa. (42)

To capture a specific number of packets, use the -c option to enter the desired number.

$ tcpdump -c 5 -i eth1

You can also capture and save packets to a file for later analysis, use the -w flag to specify the output file.

$ tcpdump -w captured.pacs -i eth1

18. Wireshark Utility

Wireshark is a popular, powerful, versatile and easy to use tool for capturing and analyzing packets in a packet-switched network, in real-time.

You can also save data it has captured to a file for later inspection. It is used by system administrators and network engineers to monitor and inspect the packets for security and troubleshooting purposes.

Read our article “10 Tips On How to Use Wireshark to Analyze Network Packets to learn more about Wireshark”.

19. Bmon Tool

bmon is a powerful, command line based network monitoring and debugging utility for Unix-like systems, it captures networking related statistics and prints them visually in a human friendly format. It is a reliable and effective real-time bandwidth monitor and rate estimator.

Read our article “bmon – A Powerful Network Bandwidth Monitoring and Debugging Tool to learn more about bmon”.

Linux Firewall Management Tools

20. Iptables Firewall

iptables is a command line tool for configuring, maintaining, and inspecting the tables IP packet filtering and NAT ruleset. It it used to set up and manage the Linux firewall (Netfilter). It allows you to list existing packet filter rules; add or delete or modify packet filter rules; list per-rule counters of the packet filter rules.

You can learn how to use Iptables for various purposes from our simple yet comprehensive guides.

  1. Basic Guide on IPTables (Linux Firewall) Tips / Commands
  2. 25 Useful IPtable Firewall Rules Every Linux Administrator Should Know
  3. How To Setup an Iptables Firewall to Enable Remote Access to Services
  4. How to Block Ping ICMP Requests to Linux Systems

21. Firewalld

Firewalld is a powerful and dynamic daemon to manage the Linux firewall (Netfilter), just like iptables. It uses “networks zones” instead of INPUT, OUTPUT and FORWARD CHAINS in iptables. On current Linux distributions such as RHEL/CentOS 7 and Fedora 21+iptables is actively being replaced by firewalld.

To get started with firewalld, consult these guides listed below:

  1. Useful ‘FirewallD’ Rules to Configure and Manage Firewall in Linux
  2. How to Configure ‘FirewallD’ in RHEL/CentOS 7 and Fedora 21
  3. How to Start/Stop and Enable/Disable FirewallD and Iptables Firewall in Linux
  4. Setting Up Samba and Configure FirewallD and SELinux to Allow File Sharing on Linux/Windows

ImportantIptables is still supported and can be installed with YUM package manager. However, you can’t use Firewalld and iptables at the same time on same server – you must choose one.

22. UFW (Uncomplicated Firewall)

UFW is a well known and default firewall configuration tool on Debian and Ubuntu Linux distributions. It is used top enable/disable system firewall, add/delete/modify/reset packet filtering rules and much more.

To check UFW firewall status, type.

$ sudo ufw status

If UFW firewall is not active, you can activate or enable it using the following command.

$ sudo ufw enable

To disable UFW firewall, use the following command.

$ sudo ufw disable 

Read our article “How to Setup UFW Firewall on Ubuntu and Debian” to learn more UFW).

If you want to find more information about a particular program, you can consult its man pages as shown.

$ man programs_name

That’s all for now! In this comprehensive guide, we reviewed some of the most used command-line tools and utilities for network management in Linux, under different categories, for system administrators, and equally useful to full-time network administrators/engineers.

You can share your thoughts about this guide via the comment form below. If we have missed any frequently used and important Linux networking tools/utilities or any useful related information, also let us know.

Source

Understanding Shared Libraries in Linux

In programming, a library is an assortment of pre-compiled pieces of code that can be reused in a program. Libraries simplify life for programmers, in that they provide reusable functions, routines, classes, data structures and so on (written by a another programmer), which they can use in their programs.

For instance, if you are building an application that needs to perform math operations, you don’t have to create a new math function for that, you can simply use existing functions in libraries for that programming language.

Examples of libraries in Linux include libc (the standard C library) or glibc (GNU version of the standard C library), libcurl (multiprotocol file transfer library), libcrypt (library used for encryption, hashing, and encoding in C) and many more.

Linux supports two classes of libraries, namely:

  • Static libraries – are bound to a program statically at compile time.
  • Dynamic or shared libraries – are loaded when a program is launched and loaded into memory and binding occurs at run time.

Dynamic or shared libraries can further be categorized into:

  • Dynamically linked libraries – here a program is linked with the shared library and the kernel loads the library (in case it’s not in memory) upon execution.
  • Dynamically loaded libraries – the program takes full control by calling functions with the library.

Shared Library Naming Conventions

Shared libraries are named in two ways: the library name (a.k.a soname) and a “filename” (absolute path to file which stores library code).

For example, the soname for libc is libc.so.6: where lib is the prefix, c is a descriptive name, so means shared object, and 6 is the version. And its filename is: /lib64/libc.so.6. Note that the soname is actually a symbolic link to the filename.

Locating Shared Libraries in Linux

Shared libraries are loaded by ld.so (or ld.so.x) and ld-linux.so (or ld-linux.so.x) programs, where x is the version. In Linux, /lib/ld-linux.so.x searches and loads all shared libraries used by a program.

A program can call a library using its library name or filename, and a library path stores directories where libraries can be found in the filesystem. By default, libraries are located in /usr/local/lib/usr/local/lib64/usr/lib and /usr/lib64; system startup libraries are in /lib and /lib64. Programmers can, however, install libraries in custom locations.

The library path can be defined in /etc/ld.so.conf file which you can edit with a command line editor.

# vi /etc/ld.so.conf 

The line(s) in this file instruct the kernel to load file in /etc/ld.so.conf.d. This way, package maintainers or programmers can add their custom library directories to the search list.

If you look into the /etc/ld.so.conf.d directory, you’ll see .conf files for some common packages (kernel, mysql and postgresql in this case):

# ls /etc/ld.so.conf.d

kernel-2.6.32-358.18.1.el6.x86_64.conf  kernel-2.6.32-696.1.1.el6.x86_64.conf  mariadb-x86_64.conf
kernel-2.6.32-642.6.2.el6.x86_64.conf   kernel-2.6.32-696.6.3.el6.x86_64.conf  postgresql-pgdg-libs.conf

If you take a look at the mariadb-x86_64.conf, you will see an absolute path to package’s libraries.

# cat mariadb-x86_64.conf

/usr/lib64/mysql

The method above sets the library path permanently. To set it temporarily, use the LD_LIBRARY_PATHenvironment variable on the command line. If you want to keep the changes permanent, then add this line in the shell initialization file /etc/profile (global) or ~/.profile (user specific).

# export LD_LIBRARY_PATH=/path/to/library/file

Managing Shared Libraries in Linux

Let us now look at how to deal with shared libraries. To get a list of all shared library dependencies for a binary file, you can use the ldd utility. The output of ldd is in the form:

library name =>  filename (some hexadecimal value)
OR
filename (some hexadecimal value)  #this is shown when library name can’t be read

This command shows all shared library dependencies for the ls command.

# ldd /usr/bin/ls
OR
# ldd /bin/ls
Sample Output
	linux-vdso.so.1 =>  (0x00007ffebf9c2000)
	libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003b71e00000)
	librt.so.1 => /lib64/librt.so.1 (0x0000003b71600000)
	libcap.so.2 => /lib64/libcap.so.2 (0x0000003b76a00000)
	libacl.so.1 => /lib64/libacl.so.1 (0x0000003b75e00000)
	libc.so.6 => /lib64/libc.so.6 (0x0000003b70600000)
	libdl.so.2 => /lib64/libdl.so.2 (0x0000003b70a00000)
	/lib64/ld-linux-x86-64.so.2 (0x0000561abfc09000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003b70e00000)
	libattr.so.1 => /lib64/libattr.so.1 (0x0000003b75600000)

Because shared libraries can exist in many different directories, searching through all of these directories when a program is launched would be greatly inefficient: which is one of the likely disadvantages of dynamic libraries. Therefore a mechanism of caching employed, performed by a the program ldconfig.

By default, ldconfig reads the content of /etc/ld.so.conf, creates the appropriate symbolic links in the dynamic link directories, and then writes a cache to /etc/ld.so.cache which is then easily used by other programs.

This is very important especially when you have just installed new shared libraries or created your own, or created new library directories. You need to run ldconfig command to effect the changes.

# ldconfig
OR
# ldconfig -v 	#shows files and directories it works with

After creating your shared library, you need to install it. You can either move it into any of the standard directories mentioned above, and run the ldconfig command.

Alternatively, run the following command to create symbolic links from the soname to the filename:

# ldconfig -n /path/to/your/shared/libraries

To get started with creating your own libraries, check out this guide from The Linux Documentation Project(TLDP).

Thats all for now! In this article, we gave you an introduction to libraries, explained shared libraries and how to manage them in Linux. If you have any queries or additional ideas to share, use the comment form below.

Source

How to Find and Remove Duplicate/Unwanted Files in Linux Using ‘FSlint’ Tool

Very recently I have written a post on fdupes utility which is used to find and replace duplicate files in Linux. This post was very much liked by our readers. If you have not gone through the fdupes utility post, you may like to go through it here:

  1. fdupes Tool to Find and Delete Duplicate Files

This post aims at throwing light on what is fslint, its features, installation and usages.

Find and Delete Duplicate Files in Linux

FSlint – Find and Delete Duplicate Files in Linux

What is fslint?

fslint is a Linux utility to remove unwanted and problematic cruft in files and file names and thus keeps the computer clean. A large volume of unnecessary and unwanted files are called lint. fslint remove such unwanted lint from files and file names. Fslint help fight against unwanted files by coping with duplicate files, empty directories and improper names.

Features of fslint

  1. It is a combination of different tools that look after duplicate files, empty directories and improper name.
  2. Simple GTK+ Graphic front-end as well as command-line.
  3. Fslint cope with lint that relates to Duplicate files, Problematic filenames, Temporary files, Bad Symlinks, Empty directories and Non-stripped binaries.
  4. Help you in reclaiming disk space that were used by unnecessary and unwanted files.

Install fslint on a Linux

Installation of latest version of fslint package can be installed as easy as executing following command on Debian based systems such as Ubuntu and Linux Mint.

$ sudo apt-get install fslint

On CentOS/RHEL based distributions, you need to active epel repository to install fslint package.

# yum install  fslint
# dnf install  fslint    [On Fedora 22 onwards]

How do I use fslint Command?

Hope you know one of the basic rule of computation and understand the risk – have backup. Before you start testing this application make sure you have backup of everything on your system, so that even if an important file gets deleted you may restore almost immediately.

Now as you know that fslint is one such application that has a command-line interface as well as a front-end GUI at the same time. You may use either.

For developers and administrators, CLI version is preferred as it gives you immense power. GUI front-end is best suited to newbies and those who prefer GUI over CLI.

fslint Command Line Usage

The command line version of fslint is not on the path of most of the Linux users. You may access it at the location /usr/share/fslint/.

$ ./usr/share/fslint/fslint/fslint
Sample Output
-----------------------------------file name lint
./.config/google-chrome/Default/Pepper\ Data/Shockwave\ Flash/WritableRoot/#SharedObjects/NNPAG57S/videos.bhaskar.com/[[IMPORT]]
./Documents/.~lock.fslint\ -\ Remove\ duplicate\ files\ with\ fslint\ (230).odt#
./Documents/7\ Best\ Audio\ Player\ Plugins\ for\ WordPress\ (220).odt
./Documents/7\ Best\ WordPress\ Help\ Desk\ Plugins\ for\ Customer\ Support\ (219).odt
./Documents/A\ Linux\ User\ using\ Windows\ (Windows\ 10)\ after\ more\ than\ 8\ years(229).odt
./Documents/Add\ PayPal\ to\ WordPress(211).odt
./Documents/Atom\ Text\ Editor\ (202).odt
./Documents/Create\ Mailchimp\ account\ and\ Integrate\ it\ with\ WordPress(227).odt
./Documents/Export\ Feedburner\ feed\ and\ Import\ it\ to\ Mailchimp\ &\ setup\ RSS\ Feed\ Newsletter\ in\ Mailchimp(228).odt

----------------------------------DUPlicate files
Job 7, “/usr/share/fslint/fslint/fslint” has stopped

Important: Two things you should be kept in mind at this point. First fslint don’t delete any file on its own, It just shows you the lint files, their location and their name. You have to decide what to do with them. Second is fslint by default start searching from your ‘/home’ directory.

To search a different other than your /home directory, you must pass the directory name with the command, as:

$ /usr/share/fslint/fslint/fslint /home/avi/Pictures

Find Duplicate Files in Linux

Find Duplicate Files

To search recursively to all the sub-folders, you should use flag ‘-r’, simply as:

$ /usr/share/fslint/fslint/fslint -r /home/avi/Music/

Find Duplicate Files Recursively

Find Duplicate Files Recursively

fslint GUI Usage

You may fire the GUI Application built on top of fslint by typing fslint from Linux terminal or from the Application Menu.

$ fslint-gui

fslint Gui Tool

fslint Gui Tool

Everything in GUI is simple to understand. All you need to do is:

  1. Add/remove the directories to scan.
  2. Select to scan recursively or not by checking/unchecking checkbox on the top-right.
  3. Click on ‘Find’. And all done!

Again you should remember, this utility do not delete the lint files but provide you with the information only and leaves everything on you.

Conclusion

fslint is a perfect tool that remove lint of various types from a file system. Though it needs improvement in certain gray areas: –

  1. A bit slow for duplicate photo detection.
  2. Requires some improvement in User Interface.
  3. No Progress meter.

Hope you liked the post. If yes! Be audible. Post your valuable feedback in the comments below. Stay tuned and connected to Tecmint while I am working on another post you will love to read. Like and share us and help us get spread.

Source

WP2Social Auto Publish Powered By : XYZScripts.com