8 Useful Commands to Monitor Swap Space Usage in Linux

Memory management is an essential aspect of every System Administrator to improve the performance of a Linux system. It is always a good practice to monitor swap space usage in Linux to ensure that your system operates relative to its memory demands.

Check Linux Swap Space Usage

8 Commands to Check Linux Swap Space Usage

Therefore in this article we are going to look at ways to monitor swap space usage in a Linux systems.

What is Swap space?

Swap space is a restricted amount of physical memory that is allocated for use by the operating system when available memory has been fully utilized. It is memory management that involves swapping sections of memory to and from physical storage.

On most distributions of Linux, it is recommended that you set swap space when installing the operating system. The amount of swap space you can set for your Linux system may depend on the architecture and kernel version.

How do I check Swap space usage in Linux?

We shall look at different commands and tools that can help you to monitor your swap space usage in your Linux systems as follows:

1. Using the swapon Command

This command helps you to specify the devices on which paging and swapping will be done and we shall look at few important options.

To view all devices marked as swap in the /etc/fstab file you can use the --all option. Though devices that are already working as swap space are skipped.

# swapon --all

If you want to view a summary of swap space usage by device, use the --summary option as follows.

# swapon --summary

Filename				Type		Size	Used	Priority
/dev/sda10                              partition	8282108	0	-1

Use --help option to view help information or open the manpage for more usage options.

2. Using /proc/swaps which is equivalent to swapon

The /proc filesystem is a very special virtual filesystem in Linux. It is also referred to as a process information pseudo-file system.

It actually does not contain ‘real’ files but runtime system information, for example system memory, devices mounted, hardware configuration and many more. Therefore you can also refer to it as a control and information base for the kernel.

To understand more about this filesystem read our article: Understanding /proc File System in Linux.

To check swap usage information, you can view the /proc/swaps file using the cat utility.

# cat /proc/swaps

Filename				Type		Size	Used	Priority
/dev/sda10                              partition	8282108	0	-1

3. Using ‘free’ Command

The free command is used to display the amount of free and used system memory. Using the free command with -h option, which displays output in a human readable format.

# free -h

             total       used       free     shared    buffers     cached
Mem:          7.7G       4.7G       3.0G       408M       182M       1.8G
-/+ buffers/cache:       2.7G       5.0G
Swap:         7.9G         0B       7.9G

From the output above, you can see that the last line provides information about the system swap space. For more usage and examples of free command can be found at: 10 free Command to Check Memory Usage in Linux.

4. Using top Command

The top command displays processor activity of your Linux system, tasks managed by kernel in real-time. To understand how the top command works, read this article: 12 top Commands to Check Linux Process Activity

To check swap space usage with the help of ‘top’ command run the following command.

# top

Check Swap Space Using Top Command

Check Swap Space Using Top Command

5. Using atop Command

The atop command is a system monitor that reports about activities of various processes. But importantly it also shows information about free and used memory space.

# atop

Atop Check Swap Usage

Atop Check Swap Usage

To know more about how to install and use atop command in Linux, read this article: Monitor Logging Activity of Linux System Processes

6. Using htop Command

The htop command is used to view processes in an interactive mode and also displays information about memory usage.

# htop

Htop Check Swap Usage

Htop Check Swap Usage

For more information regarding installation and usage about htop command, read this article: Htop – Interactive Linux Process Monitoring

7. Using the Glances Command

This is a cross-platform system monitoring tool that displays information about running processes, cpu load, storage space usage, memory usage, swap space usage and many more.

# glances

Glances Check Swap Usage

Glances Check Swap Usage

For more information regarding installation and usage about glances command, read this article: Glances – An Advanced Real Time Linux System Monitoring Tool

8. Using the vmstat Command

This command is used to display information about virtual memory statistics. To install vmstat on your Linux system, you can read the article below and see more usage examples:

Linux Performance Monitoring with Vmstat

# vmstat

VmStat Check Swap Usage

VmStat Check Swap Usage

You need to take note of the following in the swap field from the output of this command.

  1. si: Amount of memory swapped in from disk (s).
  2. so: Amount of memory swapped to disk (s).

Summary

These are easy methods one can use and follow to monitor swap space usage and hope this article was helpful. In case you need help or want to add any information relating to memory management in Linux systems, please post a comment.

Source

5 Best Command Line Archive Tools for Linux

In our day-to-day life we come across, archived files on the platforms of all kind be it WindowsMac or Linux. There are several Application program available for all of the platforms to create archive files as well as uncompress them. When it comes to work on Linux Platform, we need to deal with archived files very frequently.

Linux Command Line Archive Tools

Linux Command Line Archive Tools

Here in this article we will be discussing archive tools available on standard Linux Distribution, their features, Examples, etc. The article divided into two parts, each part contains five command line archive tools (i.e. total of 10 Best Command Line Archive Tools).

What is Archived file?

An archive file is a compressed file which is composed of one or more than one computer files along with metadata.

Features of Archiving

  1. Data Compression
  2. Encryption
  3. File Concatenation
  4. Automatic Extraction
  5. Automatic Installation
  6. Source Volume and Media Information
  7. File Spanning
  8. Checksum
  9. Directory Structure Information
  10. Other Metadata (Data About Data)
  11. Error discovery

Area of Application

  1. Store Computer Files System along with Metadata.
  2. Useful in transferring file locally.
  3. Useful in transferring file over web.
  4. Software Packaging Application.

The useful archiving application on standard Linux distribution follows:

1. tar Command

tar is the standard UNIX/Linux archiving application tool. In its early stage it used to be a Tape Archiving Program which gradually is developed into General Purpose archiving package which is capable of handling archive files of every kind. tar accepts a lot of archiving filter with options.

tar options

  1. -A : Append tar files to existing archives.
  2. -c : Create a new archive file.
  3. -d : Compare archive with Specified filesystem.
  4. -j : bzip the archive
  5. -r : append files to existing archives.
  6. -t : list contents of existing archives.
  7. -u : Update archive
  8. -x : Extract file from existing archive.
  9. -z : gzip the archive
  10. –delete : Delete files from existing archive.
tar Examples

Create a tar archive file.

# tar -zcvf name_of_tar.tar.gz /path/to/folder

Decompress an tar archive file.

# tar -zxvf Name_of_tar_file.tar.gz

For more detailed examples, read 18 Tar Command Examples in Linux.

shar Command

shar which stands for Shell archive is a shell script, the execution of which will create the files. shar is a self-extracting archive file which is a legacy utility and needs Unix Bourne Shell to extract the files. shar has an advantage of being plain text however it is potentially dangerous, since it outputs an executable.

shar options

  1. -o : Save output to archive files as specified, in the option.
  2. -l : Limit the output size, as specified, in the option but do not split it.
  3. -L : Limit the output size, as specified, in the option and split it.
  4. -n : Name of Archive to be included in the header of the shar files.
  5. -a : Allow automatic generation of headers.

Note: The ‘-o‘ option is required if the ‘-l‘ or ‘-L‘ option is used and the ‘-n‘ option is required if the ‘-a‘ option is used.

shar Examples

Create a shar archive file.

# shar file_name.extension > filename.shar

Extract an shar archive file.

# unshar file_name.shar

3. ar Command

ar is the creation and manipulation utility for archives, mainly used for binary object file libraries. ar stands for archiver which can be used to create archive of any kind for any purpose but has largely been replaced by ‘tar’ and now-a-days it is used only to create and update static library files.

ar options

  1. -d : Delete modules from the archive.
  2. -m : Move Members in the archive.
  3. -p : Print specified members of the archive.
  4. -q : Quick Append.
  5. -r : Insert file member to archive.
  6. -s : Add index to archive.
  7. -a : Add a new file to the existing members of archive.
ar Examples

Create an archive using ‘ar‘ tool with a static library say ‘libmath.a‘ with the objective files ‘substraction’ and ‘division’ as.

# ar cr libmath.a substraction.o division.o

To extract an ‘ar’ archive file.

# ar x libmath.a

4. cpio

cpio stands for Copy in and out. Cpio is a general purpose file archiver for Linux. It is actively used by RedHatPackage Manager (RPM) and in the initramfs of Linux Kernel as well as an important archiving tool in Apple Computer’s Installer (pax).

cpio options

  1. -0 : Read a list of filenames terminated by a null character instead of a newline.
  2. -a : Reset Access time.
  3. -A : Append.
  4. -b : swap.
  5. -d : Make Directories.
cpio Examples

Create an ‘cpio’ archive file.

# cd tecmint
# ls

file1.o file2.o file3.o

# ls | cpio  -ov > /path/to/output_folder/obj.cpio

To extract a cpio archive file.

# cpio -idv < /path/to folder/obj.cpio

5. Gzip

gzip is standard and widely used file compression and decompression utility. Gzip allows file concatenation. Compressing the file with gzip, outputs the tarball which is in the format of ‘*.tar.gz‘ or ‘*.tgz‘.

gzip options

  1. –stdout : Produce output on standard output.
  2. –to-stdout : Produce output on standard output.
  3. –decompress : Decompress File.
  4. –uncompress : Decompress File.
  5. -d : Decompress File.
  6. -f : Force Compression/Decompression.
gzip Examples

Create an ‘gzip’ archive file.

# tar -cvzf name_of_archive.tar.gz /path/to/folder

To extract a ‘gzip’ archive file.

# gunzip file_name.tar.gz

The above command must be passed followed with below command.

# tar -xvf file_name.tar

Note: The architecture and functionality of ‘gzip’ makes it difficult to recover corrupted ‘gzipped tar archive’ file. It is advised to make several backups of gzipped Important files, at different Locations.

That’s all for now.

Source

How to Control Systemd Services on Remote Linux Server

Systemd system and services manager can be controlled using the systemctl command line utility. It enables you to manage systemd locally or on a remote Linux machine over the SSH protocol.

In this short article, we will show you how to manage systemd system and service manager on a remote Linux machine over a SSH session.

Attention: We recommend using public/private key pairs for passwordless authentication for SSH, as opposed to passwords, and also employing additional methods to secure SSH service, as explained in these guides.

  1. SSH Passwordless Login Using SSH Keygen in 5 Easy Steps
  2. 5 Best Practices to Secure and Protect SSH Server
  3. How to Block SSH and FTP Access to Specific IP and Network Range

To connect to a remote server, run systemctl with the --host or -H flag as follows. In the command below, we are connecting to the remote server as the root user and status is a subcommand of systemctl utility used to view the status of the httpd service on centos.temint.lan (remote Linux server).

$ systemctl --host root@centos.temint.lan status httpd.service
OR
$ systemctl -H root@centos.temint.lan status httpd.service

Manage Systemd Service on Remote Linux

Manage Systemd Service on Remote Linux

Similarly, you can also start, stop or restart remote systemd service as shown.

$ systemctl --host root@centos.temint.lan start httpd.service   
$ systemctl --host root@centos.temint.lan stop httpd.service
$ systemctl --host root@centos.temint.lan restart httpd.service

To end the session, simply type [Ctrl+C]. For more information and usage options, see the systemctl man page:

$ man systemctl 

That’s all for now! What follows is an assortment of systemd articles which you’ll find useful:

  1. The Story Behind: Why ‘init’ Needed to be Replaced with ‘systemd’ in Linux
  2. Managing System Startup Process and Services (SysVinit, Systemd and Upstart)
  3. Manage Log Messages Under Systemd Using Journalctl [Comprehensive Guide]
  4. How to Create and Run New Service Units in Systemd Using Shell Script
  5. How to Change Runlevels (targets) in SystemD

In this article, we showed you how to manage systemd system and service manager on a remote Linux machine. Use the feedback section to ask questions or share your thoughts about this guide.

Source

Rename – A Command Line Tool For Renaming Multiple Files in Linux

We often use “mv” command to rename a single file in Linux. However, renaming multiple or group of files quickly makes it very difficult task in a terminal.

Linux comes with a very powerful built-in tool called rename. The rename command is used to rename multiple or group of files, rename files to lowercase, rename files to uppercase and overwrite files using perl expressions.

Rename Multiple Files In Linux

The “rename” command is a part of Perl script and it resides under “/usr/bin/” on many Linux distributions. You can run “which” command to find out the location of rename command.

$ which rename
/usr/bin/rename
The Basic Syntax of Rename Command
rename 's/old-name/new-name/' files

The rename command comes with few optional arguments along with mandatory perl expression that guides rename command to do actual work.

rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]
  1. -v: Print names of files successfully renamed.
  2. -n: Show what files would have been renamed.
  3. -f: Force overwrite existing files.
  4. perlexpr: Perl Expression.

For better understanding of this utility, we’ve discussed few practical examples of this command in the article.

1. A Basic Rename Command Example

Suppose you’ve bunch of files with “.html” extension and you want to rename all “.html” files to “.php” at one go. For example, first do a “ls -l” to check the list of files with “.html” extension.

# ravisaive@tecmint:~$ ls -l
total 22532
-rw-rw-r-- 1 ravisaive ravisaive 6888896 Oct 10 12:10 cricket.html
-rw-rw-r-- 1 ravisaive ravisaive  588895 Oct 10 12:10 entertainment.html
-rw-rw-r-- 1 ravisaive ravisaive 6188895 Oct 10 12:10 health.html
-rw-rw-r-- 1 ravisaive ravisaive 6538895 Oct 10 12:10 lifestyle.html
-rw-rw-r-- 1 ravisaive ravisaive  938895 Oct 10 12:10 news.html
-rw-rw-r-- 1 ravisaive ravisaive  938937 Oct 10 12:11 photos.html
-rw-rw-r-- 1 ravisaive ravisaive  978137 Oct 10 12:11 sports.html

Now, you want to change the extension of all these files from “.html” to “.php“. You can use the following “rename” command with perl expression as shown below.

ravisaive@tecmint:~$ rename 's/\.html$/\.php/' *.html

Note: In the above command we’ve used two arguments.

  1. First argument is a perl expression that substitute .html with .php.
  2. Second argument tells the rename command to substitute all the files with *.php.

Let’s verify whether all files are renamed to “.php” extension, doing ls -l on the prompt.

ravisaive@tecmint:~$ ls -l
total 22532
-rw-rw-r-- 1 ravisaive ravisaive 6888896 Oct 10 12:10 cricket.php
-rw-rw-r-- 1 ravisaive ravisaive  588895 Oct 10 12:10 entertainment.php
-rw-rw-r-- 1 ravisaive ravisaive 6188895 Oct 10 12:10 health.php
-rw-rw-r-- 1 ravisaive ravisaive 6538895 Oct 10 12:10 lifestyle.php
-rw-rw-r-- 1 ravisaive ravisaive  938895 Oct 10 12:10 news.php
-rw-rw-r-- 1 ravisaive ravisaive  938937 Oct 10 12:11 photos.php
-rw-rw-r-- 1 ravisaive ravisaive  978137 Oct 10 12:11 sports.php

Now you can see above that all the html files are renamed to php.

2. Check Changes Before Running Rename Command

While doing critical or major renaming tasks, you can always check the changes by running rename command with “-n” argument. The “-n” parameter will tell you exactly what changes would take place, but the changes are not done for real. Here, is the example of the command below.

ravisaive@tecmint:~$ rename -n 's/\.php$/\.html/' *.php

cricket.php renamed as cricket.html
entertainment.php renamed as entertainment.html
health.php renamed as health.html
lifestyle.php renamed as lifestyle.html
news.php renamed as news.html
photos.php renamed as photos.html
sports.php renamed as sports.html

Note: The above command output only displays changes, but in real the changes are not done, unless you run the command without “-n” switch.

3. Print Rename Output

We saw that the rename command didn’t displayed any information of changes it does. So, if you want to get the details of rename command (like we did using “-n” option), here we use “-v” option to print the complete details of all the changes done by rename command successfully.

ravisaive@tecmint:~$ rename -v 's/\.php$/\.html/' *.php

cricket.php renamed as cricket.html
entertainment.php renamed as entertainment.html
health.php renamed as health.html
lifestyle.php renamed as lifestyle.html
news.php renamed as news.html
photos.php renamed as photos.html
sports.php renamed as sports.html

4. Convert all Lowercase to Uppercase and Vise-Versa

To batch rename all files with lower case names to upper case. For example, I want to covert all these following files from lower to upper case.

Lower to Upper Case
ravisaive@tecmint:~$ ls -l
total 22532
-rw-rw-r-- 1 ravisaive ravisaive 6888896 Oct 10 12:10 cricket.html
-rw-rw-r-- 1 ravisaive ravisaive  588895 Oct 10 12:10 entertainment.html
-rw-rw-r-- 1 ravisaive ravisaive 6188895 Oct 10 12:10 health.html
-rw-rw-r-- 1 ravisaive ravisaive 6538895 Oct 10 12:10 lifestyle.html
-rw-rw-r-- 1 ravisaive ravisaive  938895 Oct 10 12:10 news.html
-rw-rw-r-- 1 ravisaive ravisaive  938937 Oct 10 12:11 photos.html
-rw-rw-r-- 1 ravisaive ravisaive  978137 Oct 10 12:11 sports.html

Just, use the following command with perl expression.

ravisaive@tecmint:~$ rename 'y/a-z/A-Z/' *.html

Once you’ve executed the above command, you can check the changes by doing “ls -l“.

ravisaive@tecmint:~$ ls -l
total 22532
-rw-rw-r-- 1 ravisaive ravisaive 6888896 Oct 10 12:10 CRICKET.HTML
-rw-rw-r-- 1 ravisaive ravisaive  588895 Oct 10 12:10 ENTERTAINMENT.HTML
-rw-rw-r-- 1 ravisaive ravisaive 6188895 Oct 10 12:10 HEALTH.HTML
-rw-rw-r-- 1 ravisaive ravisaive 6538895 Oct 10 12:10 LIFESTYLE.HTML
-rw-rw-r-- 1 ravisaive ravisaive  938895 Oct 10 12:10 NEWS.HTML
-rw-rw-r-- 1 ravisaive ravisaive  938937 Oct 10 12:11 PHOTOS.HTML
-rw-rw-r-- 1 ravisaive ravisaive  978137 Oct 10 12:11 SPORTS.HTML

You can see that the above command actually renamed all the lower case file names (with .HTML extension) to upper case.

Upper to Lower Case

Similarly, you can also convert all upper case characters to lower case using the following command.

ravisaive@tecmint:~$ rename 'y/A-Z/a-z/' *.HTML
ravisaive@tecmint:~$ ls -l
total 22532
-rw-rw-r-- 1 ravisaive ravisaive 6888896 Oct 10 12:10 cricket.html
-rw-rw-r-- 1 ravisaive ravisaive  588895 Oct 10 12:10 entertainment.html
-rw-rw-r-- 1 ravisaive ravisaive 6188895 Oct 10 12:10 health.html
-rw-rw-r-- 1 ravisaive ravisaive 6538895 Oct 10 12:10 lifestyle.html
-rw-rw-r-- 1 ravisaive ravisaive  938895 Oct 10 12:10 news.html
-rw-rw-r-- 1 ravisaive ravisaive  938937 Oct 10 12:11 photos.html
-rw-rw-r-- 1 ravisaive ravisaive  978137 Oct 10 12:11 sports.html

5. Capitalize First Letter of Filename

To capitalize only first letter of each filename use the following command.

# rename 's/\b(\w)/\U$1/g' *.ext

Capitalize First Letter Filename

Capitalize First Letter Filename

6. Overwrite Existing Files

If you would like to forcefully overwrite existing files, use the “-f” option as shown below.

ravisaive@tecmint:~$ rename -f 's/a/b/' *.html

If you would like to know more about rename command, type the “man rename” in the terminal.

The rename command is very useful, if you are dealing with multiple or batch renaming of files from the command line. Do give a try and let me know, how far is useful in terms of renaming of files.

Source

3 Useful Hacks Every Linux User Must Know

The world of Linux is filled with so much fun and interesting stuffs, the more we go in, the more we find stuffs. In our efforts to bring those little hacks and tips for you that makes you different from others, here we have came up with three little tricks.

1. How to Schedule a Linux Job Without Cron

Scheduling a job/command in Linux is acronym to cron. Whenever we need to schedule a job, we call cron, but do you know we can schedule a job at a later time without corn? You can do it as suggested below..

Run a command (say date) every 5 sec and write the output to a file (say date.txt). To achieve this scenario, we need to run the below one liner script directly on the command prompt.

$ while true; do date >> date.txt ; sleep 5 ; done &

Anatomy of the above one liner script:

  1. while true – Ask script to run while the condition is true, it acts as a loop which makes the command to run again-and-again or say in a loop.
  2. do – do perform what follows, ie., execute command or set of commands that lies ahead of do statement.
  3. date >> date.txt – here the output of date command is being written to a file date.txt. Also note that we have used >> and not >.
  4. >> ensures that the file (date.txt) is not overwritten every time the script execute. It just append the changes. Whereas > overwrite the file again and again.
  5. sleep 5 – It ask the shell to keep a time difference of 5 seconds before it executed again. Note the time here is always measured in seconds. Say if you want to execute the command every 6 minutes, you should use (6*60) 360, in succession of sleep.
  6. done – marks the end of while loop.
  7. & – Put the whole process in loop to background.

Similarly, we can execute any script in the same manner. Here is the command to call a script after certain interval (say 100 sec) and the name of script is script_name.sh.

Also worth mentioning that the script above should be run in the directory where the script to be called lies, else you need to provide full path (/home/$USER/…/script_name.sh). The syntax for calling script at above described interval is:

$ while true; do /bin/sh script_name.sh ; sleep 100 ; done &

Conclusion: The above one liner is not a replacement of Cron, because Cron utility supports a whole lots of options, as compared and is very flexible as well as customizable. However if we want to run certain test cases or I/O benchmark, then the above singe command will serve the purpose.

Read Also: 11 Linux Cron Job Scheduling Examples

2. How to Clear Terminal without Using ‘clear’ Command

What we do to clear the screen? Well you may think how silly it is to ask such question. Well, we all know it’s ‘clear‘ command. However if we make a habit of using key combination ‘ctrl+l‘ to clear terminal, we will save a lot of time of ours.

Key combination ‘Ctrl+l‘ has the same effect as ‘clear‘ command. So from next time use ctrl+l to clear your Linux Command Line Interface.

Conclusion: Since ctrl+l is a key combination, so we can not use it inside a script. If we need to clear screen inside a shell script, call command ‘clear’, for all other cases I could think of now, ctrl+l is more than sufficient.

3. Run a command and come back to the current working directory automatically.

Well this is an amazing hack not many people know. You may run a command no matter what it return back to the current directory. All you need to do is to run the command in parentheses i.e., in between ( and ).

Let see the example,

avi@deb:~$ (cd /home/avi/Downloads/)
Sample Output
avi@deb:~

First it cd to directory Downloads and then again return back to home directory in one go. May be you believe that the command didn’t executed and for some reason one or another it is not throwing error, since there is no change in prompt. Lets do a little more tweak..

avi@deb:~$ (cd /home/avi/Downloads/ && ls -l)
Sample Output
-rw-r-----  1 avi  avi     54272 May  3 18:37 text1.txt
-rw-r-----  1 avi  avi     54272 May  3 18:37 text2.txt
-rw-r-----  1 avi  avi     54272 May  3 18:37 text3.txt
avi@deb:~$

So in the above command it first changed the current directory to Downloads and then list the content of that directory before returning back to current directory. Also, it proves that command executed successfully. You may run any sort of command in the parentheses and return back to your current working directory without a hitch.

That’s all for now, if you know any such Linux hacks or tricks you may share with us via our comment section and don’t forget to share this article with your friends….

Source

Ntfy – Get Desktop or Phone Alerts When Long Running Command Finishes

Ntfy is a simple yet serviceable cross-platform Python utility that enables you to automatically get desktop notifications on demand or when long running commands complete. It can as well send push notifications to your phone once a particular command completes.

It supports shell integration with popular Linux shells such as bash and zsh; by default, ntfy will only send notifications for commands lasting longer than 10 seconds and if the terminal is focused. It also offers features for process, emjoi, XMPP, Telegram, Instapush and Slack notification support.

Check out the following video that demonstrates some of ntfy functionality:

In this article, we’ll show you how to install, configure and use ntfy in the mainstream Linux distributions to get desktop or phone notifications when long running commands finishes.

Step 1: How to Install Ntfy in Linux

Ntfy package can be installed using Python Pip as follows.

$ sudo pip install ntfy

Once ntfy installed, it can be configured using a YAML file located in ~/.ntfy.yml or in standard platform specific locations, ~/config/ntfy/ntfy.yml on Linux.

It operates via dbus, and works on most if not all popular Linux desktop environments such as Gnome, KDE, XFCE and with libnotify. Make sure you have required dependencies installed before using it as shown.

$ sudo apt-get install libdbus-glib-1-dev libdbus-1-dev [On Debian/Ubuntu]
$ sudo yum install dbus-1-glib-devel libdbus-1-devel    [On Fedora/CentOS]
$ pip install --user dbus-python

Step 2: Integrate Ntfy with Linux Shells

ntfy offers support for spontaneously sending notifications once long running commands complete in bash and zsh. In bash, it reproduces the function of zsh’s preexec and precmd functionality using rcaloras/bash-preexec.

You can enable it in your .bashrc or .zshrc file as below:

eval  "$(ntfy shell-integration)"

After integrating it with the shell, nfty will send notifications on your desktop for any commands lasting longer than 10 seconds provided the terminal is focused, this is the default setting.

Note that terminal focus works on X11 and with Terminal.app. You can configure it via the --longer-than and --foreground-too flags.

Ignore Unnecessary Notifications

Imaginably, you can do away with unnecessary notifications when running interactive programs, this can be configured using the AUTO_NTFY_DONE_IGNORE env variable.

For instance, using the export command below, you will prevent the command “vim screen meld” from generating notifications:

$ export AUTO_NTFY_DONE_IGNORE="vim screen meld"

Step 3: How to Use Nfty in Linux

Once you have installed and configured ntfy, you can test it with a these examples:

$ ntfy send "This is TecMint, we’re testing ntfy"

Ntfy Send Notification

Ntfy Send Notification

The example below shows how to run a command and send a notification when it is done:

$ ntfy done sleep 5

Ntfy Auto Send Notification

Ntfy Auto Send Notification

To use a custom notification title, set the -t flag as follows.

$ ntfy -t 'TecMint' send "Using custom notification title"

Ntfy Custom Notification Title

Ntfy Custom Notification Title

The example below will show an emoji for the particular code used.

$ ntfy send ":wink: Using emoji extra! :joy:" 

Ntfy Use Emoji in Notification

Ntfy Use Emoji in Notification

To send a notification to the desktop once a process with the specified ID completes, use the example below:

$ ntfy done --pid 2099

You can view all notifications using notification indicator, run the commands below to install recent notifications indicator.

$ sudo add-apt-repository ppa:jconti/recent-notifications
$ sudo apt update && sudo apt install indicator-notifications

When the installation completes, launch the indicator from the Unity Dash, run a few ntfy commands and click on the icon from the panel to view all notifications.

Ntfy Notifications

Ntfy Notifications

To view a help message, run:

$ ntfy -h

Step 4: Install Additional Ntfy Features

You can install additional features but this calls for extra dependencies:

ntfy done -p $PID – requires installing as ntfy[pid].

$ pip install ntfy[pid]

emjoi support – requires installing as ntfy[emoji].

$ pip install ntfy[emoji]

XMPP support – requires installing as ntfy[xmpp].

$ pip install ntfy[xmpp]

Telegram support – requires installing as ntfy[telegram].

$ pip install ntfy[telegram]

Instapush support – requires installing as ntfy[instapush].

$ pip install ntfy[instapush]

Slack support – requires installing as ntfy[slack].

$ pip install ntfy[slack]

And to install multiple extra features using a single command, separate them with commas like so:

$ pip install ntfy[pid,emjoi,xmpp, telegram]

For an exhaustive usage guide, check out: http://ntfy.readthedocs.io/en/latest/

That’s all! In this article, we showed you how to setup and use ntfy in the mainstream Linux distributions. Use the feedback form below to share your thoughts concerning this article or else share with us info about any similar Linux utilities.

Source

25 Hardening Security Tips for Linux Servers

Everybody says that Linux is secure by default and agreed to some extend (It’s debatable topics). However, Linux has in-built security model in place by default. Need to tune it up and customize as per your need which may help to make more secure system. Linux is harder to manage but offers more flexibility and configuration options.

Linux Security and Hardening Tips

25 Linux Security and Hardening Tips

Securing a system in a production from the hands of hackers and crackers is a challenging task for a System Administrator. This is our first article related to “How to Secure Linux box” or “Hardening a Linux Box“. In this post We’ll explain 25 useful tips & tricks to secure your Linux system. Hope, below tips & tricks will help you some extend to secure your system.

1. Physical System Security

Configure the BIOS to disable booting from CD/DVDExternal DevicesFloppy Drive in BIOS. Next, enable BIOSpassword & also protect GRUB with password to restrict physical access of your system.

  1. Set GRUB Password to Protect Linux Servers

2. Disk Partitions

It’s important to have different partitions to obtain higher data security in case if any disaster happens. By creating different partitions, data can be separated and grouped. When an unexpected accident occurs, only data of that partition will be damaged, while the data on other partitions survived. Make sure you must have following separate partitions and sure that third party applications should be installed on separate file systems under /opt.

/
/boot
/usr
/var
/home
/tmp
/opt

3. Minimize Packages to Minimize Vulnerability

Do you really want all sort of services installed?. It’s recommended to avoid installing useless packages to avoid vulnerabilities in packages. This may minimize risk that compromise of one service may lead to compromise of other services. Find and remove or disable unwanted services from the server to minimize vulnerability. Use the ‘chkconfig‘ command to find out services which are running on runlevel 3.

# /sbin/chkconfig --list |grep '3:on'

Once you’ve find out any unwanted service are running, disable them using the following command.

# chkconfig serviceName off

Use the RPM package manager such as “yum” or “apt-get” tools to list all installed packages on a system and remove them using the following command.

# yum -y remove package-name
# sudo apt-get remove package-name
  1. 5 chkconfig Command Examples
  2. 20 Practical Examples of RPM Commands
  3. 20 Linux YUM Commands for Linux Package Management
  4. 25 APT-GET and APT-CACHE Commands to Manage Package Management

4. Check Listening Network Ports

With the help of ‘netstat‘ networking command you can view all open ports and associated programs. As I said above use ‘chkconfig‘ command to disable all unwanted network services from the system.

# netstat -tulpn
  1. 20 Netstat Commands for Network Management in Linux

5. Use Secure Shell(SSH)

Telnet and rlogin protocols uses plain text, not encrypted format which is the security breaches. SSH is a secure protocol that use encryption technology during communication with server.

Never login directly as root unless necessary. Use “sudo” to execute commands. sudo are specified in /etc/sudoers file also can be edited with the “visudo” utility which opens in VI editor.

It’s also recommended to change default SSH 22 port number with some other higher level port number. Open the main SSH configuration file and make some following parameters to restrict users to access.

# vi /etc/ssh/sshd_config
Disable root Login
PermitRootLogin no
Only allow Specific Users
AllowUsers username
Use SSH Protocol 2 Version
Protocol 2
  1. 5 Best Practices to Secure and Protect SSH Server

6. Keep System updated

Always keep system updated with latest releases patches, security fixes and kernel when it’s available.

# yum updates
# yum check-update

7. Lockdown Cronjobs

Cron has it’s own built in feature, where it allows to specify who may, and who may not want to run jobs. This is controlled by the use of files called /etc/cron.allow and /etc/cron.deny. To lock a user using cron, simply add user names in cron.deny and to allow a user to run cron add in cron.allow file. If you would like to disable all users from using cron, add the ‘ALL‘ line to cron.deny file.

# echo ALL >>/etc/cron.deny
  1. 11 Cron Scheduling Examples in Linux

8. Disable USB stick to Detect

Many times it happens that we want to restrict users from using USB stick in systems to protect and secure data from stealing. Create a file ‘/etc/modprobe.d/no-usb‘ and adding below line will not detect USB storage.

install usb-storage /bin/true

9. Turn on SELinux

Security-Enhanced Linux (SELinux) is a compulsory access control security mechanism provided in the kernel. Disabling SELinux means removing security mechanism from the system. Think twice carefully before removing, if your system is attached to internet and accessed by the public, then think some more on it.

SELinux provides three basic modes of operation and they are.

  1. Enforcing: This is default mode which enable and enforce the SELinux security policy on the machine.
  2. Permissive: In this mode, SELinux will not enforce the security policy on the system, only warn and log actions. This mode is very useful in term of troubleshooting SELinux related issues.
  3. DisabledSELinux is turned off.

You can view current status of SELinux mode from the command line using ‘system-config-selinux‘, ‘getenforce‘ or ‘sestatus‘ commands.

# sestatus

If it is disabled, enable SELinux using the following command.

# setenforce enforcing

It also can be managed from ‘/etc/selinux/config‘ file, where you can enable or disable it.

10. Remove KDE/GNOME Desktops

There is no need to run X Window desktops like KDE or GNOME on your dedicated LAMP server. You can remove or disable them to increase security of server and performance. To disable simple open the file ‘/etc/inittab‘ and set run level to 3. If you wish to remove it completely from the system use the below command.

# yum groupremove "X Window System"

11. Turn Off IPv6

If you’re not using a IPv6 protocol, then you should disable it because most of the applications or policies not required IPv6 protocol and currently it doesn’t required on the server. Go to network configuration file and add followings lines to disable it.

# vi /etc/sysconfig/network
NETWORKING_IPV6=no
IPV6INIT=no

12. Restrict Users to Use Old Passwords

This is very useful if you want to disallow users to use same old passwords. The old password file is located at /etc/security/opasswd. This can be achieved by using PAM module.

Open ‘/etc/pam.d/system-auth‘ file under RHEL / CentOS / Fedora.

# vi /etc/pam.d/system-auth

Open ‘/etc/pam.d/common-password‘ file under Ubuntu/Debian/Linux Mint.

# vi /etc/pam.d/common-password

Add the following line to ‘auth‘ section.

auth        sufficient    pam_unix.so likeauth nullok

Add the following line to ‘password‘ section to disallow a user from re-using last 5 password of his or her.

password   sufficient    pam_unix.so nullok use_authtok md5 shadow remember=5

Only last 5 passwords are remember by server. If you tried to use any of last 5 old passwords, you will get an error like.

Password has been already used. Choose another.

13. How to Check Password Expiration of User

In Linux, user’s passwords are stored in ‘/etc/shadow‘ file in encrypted format. To check password expiration of user’s, you need to use ‘chage‘ command. It displays information of password expiration details along with last password change date. These details are used by system to decide when a user must change his/her password.

To view any existing user’s aging information such as expiry date and time, use the following command.

#chage -l username

To change password aging of any user, use the following command.

#chage -M 60 username
#chage -M 60 -m 7 -W 7 userName
Parameters
  1. -M Set maximum number of days
  2. -m Set minimum number of days
  3. -W Set the number of days of warning

14. Lock and Unlock Account Manually

The lock and unlock features are very useful, instead of removing an account from the system, you can lock it for an week or a month. To lock a specific user, you can use the follow command.

# passwd -l accountName

Note : The locked user is still available for root user only. The locking is performed by replacing encrypted password with an (!) string. If someone trying to access the system using this account, he will get an error similar to below.

# su - accountName
This account is currently not available.

To unlock or enable access to an locked account, use the command as. This will remove (!) string with encrypted password.

# passwd -u accountName

15. Enforcing Stronger Passwords

A number of users use soft or weak passwords and their password might be hacked with a dictionary based or brute-force attacks. The ‘pam_cracklib‘ module is available in PAM (Pluggable Authentication Modules) module stack which will force user to set strong passwords. Open the following file with an editor.

Read Also:

# vi /etc/pam.d/system-auth

And add line using credit parameters as (lcreditucreditdcredit and/or ocredit respectively lower-case, upper-case, digit and other)

/lib/security/$ISA/pam_cracklib.so retry=3 minlen=8 lcredit=-1 ucredit=-2 dcredit=-2 ocredit=-1

16. Enable Iptables (Firewall)

It’s highly recommended to enable Linux firewall to secure unauthorised access of your servers. Apply rules in iptables to filters incomingoutgoing and forwarding packets. We can specify the source and destination address to allow and deny in specific udp/tcp port number.

  1. Basic IPTables Guide and Tips

17. Disable Ctrl+Alt+Delete in Inittab

In most Linux distributions, pressing ‘CTRL-ALT-DELETE’ will takes your system to reboot process. So, it’s not a good idea to have this option enabled at least on production servers, if someone by mistakenly does this.

This is defined in ‘/etc/inittab‘ file, if you look closely in that file you will see a line similar to below. By default line is not commented out. We have to comment it out. This particular key sequence signalling will shut-down a system.

# Trap CTRL-ALT-DELETE
#ca::ctrlaltdel:/sbin/shutdown -t3 -r now

18. Checking Accounts for Empty Passwords

Any account having an empty password means its opened for unauthorized access to anyone on the web and it’s a part of security within a Linux server. So, you must make sure all accounts have strong passwords and no one has any authorized access. Empty password accounts are security risks and that can be easily hackable. To check if there were any accounts with empty password, use the following command.

# cat /etc/shadow | awk -F: '($2==""){print $1}'

19. Display SSH Banner Before Login

It’s always a better idea to have an legal banner or security banners with some security warnings before SSH authentication. To set such banners read the following article.

  1. Display SSH Warning Message to Users

20. Monitor User Activities

If you are dealing with lots of users, then its important to collect the information of each user activities and processes consumed by them and analyse them at a later time or in case if any kind of performance, security issues. But how we can monitor and collect user activities information.

There are two useful tools called ‘psacct‘ and ‘acct‘ are used for monitoring user activities and processes on a system. These tools runs in a system background and continuously tracks each user activity on a system and resources consumed by services such as ApacheMySQLSSHFTP, etc. For more information about installation, configuration and usage, visit the below url.

  1. Monitor User Activity with psacct or acct Commands

21. Review Logs Regularly

Move logs in dedicated log server, this may prevents intruders to easily modify local logs. Below are the Common Linux default log files name and their usage:

  1. /var/log/message – Where whole system logs or current activity logs are available.
  2. /var/log/auth.log – Authentication logs.
  3. /var/log/kern.log – Kernel logs.
  4. /var/log/cron.log – Crond logs (cron job).
  5. /var/log/maillog – Mail server logs.
  6. /var/log/boot.log – System boot log.
  7. /var/log/mysqld.log – MySQL database server log file.
  8. /var/log/secure – Authentication log.
  9. /var/log/utmp or /var/log/wtmp : Login records file.
  10. /var/log/yum.log: Yum log files.

22. Important file Backup

In a production system, it is necessary to take important files backup and keep them in safety vault, remote site or offsite for Disasters recovery.

23. NIC Bonding

There are two types of mode in NIC bonding, need to mention in bonding interface.

  1. mode=0 – Round Robin
  2. mode=1 – Active and Backup

NIC Bonding helps us to avoid single point of failure. In NIC bonding, we bond two or more Network Ethernet Cards together and make one single virtual Interface where we can assign IP address to talk with other servers. Our network will be available in case of one NIC Card is down or unavailable due to any reason.

Read Also : Create NIC Channel Bonding in Linux

24. Keep /boot as read-only

Linux kernel and its related files are in /boot directory which is by default as read-write. Changing it to read-onlyreduces the risk of unauthorized modification of critical boot files. To do this, open “/etc/fstab” file.

# vi /etc/fstab

Add the following line at the bottom, save and close it.

LABEL=/boot     /boot     ext2     defaults,ro     1 2

Please note that you need to reset the change to read-write if you need to upgrade the kernel in future.

25. Ignore ICMP or Broadcast Request

Add following line in “/etc/sysctl.conf” file to ignore ping or broadcast request.

Ignore ICMP request:
net.ipv4.icmp_echo_ignore_all = 1

Ignore Broadcast request:
net.ipv4.icmp_echo_ignore_broadcasts = 1

Load new settings or changes, by running following command

#sysctl -p

If you’ve missed any important security or hardening tip in the above list, or you’ve any other tip that needs to be included in the list. Please drop your comments in our comment box.

Source

10 Useful Sudoers Configurations for Setting ‘sudo’ in Linux

In Linux and other Unix-like operating systems, only the root user can run all commands and perform certain critical operations on the system such as install and update, remove packages, create users and groups, modify important system configuration files and so on.

However, a system administrator who assumes the role of the root user can permit other normal system users with the help of sudo command and a few configurations to run some commands as well as carry out a number of vital system operations including the ones mentioned above.

Alternatively, the system administrator can share the root user password (which is not a recommended method) so that normal system users have access to the root user account via su command.

sudo allows a permitted user to execute a command as root (or another user), as specified by the security policy:

  1. It reads and parses /etc/sudoers, looks up the invoking user and its permissions,
  2. then prompts the invoking user for a password (normally the user’s password, but it can as well be the target user’s password. Or it can be skipped with NOPASSWD tag),
  3. after that, sudo creates a child process in which it calls setuid() to switch to the target user
  4. next, it executes a shell or the command given as arguments in the child process above.

Below are ten /etc/sudoers file configurations to modify the behavior of sudo command using Defaults entries.

$ sudo cat /etc/sudoers
/etc/sudoers File
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults	env_reset
Defaults	mail_badpass
Defaults	secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Defaults	logfile="/var/log/sudo.log"
Defaults	lecture="always"
Defaults	badpass_message="Password is wrong, please try again"
Defaults	passwd_tries=5
Defaults	insults
Defaults	log_input,log_output

Types of Defaults Entries

Defaults                parameter,   parameter_list     #affect all users on any host
Defaults@Host_List      parameter,   parameter_list     #affects all users on a specific host
Defaults:User_List      parameter,   parameter_list     #affects a specific user
Defaults!Cmnd_List      parameter,   parameter_list     #affects  a specific command 
Defaults>Runas_List     parameter,   parameter_list     #affects commands being run as a specific user

For the scope of this guide, we will zero down to the first type of Defaults in the forms below. Parameters may be flags, integer values, strings, or lists.

You should note that flags are implicitly boolean and can be turned off using the '!' operator, and lists have two additional assignment operators, += (add to list) and -= (remove from list).

Defaults     parameter
OR
Defaults     parameter=value
OR
Defaults     parameter -=value   
Defaults     parameter +=value  
OR
Defaults     !parameter       

1. Set a Secure PATH

This is the path used for every command run with sudo, it has two importances:

  1. Used when a system administrator does not trust sudo users to have a secure PATH environment variable
  2. To separate “root path” and “user path”, only users defined by exempt_group are not affected by this setting.

To set it, add the line:

Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

2. Enable sudo on TTY User Login Session

To enable sudo to be invoked from a real tty but not through methods such as cron or cgi-bin scripts, add the line:

Defaults  requiretty   

3. Run Sudo Command Using a pty

A few times, attackers can run a malicious program (such as a virus or malware) using sudo, which would again fork a background process that remains on the user’s terminal device even when the main program has finished executing.

To avoid such a scenario, you can configure sudo to run other commands only from a psuedo-pty using the use_pty parameter, whether I/O logging is turned on or not as follows:

Defaults  use_pty

4. Create a Sudo Log File

By default, sudo logs through syslog(3). However, to specify a custom log file, use the logfile parameter like so:

Defaults  logfile="/var/log/sudo.log"

To log hostname and the four-digit year in the custom log file, use log_host and log_year parameters respectively as follows:

Defaults  log_host, log_year, logfile="/var/log/sudo.log"

Below is an example of a custom sudo log file:

Create Custom Sudo Log File

Create Custom Sudo Log File

5. Log Sudo Command Input/Output

The log_input and log_output parameters enable sudo to run a command in pseudo-tty and log all user input and all output sent to the screen receptively.

The default I/O log directory is /var/log/sudo-io, and if there is a session sequence number, it is stored in this directory. You can specify a custom directory through the iolog_dir parameter.

Defaults   log_input, log_output

There are some escape sequences are supported such as %{seq} which expands to a monotonically increasing base-36 sequence number, such as 000001, where every two digits are used to form a new directory, e.g. 00/00/01 as in the example below:

$ cd /var/log/sudo-io/
$ ls
$ cd  00/00/01
$ ls
$ cat log

Log sudo Input Output

Log sudo Input Output

You can view the rest of the files in that directory using the cat command.

6. Lecture Sudo Users

To lecture sudo users about password usage on the system, use the lecture parameter as below.

It has 3 possible values:

  1. always – always lecture a user.
  2. once – only lecture a user the first time they execute sudo command (this is used when no value is specified)
  3. never – never lecture the user.
 
Defaults  lecture="always"

Additionally, you can set a custom lecture file with the lecture_file parameter, type the appropriate message in the file:

Defaults  lecture_file="/path/to/file"

Lecture Sudo Users

Lecture Sudo Users

7. Show Custom Message When You Enter Wrong sudo Password

When a user enters a wrong password, a certain message is displayed on the command line. The default message is “sorry, try again”, you can modify the message using the badpass_message parameter as follows:

Defaults  badpass_message="Password is wrong, please try again"

8. Increase sudo Password Tries Limit

The parameter passwd_tries is used to specify the number of times a user can try to enter a password.

The default value is 3:

Defaults   passwd_tries=5 

Increase Sudo Password Attempts

Increase Sudo Password Attempts

To set a password timeout (default is 5 minutes) using passwd_timeout parameter, add the line below:

Defaults   passwd_timeout=2

9. Let Sudo Insult You When You Enter Wrong Password

In case a user types a wrong password, sudo will display insults on the terminal with the insults parameter. This will automatically turn off the badpass_message parameter.

Defaults  insults 

Let's Sudo Insult You When Enter Wrong Password

Let’s Sudo Insult You When Enter Wrong Password

Read MoreLet Sudo Insult You When You Enter Incorrect Password

10. Learn More Sudo Configurations

Additionally, you can learn more sudo command configurations by reading: Difference Between su and sudo and How to Configure sudo in Linux.

That’s it! You can share other useful sudo command configurations or tricks and tips with Linux users out there via the comment section below.

Source

Newsboat – An RSS/Atom Feed Reader for Linux Terminals

Newsboat is a free, open source RSS/Atom feed reader for Linux terminals. It is originally created from Newsbeuter, a text based RSS/Atom feed reader, however, Newsbeuter is not actively maintained.

RSS/Atom are a number of widely-used XML formats to communicate, publish and syndicate articles, for instance news or blog articles. Newsboat is created to be used on text terminals such as GNU/Linux, FreeBSD or macOS.

Read AlsoNewsroom – A Modern CLI to Get Your Favorite News in Linux

In this article, we will show how to install and use Newsboat – a command-line feed reader to read your favorite news or articles from the Linux terminal.

Requirements:

  • GCC 4.9 or later, or Clang 3.6 or later
  • STFL (version 0.21 or later)
  • pkg-config
  • GNU gettext (only for systems that do not offer gettext in the libc)
  • libcurl (version 7.18.0 or later)
  • libxml2, xmllint, and xsltproc
  • json-c (version 0.11 or later)
  • SQLite3 (version 3.5 or later)
  • DocBook XML
  • DocBook SML
  • asciidoc

How to Install Newsboat in Linux Systems

Newsboat is available to install from the snap package management system, but first you have to install snapdon your system to install Newsboat as shown.

------------- On Debian/Ubuntu/Linux Mint ------------- 
$ sudo apt install snapd	
$ sudo snap install newsboat 

------------- On Fedora 22+ -------------
$ sudo dnf install snapd
$ sudo snap install newsboat

Alternatively, you can install Newsboat from source code to use some of the latest features, but before that you need to fully install dependencies with the command that follows.

------------- On Debian/Ubuntu/Linux Mint ------------- 
$ sudo apt update
$ sudo apt install libncursesw5-dev ncurses-term debhelper libjson0 libjson0-dev libxml2-dev libstfl-dev libsqlite3-dev perl pkg-config libcurl4-gnutls-dev librtmp-dev libjson-c-dev asciidoc libxml2-utils xsltproc docbook-xml docbook-xsl bc
$ wget http://www.clifford.at/stfl/stfl-0.24.tar.gz
$ tar -xvf  stfl-0.24.tar.gz
$ cd  stfl-0.24
$ make
$ sudo make install
------------- On RHEL and CentOS -------------
# yum install libncursesw5-devel ncurses-term libjson0-devel libxml2-devel libstfl-devel libsqlite3-devel perl pkgconfig libcurl4-gnutls-devel librtmp-devel libjson-c-devel asciidoc libxml2-devel libxslt-devel debhelper docbook-style-xsl docbook-style-xml bc
# wget http://www.clifford.at/stfl/stfl-0.24.tar.gz
# tar -xvf  stfl-0.24.tar.gz
# cd  stfl-0.24
# make
# make install 

Then clone the Newsboat repository from Github to your system, and install it as shown.

$ git clone git://github.com/newsboat/newsboat.git
$ cd newsboat  
$ make
$ sudo make install

How to Use Newsboat Feed Reader in Linux Terminal

In this section, we will explain how to use Newsboat to read RSS feed from a site, for example tecmint.comFirst of all, we will need to get the rss-feed link for tecmint.com from a browser and copy it (you can use any website feed url).

https://www.tecmint.com/feed/

Afterwards, save it in a file for later usage.

$ echo "https://www.tecmint.com/feed/" >rss_links.txt

Now you can read RSS feed from Tecmint.com using following command with the switches -u (specifies file containing RSS feed URLs) and -r (refresh feeds on start) as follows.

$ newsboat -ru rss_links.txt

Read RSS Feed in Linux Terminal

Read RSS Feed in Linux Terminal

To select a topic, use the Up and Down arrows to navigate, then press Enter on the topic you want. This examples shows that we have selected topic number 5 from the list.

Select Feed Topic in Linux Terminal

Select Feed Topic in Linux Terminal

To open a topic in the browser, you can press o, and to quit the program, hit q.

You can see all the options and usages by running the following command.

$ newsboat -h

For more information, visit Newsboat Github Repository: https://github.com/newsboat/newsboat.

Read Also: Cricket-CLI – Watch Live Cricket Scores in Linux Terminal

Newsboat is a simple and intuitive RSS/Atom feed reader for Linux terminals. Try it out and give us your feedback via the comment form below.

Source

20 Funny Commands of Linux or Linux is Fun in Terminal

Linux is fun! Huhhh. OK so you don’t believe me. Mind me at the end of this article you will have to believe that Linux is actually a fun box.

Linux Funny Commands

20 Linux Funny Commands

1. Command: sl (Steam Locomotive)

You might be aware of command ‘ls‘ the list command and use it frequently to view the contents of a folder but because of miss-typing sometimes you would result in ‘sl‘, how about getting a little fun in terminal and not “command not found“.

Install sl

root@tecmint:~# apt-get install sl 		(In Debian like OS)
root@tecmint:~# yum -y install sl 		(In Red Hat like OS)
Output
root@tecmint:~# sl

sl funny command

sl command

This command works even when you type ‘LS‘ and not ‘ls‘.

2. Command: telnet

NoNo!! it is not as much complex as it seems. You would be familiar with telnet. Telnet is a text-oriented bidirectional network protocol over network. Here is nothing to be installed. What you should have is a Linux box and a working Internet.

root@tecmint:~# telnet towel.blinkenlights.nl

telnet command

telnet command

3. Command: fortune

what about getting your random fortune, sometimes funny in terminal.

Install fortune

root@tecmint:~# apt-get install fortune 	(for aptitude based system)
root@tecmint:~# yum install fortune 		(for yum based system)
root@tecmint:~# fortune

You're not my type.  For that matter, you're not even my species!!!
Future looks spotty.  You will spill soup in late evening.
You worry too much about your job.  Stop it.  You are not paid enough to worry.
Your love life will be... interesting.

4. Command: rev (Reverse)

It reverse every string given to it, is not it funny.

root@tecmint:~# rev

123abc 
cba321 

xuniL eb ot nrob
born to be Linux

5. Command: factor

Time for some Mathematics, this command output all the possible factors of a given number.

root@tecmint:~# factor 5

5 
5: 5 

12 
12: 2 2 3 

1001 
1001: 7 11 13 

5442134 
5442134: 2 2721067

6. Command: script

OK fine this is not a command and a script but it is nice.

root@tecmint:~# for i in {1..12}; do for j in $(seq 1 $i); do echo -ne $i×$j=$((i*j))\t;done; echo;done 

1×1=1	
2×1=2	2×2=4	
3×1=3	3×2=6	3×3=9	
4×1=4	4×2=8	4×3=12	4×4=16	
5×1=5	5×2=10	5×3=15	5×4=20	5×5=25	
6×1=6	6×2=12	6×3=18	6×4=24	6×5=30	6×6=36	
7×1=7	7×2=14	7×3=21	7×4=28	7×5=35	7×6=42	7×7=49	
8×1=8	8×2=16	8×3=24	8×4=32	8×5=40	8×6=48	8×7=56	8×8=64	
9×1=9	9×2=18	9×3=27	9×4=36	9×5=45	9×6=54	9×7=63	9×8=72	9×9=81	
10×1=10	10×2=20	10×3=30	10×4=40	10×5=50	10×6=60	10×7=70	10×8=80	10×9=90	10×10=100	
11×1=11	11×2=22	11×3=33	11×4=44	11×5=55	11×6=66	11×7=77	11×8=88	11×9=99	11×10=110	11×11=121	
12×1=12	12×2=24	12×3=36	12×4=48	12×5=60	12×6=72	12×7=84	12×8=96	12×9=108	12×10=120	12×11=132	12×12=144

7. Command: Cowsay

An ASCII cow in terminal that will say what ever you want.

Install Cowsay

root@tecmint:~# apt-get install cowsay 		(for Debian based OS)
root@tecmint:~# yum install cowsay		(for Red Hat based OS)
Output
root@tecmint:~# cowsay I Love nix 

 ____________
< I Love nix >
 ------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

How about pipelineing ‘fortune command‘, described above with cowsay?

root@tecmint:~# fortune | cowsay 

 _________________________________________
/ Q: How many Oregonians does it take to  \
| screw in a light bulb? A: Three. One to |
| screw in the light bulb and two to fend |
| off all those                           |
|                                         |
| Californians trying to share the        |
\ experience.                             /
 -----------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Note: ‘|‘ is called pipeline instruction and it is used where the output of one command needs to be the input of another command. In the above example the output of ‘fortune‘ command acts as an input of ‘cowsay‘ command. This pipeline instruction is frequently used in scripting and programming.

xcowsay is a graphical program which response similar to cowsay but in a graphical manner, hence it is X of cowsay.

apt-get install xcowsay
yum install xcowsay
Output
root@tecmint:~# xcowsay I Love nix

install xcowsay

xcowsay command

cowthink is another command just run “cowthink Linux is sooo funny” and see the difference in output of cowsay and cowthink.

apt-get install cowthink
yum install cowthink
Output
root@tecmint:~# cowthink ....Linux is sooo funny
 _________________________
( ....Linux is sooo funny )
 -------------------------
        o   ^__^
         o  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

8. Command: yes

It is funny but useful as well, specially in scripts and for System Administrators where an automated predefined response can be passed to terminal or generated.

root@tecmint:~# yes I Love Linux

I Love Linux
I Love Linux
I Love Linux
I Love Linux
I Love Linux
I Love Linux
I Love Linux
I Love Linux
I Love Linux
I Love Linux
I Love Linux
I Love Linux

Note: (Till you interrupt i.e ctrl+c).

9. Command: toilet

what? Are u kidding, huhh no! Definitely not, but for sure this command name itself is too funny, and I don’t know from where this command gets it’s name.

Install toilet

root@tecmint:~# apt-get install toilet 
root@tecmint:~# yum install toilet
Output
root@tecmint:~# toilet tecmint 

mmmmmmm                        "             m                               
   #     mmm    mmm   mmmmm  mmm    m mm   mm#mm          mmm    mmm   mmmmm 
   #    #"  #  #"  "  # # #    #    #"  #    #           #"  "  #" "#  # # # 
   #    #""""  #      # # #    #    #   #    #           #      #   #  # # # 
   #    "#mm"  "#mm"  # # #  mm#mm  #   #    "mm    #    "#mm"  "#m#"  # # #

It even offers some kind of color and fonts style.

root@tecmint:~# toilet -f mono12 -F metal Tecmint.com

install toilet command

toilet command

NoteFiglet is another command that more or less provide such kind of effect in terminal.

10. Command: cmatrix

You might have seen Hollywood movie ‘matrix‘ and would be fascinated with power, Neo was provided with, to see anything and everything in matrix or you might think of an animation that looks alike Hacker‘s desktop.

Install cmatrix

root@tecmint:~# apt-get install cmatrix
root@tecmint:~# yum install cmatrix
Output
root@tecmint:~# cmatrix

cmatrix command

cmatrix command

11. Command: oneko

OK so you believe that mouse pointer of Linux is the same silly black/white pointer where no animation lies then I fear you could be wrong. “oneko“ is a package that will attach a “Jerry“ with you mouse pointer and moves along with you pointer.

Install oneko

root@tecmint:~# apt-get install oneko
root@tecmint:~# yum install oneko
Output
root@tecmint:~# oneko

install oneko

oneko command

Note: Once you close the terminal from which oneko was run, jerry will disappear, nor will start at start-up. You can add the application to start up and continue enjoying.

12. Fork Bomb

This is a very nasty piece of code. Run this at your own risk. This actually is a fork bomb which exponentially multiplies itself till all the system resource is utilized and the system hangs. (To check the power of above code you should try it once, but all at your own risk, close and save all other programs and file before running fork bomb).

root@tecmint:~# :(){ :|:& }:

13. Command: while

The below “while” command is a script which provides you with colored date and file till you interrupt (ctrl + c). Just copy and paste the below code in terminal.

root@tecmint:~# while true; do echo "$(date '+%D %T' | toilet -f term -F border --gay)"; sleep 1; done

Linux while command

Linux while command

Note: The above script when modified with following command, will gives similar output but with a little difference, check it in your terminal.

root@tecmint:~# while true; do clear; echo "$(date '+%D %T' | toilet -f term -F border --gay)"; sleep 1; done

14. Command: espeak

Just Turn the Knob of your multimedia speaker to full before pasting this command in your terminal and let us know how you felt listening the god’s voice.

Install espeak

root@tecmint:~# apt-get install espeak
root@tecmint:~# yum install espeak
Output
root@tecmint:~# espeak "Tecmint is a very good website dedicated to Foss Community"

15. Command: aafire

How about fire in your terminal. Just type “aafire” in the terminal, without quotes and see the magic. Press any key to interrupt the program.

Install aafire

root@tecmint:~# apt-get install libaa-bin
Output
root@tecmint:~# aafire

install aafire

aafire command

16. Command: bb

First install “apt-get insatll bb” and then, type “bb” in terminal and see what happens.

root@tecmint:~# bb

bb command

bb command

17. Command: url

Won’t it be an awesome feeling for you if you can update you twitter status from command line in front of your friend and they seems impressed. OK just replace usernamepassword and your status message with your’s usernamepassword and “your status message“.

root@tecmint:~# url -u YourUsername:YourPassword -d status="Your status message" http://twitter.com/statuses/update.xml

18. ASCIIquarium

How it will be to get an aquarium in terminal.

root@tecmint:~# apt-get install libcurses-perl
root@tecmint:~# cd /tmp 
root@tecmint:~# wget http://search.cpan.org/CPAN/authors/id/K/KB/KBAUCOM/Term-Animation-2.4.tar.gz
root@tecmint:~# tar -zxvf Term-Animation-2.4.tar.gz
root@tecmint:~# cd Term-Animation-2.4/
root@tecmint:~# perl Makefile.PL &&  make &&   make test
root@tecmint:~# make install
Install ASCIIquarium

Now Download and Install ASCIIquarium.

root@tecmint:~# cd /tmp
root@tecmint:~# wget http://www.robobunny.com/projects/asciiquarium/asciiquarium.tar.gz
root@tecmint:~# tar -zxvf asciiquarium.tar.gz
root@tecmint:~# cd asciiquarium_1.1/
root@tecmint:~# cp asciiquarium /usr/local/bin
root@tecmint:~# chmod 0755 /usr/local/bin/asciiquarium

And finally run “asciiquarium” or “/usr/local/bin/asciiquarium“ in terminal without quotes and be a part of magic that will be taking place in front of your eyes.

root@tecmint:~# asciiquarium

install aquarium

aquarium command

19. Command: funny manpages

First install “apt-get install funny-manpages” and then run man pages for the commands below. Some of them may be 18+, run at your own risk, they all are too funny.

baby
celibacy
condom
date
echo
flame
flog
gong
grope, egrope, fgrope 
party 
rescrog 
rm
rtfm
tm
uubp
woman (undocumented)
xkill 
xlart 
sex 
strfry
root@tecmint:~# man baby

20. Linux Tweaks

It is time for you to have some one liner tweaks.

root@tecmint:~# world

bash: world: not found
root@tecmint:~# touch girls\ boo** 

touch: cannot touch `girls boo**': Permission denied
root@tecmint:~# nice man woman

No manual entry for woman
root@tecmint:~# ^How did the sex change operation go?^ 

bash: :s^How did the sex change operation go?^ : substitution failed
root@tecmint:~# %blow 

bash: fg: %blow: no such job
root@tecmint:~# make love 

make: *** No rule to make target `love'.  Stop.
$ [ whereis my brain?                    
sh: 2: [: missing ]
% man: why did you get a divorce? 
man:: Too many arguments.
% !:say, what is saccharine? 
Bad substitute.
server@localhost:/srv$ \(- 
bash: (-: command not found

Linux is sexy: who | grep -i blonde | date; cd ~; unzip; touch; strip; finger; mount; gasp; yes; uptime; umount; sleep (If you know what i mean)

There are certain other but these don’t work on all the system and hence not included in this article. Some of them are man dog , filterbanner, etc.

Have fun, you can say me thanks later 🙂 yup your comment is highly appreciated which encourages us write more. Tell us which command you liked the most. Stay tuned i will be back soon with another article worth reading.

Source

WP2Social Auto Publish Powered By : XYZScripts.com