How to Check MD5 Sums of Installed Packages in Debian/Ubuntu Linux

Have you ever wondered why a given binary or package installed on your system does not work according to you expectations, meaning it does not function correctly as it is supposed to do, perhaps it can not event start at all.

While downloading packages, you may face challenges of unsteady network connections or unexpected power blackouts, this can result into installation of corrupted package.

Considering this as an important factor in maintaining uncorrupted packages on your system, it is therefore a vital step to verify the files on the file system against the information stored in the package by using following article.

Suggested Read: Learn How to Generate and Verify Files with MD5 Checksum in Linux

How to Verify Installed Debian Packages Against MD5 Checksums

On Debian/Ubuntu systems, you can use the debsums tool to check the MD5 sums of installed packages. If you want to know the information about debsums package before installing it, you can use APT-CACHE like so:

$ apt-cache search debsums

Next, install it using apt command as follows:

$ sudo apt install debsums

Now its time to learn how to use debsums tool to verify MD5sum of installed packages.

Note: I have used sudo with all the commands below because certain files may not have read permissions for regular users.

In addition, the output from the debsums command shows you the file location on the left and the check results on the right. There are three possible results you can get, they include:

  1. OK – indicates that a file’s MD5 sum is good.
  2. FAILED – shows that a file’s MD5 sum does not match.
  3. REPLACED – means that the specific file has been replaced by a file from another package.

When you run it without any options, debsums checks every file on your system against the stock md5sum files.

$ sudo debsums
Scans File System for MD5 Sums
/usr/bin/a11y-profile-manager-indicator                                       OK
/usr/share/doc/a11y-profile-manager-indicator/copyright                       OK
/usr/share/man/man1/a11y-profile-manager-indicator.1.gz                       OK
/usr/share/accounts/providers/facebook.provider                               OK
/usr/share/accounts/qml-plugins/facebook/Main.qml                             OK
/usr/share/accounts/services/facebook-microblog.service                       OK
/usr/share/accounts/services/facebook-sharing.service                         OK
/usr/share/doc/account-plugin-facebook/copyright                              OK
/usr/share/accounts/providers/flickr.provider                                 OK
/usr/share/accounts/qml-plugins/flickr/Main.qml                               OK
/usr/share/accounts/services/flickr-microblog.service                         OK
/usr/share/accounts/services/flickr-sharing.service                           OK
/usr/share/doc/account-plugin-flickr/copyright                                OK
/usr/share/accounts/providers/google.provider                                 OK
/usr/share/accounts/qml-plugins/google/Main.qml                               OK
/usr/share/accounts/services/google-drive.service                             OK
/usr/share/accounts/services/google-im.service                                OK
/usr/share/accounts/services/picasa.service                                   OK
/usr/share/doc/account-plugin-google/copyright                                OK
/lib/systemd/system/accounts-daemon.service                                   OK
/usr/lib/accountsservice/accounts-daemon                                      OK
/usr/share/dbus-1/interfaces/org.freedesktop.Accounts.User.xml                OK
/usr/share/dbus-1/interfaces/org.freedesktop.Accounts.xml                     OK
/usr/share/dbus-1/system-services/org.freedesktop.Accounts.service            OK
/usr/share/doc/accountsservice/README                                         OK
/usr/share/doc/accountsservice/TODO                                           OK
....

To enable checking of every file and configuration files for each package for any changes, include the -a or --all option:

$ sudo debsums --all
Check MD5 Sums of All Configuration Files
/usr/bin/a11y-profile-manager-indicator                                       OK
/usr/share/doc/a11y-profile-manager-indicator/copyright                       OK
/usr/share/man/man1/a11y-profile-manager-indicator.1.gz                       OK
/etc/xdg/autostart/a11y-profile-manager-indicator-autostart.desktop           OK
/usr/share/accounts/providers/facebook.provider                               OK
/usr/share/accounts/qml-plugins/facebook/Main.qml                             OK
/usr/share/accounts/services/facebook-microblog.service                       OK
/usr/share/accounts/services/facebook-sharing.service                         OK
/usr/share/doc/account-plugin-facebook/copyright                              OK
/etc/signon-ui/webkit-options.d/www.facebook.com.conf                         OK
/usr/share/accounts/providers/flickr.provider                                 OK
/usr/share/accounts/qml-plugins/flickr/Main.qml                               OK
/usr/share/accounts/services/flickr-microblog.service                         OK
/usr/share/accounts/services/flickr-sharing.service                           OK
/usr/share/doc/account-plugin-flickr/copyright                                OK
/etc/signon-ui/webkit-options.d/login.yahoo.com.conf                          OK
/usr/share/accounts/providers/google.provider                                 OK
/usr/share/accounts/qml-plugins/google/Main.qml                               OK
/usr/share/accounts/services/google-drive.service                             OK
/usr/share/accounts/services/google-im.service                                OK
/usr/share/accounts/services/picasa.service                                   OK
/usr/share/doc/account-plugin-google/copyright                                OK
...

It is as well possible to check only the configuration file excluding all other package files by using the -e or --config option:

$ sudo debsums --config
Only Check MD5 Sums of Configuration Files
/etc/xdg/autostart/a11y-profile-manager-indicator-autostart.desktop           OK
/etc/signon-ui/webkit-options.d/www.facebook.com.conf                         OK
/etc/signon-ui/webkit-options.d/login.yahoo.com.conf                          OK
/etc/signon-ui/webkit-options.d/accounts.google.com.conf                      OK
/etc/dbus-1/system.d/org.freedesktop.Accounts.conf                            OK
/etc/acpi/asus-keyboard-backlight.sh                                          OK
/etc/acpi/events/asus-keyboard-backlight-down                                 OK
/etc/acpi/ibm-wireless.sh                                                     OK
/etc/acpi/events/tosh-wireless                                                OK
/etc/acpi/asus-wireless.sh                                                    OK
/etc/acpi/events/lenovo-undock                                                OK
/etc/default/acpi-support                                                     OK
/etc/acpi/events/ibm-wireless                                                 OK
/etc/acpi/events/asus-wireless-on                                             OK
/etc/acpi/events/asus-wireless-off                                            OK
/etc/acpi/tosh-wireless.sh                                                    OK
/etc/acpi/events/asus-keyboard-backlight-up                                   OK
/etc/acpi/events/thinkpad-cmos                                                OK
/etc/acpi/undock.sh                                                           OK
/etc/acpi/events/powerbtn                                                     OK
/etc/acpi/powerbtn.sh                                                         OK
/etc/init.d/acpid                                                             OK
/etc/init/acpid.conf                                                          OK
/etc/default/acpid                                                            OK
...

Next, to only display changed files in the output of debsums, use the -c or --changed option. I didn’t found any changed files in my system.

$ sudo debsums --changed

The next command prints out files that do not have md5sum info, here we use the -l and --list-missingoption. On my system, the command does not show any file.

$ sudo debsums --list-missing

Now it’s time to verify the md5 sum of a single package by specifying its name:

$ sudo debsums apache2 
Check MD5 Sum of Installed Package
/lib/systemd/system/apache2.service.d/apache2-systemd.conf                    OK
/usr/sbin/a2enmod                                                             OK
/usr/sbin/a2query                                                             OK
/usr/sbin/apache2ctl                                                          OK
/usr/share/apache2/apache2-maintscript-helper                                 OK
/usr/share/apache2/ask-for-passphrase                                         OK
/usr/share/bash-completion/completions/a2enmod                                OK
/usr/share/doc/apache2/NEWS.Debian.gz                                         OK
/usr/share/doc/apache2/PACKAGING.gz                                           OK
/usr/share/doc/apache2/README.Debian.gz                                       OK
/usr/share/doc/apache2/README.backtrace                                       OK
/usr/share/doc/apache2/README.multiple-instances                              OK
/usr/share/doc/apache2/copyright                                              OK
/usr/share/doc/apache2/examples/apache2.monit                                 OK
/usr/share/doc/apache2/examples/secondary-init-script                         OK
/usr/share/doc/apache2/examples/setup-instance                                OK
/usr/share/lintian/overrides/apache2                                          OK
/usr/share/man/man1/a2query.1.gz                                              OK
/usr/share/man/man8/a2enconf.8.gz                                             OK
/usr/share/man/man8/a2enmod.8.gz                                              OK
/usr/share/man/man8/a2ensite.8.gz                                             OK
/usr/share/man/man8/apache2ctl.8.gz                                           OK

Assuming that you are running debsums as a regular user without sudo, you can treat permission errors as warnings by employing the --ignore-permissions option:

$ debsums --ignore-permissions 

How To Generate MD5 Sums from .Deb Files

The -g option tells debsums to generate MD5 sums from deb contents, where:

  1. missing – instruct debsums to generate MD5 sums from the deb for packages which don’t provide one.
  2. all – directs debsums to ignore the on disk sums and use the one present in the deb file, or generated from it if none exists.
  3. keep – tells debsums to write the extracted/generated sums to /var/lib/dpkg/info/package.md5sums file.
  4. nocheck – means the extracted/generated sums are not checked against the installed package.

When you look at the contents of the directory /var/lib/dpkg/info/, you will see md5sums for various files that packages as in the image below:

$ cd /var/lib/dpkg/info
$ ls *.md5sums
List All MD5 Sums for Packages
a11y-profile-manager-indicator.md5sums
account-plugin-facebook.md5sums
account-plugin-flickr.md5sums
account-plugin-google.md5sums
accountsservice.md5sums
acl.md5sums
acpid.md5sums
acpi-support.md5sums
activity-log-manager.md5sums
adduser.md5sums
adium-theme-ubuntu.md5sums
adwaita-icon-theme.md5sums
aisleriot.md5sums
alsa-base.md5sums
alsa-utils.md5sums
anacron.md5sums
apache2-bin.md5sums
apache2-data.md5sums
apache2.md5sums
apache2-utils.md5sums
apg.md5sums
apparmor.md5sums
app-install-data.md5sums
app-install-data-partner.md5sums
...

Remember that using -g option is the same as --generate=missing, you can try to generate a md5 sum for apache2 package by running the following command.

$ sudo debsums --generate=missing apache2 

Since apache2 package on my system already has md5 sums, it will show the output below, which is the same as running:

$ sudo debsums apache2

For more interesting options and usage info, look through the debsums man page.

$ man debsums

In this article, we shared how to verify installed Debian/Ubuntu packages against MD5 checksums, this can be useful in order to avoid installing and executing corrupted binaries or package files on your system by checking the files on the file system against the information stored in the package.

For any questions or feedback, take advantage of the comment form below. Imaginably, you can as well offer one or two suggestions to make this post better.

Source

fkill – Interactively Kill Processes in Linux

Fkill-cli is a free open source, simple and cross-platform command line tool designed to interactively kill processes in Linux, developed using Nodejs. It also runs on Windows and MacOS X operating systems. It requires a process ID (PID) or process name to kill it.

fkill - Kill Linux Processes

Requirements:

  1. Install Nodejs 8 and NPM in Linux

In this article, we will explain how to install and use fkill to interactively kill processes in Linux systems.

How to Install fkill-cli in Linux Systems

To install fkill-cli tool, first you need to install required packages Nodejs and NPM on your Linux distributions using following commands.

Install Nojejs and NPM in Debian/Ubuntu

--------------- Install Noje.js 8 --------------- 
$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
$ sudo apt install -y nodejs

--------------- or Install Noje.js 10 ---------------
$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
$ sudo apt install -y nodejs

Install Nojejs and NPM in CentOS/RHEL & Fedora

--------------- Install Noje.js 8 --------------- 
$ curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
$ sudo yum -y install nodejs

--------------- or Install Noje.js 10 ---------------
$ curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -
$ sudo yum -y install nodejs

Once Nodejs and NPM packages are installed, now you can install fkill-cli package using npm command using the -g option, which enables installing it globally.

$ sudo npm install -g fkill-cli

Once you have installed fkill-cli on your system, use the fkill command to launch it in interactive mode by running it without any arguments. Once you have select the process you want to kill, press Enter.

$ fkill  

Run fkill Interactively

Run fkill Interactively

You can also provide a PID or process name from the command line, the process name is case insensitive, here are some examples.

$ fkill 1337
$ fkill firefox

To kill a port, prefix it with a colon, for example: :19999.

$ fkill :19999

You can use the -f flag to force an operation and -v allows for displaying process arguments.

$ fkill -f 1337
$ fkill -v firefox

To view the fkill help message, use the following command.

$ fkill --help

Also check out examples of how to kill processes using traditional Linux tools such as killpkill and killall:

  1. A Guide to Kill, Pkill and Killall Commands to Terminate a Process in Linux
  2. How to Find and Kill Running Processes in Linux
  3. How to Kill Linux Processes/Unresponsive Applications Using ‘xkill’ Command

Fkill-cli Github repositoryhttps://github.com/sindresorhus/fkill-cli

That’s it! In this article, we have explained how to install and use fkill-cli tool in Linux with examples. Use the comment form below to ask any questions, or share your thoughts about it.

Source

How to Auto Execute Commands/Scripts During Reboot or Startup

I am always fascinated by the things going on behind the scenes when I boot a Linux system and log on. By pressing the power button on a bare metal or starting a virtual machine, you put in motion a series of events that lead to a fully-functional system – sometimes in less than a minute. The same is true when you log off and / or shutdown the system.

What makes this more interesting and fun is the fact that you can have the operating system execute certain actions when it boots and when you logon or logout.

In this distro-agnostic article we will discuss the traditional methods for accomplishing these goals in Linux.

Note: We will assume the use of Bash as main shell for logon and logout events. If you happen to use a different one, some of these methods may or may not work. If in doubt, refer to the documentation of your shell.

Executing Linux Scripts During Reboot or Startup

There are two traditional methods to execute a command or run scripts during startup:

Method #1 – Use a cron Job

Besides the usual format (minute / hour / day of month / month / day of week) that is widely used to indicate a schedule, cron scheduler also allows the use of @reboot. This directive, followed by the absolute path to the script, will cause it to run when the machine boots.

However, there are two caveats to this approach:

  1. a) the cron daemon must be running (which is the case under normal circumstances), and
  2. b) the script or the crontab file must include the environment variables (if any) that will be needed (refer to this StackOverflow thread for more details).

Method #2 – Use /etc/rc.d/rc.local

This method is valid even for systemd-based distributions. In order for this method to work, you must grant execute permissions to /etc/rc.d/rc.local as follows:

# chmod +x /etc/rc.d/rc.local

and add your script at the bottom of the file.

The following image shows how to run two sample scripts (/home/gacanepa/script1.sh and /home/gacanepa/script2.sh) using a cron job and rc.local, respectively, and their respective results.

script1.sh:
#!/bin/bash
DATE=$(date +'%F %H:%M:%S')
DIR=/home/gacanepa
echo "Current date and time: $DATE" > $DIR/file1.txt
script2.sh:
#!/bin/bash
SITE="Tecmint.com"
DIR=/home/gacanepa
echo "$SITE rocks... add us to your bookmarks." > $DIR/file2.txt

Run Linux Scripts at Startup

Run Linux Scripts at Startup

Keep in mind that both scripts must be granted execute permissions previously:

$ chmod +x /home/gacanepa/script1.sh
$ chmod +x /home/gacanepa/script2.sh

Executing Linux Scripts at Logon and Logout

To execute a script at logon or logout, use ~.bash_profile and ~.bash_logout, respectively. Most likely, you will need to create the latter file manually. Just drop a line invoking your script at the bottom of each file in the same fashion as before and you are ready to go.

Summary

In this article we have explained how to run script at reboot, logon, and logout. If you can think of other methods we could have included here, feel free to use the comment form below to point them out. We look forward to hearing from you!

Source

How to Find Out File Types in Linux

The easiest way to determine the type of a file on any operating system is usually to look at its extension (for instance .xml.sh.c.tar etc..). What if a file doesn’t have an extension, how can you determine its type?

Read Also7 Ways to Find Out File System Types in Linux

Linux has a useful utility called file which carry out some tests on a specified file and prints the file type once a test is successful. In this short article, we will explain useful file command examples to determine a file type in Linux.

Note: To have all the options described in this article, you should be running file version 5.25 (available in Ubuntu repositories) or newer. CentOS repositories have an older version of file command (file-5.11) which lacks some options.

You can run following command to verify the version of file utility as shown.

$ file -v

file-5.33
magic file from /etc/magic:/usr/share/misc/magic

Linux file Command Examples

1. The simplest file command is as follows where you just provide a file whose type you want to find out.

$ file etc

Find File Type in Linux

Find File Type in Linux

2. You can also pass the names of the files to be examined from a file (one per line), which you can specify using the -f flag as shown.

$ file -f files.list

Find Files Type in Filename List

Find Files Type in Filename List

3. To make file work faster you can exclude a test (valid tests include apptype, ascii, encoding, tokens, cdf, compress, elf, soft and tar) from the list of tests made to determine the file type, use the -e flag as shown.

$ file -e ascii -e compress -e elf etc

4. The -s option causes file to also read block or character special files, for example.

$ file -s /dev/sda

/dev/sda: DOS/MBR boot sector, extended partition table (last)

5. Adding the -z options instructs file to look inside compressed files.

$ file -z backup

Determine Compressed Files

Determine Compressed Files

6. If you want to report information about the contents only not the compression, of a compressed file, use the -Z flag.

$ file -Z backup

7. You can tell file command to output mime type strings instead of the more traditional human readable ones, using the -i option.

$ file -i -s /dev/sda

/dev/sda: application/octet-stream; charset=binary

8. In addition, you can get a slash-separated list of valid extensions for the file type found by adding the –extension switch.

$ file --extension /dev/sda

For more information and usage options, consult the file command man page.

$ man file

That’s all! file command is a useful Linux utility to determine the type of a file without an extension. In this article, we shared some useful file command examples. If you have any questions or thoughts to share, use the feedback form below to reach us.

Source

How to Manage User Password Expiration and Aging in Linux

System administration involves numerous tasks including managing users/groups and under user management, some of the minor tasks involved are adding, modifying, suspending, or deactivating user accounts, and many more.

This article will explain one of the critical user account management functions, how to set or change user password expiration and aging in Linux using the chage command.

Read AlsoHow to Manage Users and Groups in Linux

The chage command is used to modify user password expiry information. It enables you to view user account aging information, change the number of days between password changes and the date of the last password change.

Once you have set password expiry and aging information, this information is used by the system to determine when a user must change his/her password. Normally, companies or organizations have certain security polices that demand users to change passwords regularly: this can be a simple way to enforce such policies as we explained below.

To view a user account aging information, use the -l flag as shwon.

# chage -l ravi

View User Password Aging Information

View User Password Aging Information

To set the date or number of days (since January 1, 1970) when the password was last changed, use the -dflag as follows.

# chage -d 2018-02-11 ravi

Next, you can also set the date or number of days (since January 1, 1970) on which the user’s account will no longer be accessible by using the -E switch as shown in the following command.

In this case, once a user’s account is locked, he/she is required to contact the system administrator before being able to use the system again.

# chage -E 2018-02-16 ravi

Then, the -W option allows you to set the number of days of warning before a password change is required. Considering the command below, the user ravi will be warned 10 days prior to his password expiring.

# chage -W 10 ravi

In addition, you can set the number of days of inactivity after a password has expired before the account is locked. This example means that after user ravi’s password expires, his account will be inactive for 2 days before it is locked.

When the account becomes inactive, he must contact the system administrator before being able to use the system again.

# chage -I 2 ravi

For more information, refer to the chage man page.

# man chage

Note that you can also change a user’s password expiration and aging information using the usermod command, which is actually intended for modifying a user account.

Also check out:

  1. Managing Users & Groups, File Permissions & Attributes on User Accounts
  2. 11 Ways to Find User Account Info and Login Details in Linux

That’s it for now. Hoping you find this article informative and useful, if you have any questions to ask, use the feedback form below.

Source

12 Useful “df” Commands to Check Disk Space in Linux

On the internet you will find plenty of tools for checking disk space utilization in Linux. However, Linux has a strong built in utility called ‘df‘. The ‘df‘ command stand for “disk filesystem“, it is used to get full summary of available and used disk space usage of file system on Linux system.

Using ‘-h‘ parameter with (df -h) will shows the file system disk space statistics in “human readable” format, means it gives the details in bytes, mega bytes and gigabyte.

How to Check Disk Space in Linux

Useful df Command Examples

This article explain a way to get the full information of Linux disk space usage with the help of ‘df‘ command with their practical examples. So, you could better understand the usage of df command in Linux.

1. Check File System Disk Space Usage

The “df” command displays the information of device name, total blocks, total disk space, used disk space, available disk space and mount points on a file system.

[root@tecmint ~]# df

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/cciss/c0d0p2     78361192  23185840  51130588  32% /
/dev/cciss/c0d0p5     24797380  22273432   1243972  95% /home
/dev/cciss/c0d0p3     29753588  25503792   2713984  91% /data
/dev/cciss/c0d0p1       295561     21531    258770   8% /boot
tmpfs                   257476         0    257476   0% /dev/shm

2. Display Information of all File System Disk Space Usage

The same as above, but it also displays information of dummy file systems along with all the file system disk usage and their memory utilization.

[root@tecmint ~]# df -a

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/cciss/c0d0p2     78361192  23186116  51130312  32% /
proc                         0         0         0   -  /proc
sysfs                        0         0         0   -  /sys
devpts                       0         0         0   -  /dev/pts
/dev/cciss/c0d0p5     24797380  22273432   1243972  95% /home
/dev/cciss/c0d0p3     29753588  25503792   2713984  91% /data
/dev/cciss/c0d0p1       295561     21531    258770   8% /boot
tmpfs                   257476         0    257476   0% /dev/shm
none                         0         0         0   -  /proc/sys/fs/binfmt_misc
sunrpc                       0         0         0   -  /var/lib/nfs/rpc_pipefs

3. Show Disk Space Usage in Human Readable Format

Have you noticed that above commands displays information in bytes, which is not readable yet all, because we are in a habit of reading the sizes in megabytes, gigabytes etc. as it makes very easy to understand and remember.

The df command provides an option to display sizes in Human Readable formats by using ‘-h’ (prints the results in human readable format (e.g., 1K 2M 3G)).

[root@tecmint ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/cciss/c0d0p2      75G   23G   49G  32% /
/dev/cciss/c0d0p5      24G   22G  1.2G  95% /home
/dev/cciss/c0d0p3      29G   25G  2.6G  91% /data
/dev/cciss/c0d0p1     289M   22M  253M   8% /boot
tmpfs                 252M     0  252M   0% /dev/shm

4. Display Information of /home File System

To see the information of only device /home file system in human readable format use the following command.

[root@tecmint ~]# df -hT /home

Filesystem		Type    Size  Used Avail Use% Mounted on
/dev/cciss/c0d0p5	ext3     24G   22G  1.2G  95% /home

5. Display Information of File System in Bytes

To display all file system information and usage in 1024-byte blocks, use the option ‘-k‘ (e.g. –block-size=1K) as follows.

[root@tecmint ~]# df -k

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/cciss/c0d0p2     78361192  23187212  51129216  32% /
/dev/cciss/c0d0p5     24797380  22273432   1243972  95% /home
/dev/cciss/c0d0p3     29753588  25503792   2713984  91% /data
/dev/cciss/c0d0p1       295561     21531    258770   8% /boot
tmpfs                   257476         0    257476   0% /dev/shm

6. Display Information of File System in MB

To display information of all file system usage in MB (Mega Byte) use the option as ‘-m‘.

[root@tecmint ~]# df -m

Filesystem           1M-blocks      Used Available Use% Mounted on
/dev/cciss/c0d0p2        76525     22644     49931  32% /
/dev/cciss/c0d0p5        24217     21752      1215  95% /home
/dev/cciss/c0d0p3        29057     24907      2651  91% /data
/dev/cciss/c0d0p1          289        22       253   8% /boot
tmpfs                      252         0       252   0% /dev/shm

7. Display Information of File System in GB

To display information of all file system statistics in GB (Gigabyte) use the option as ‘df -h‘.

[root@tecmint ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/cciss/c0d0p2      75G   23G   49G  32% /
/dev/cciss/c0d0p5      24G   22G  1.2G  95% /home
/dev/cciss/c0d0p3      29G   25G  2.6G  91% /data
/dev/cciss/c0d0p1     289M   22M  253M   8% /boot
tmpfs                 252M     0  252M   0% /dev/shm

8. Display File System Inodes

Using ‘-i‘ switch will display the information of number of used inodes and their percentage for the file system.

[root@tecmint ~]# df -i

Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/cciss/c0d0p2    20230848  133143 20097705    1% /
/dev/cciss/c0d0p5    6403712  798613 5605099   13% /home
/dev/cciss/c0d0p3    7685440 1388241 6297199   19% /data
/dev/cciss/c0d0p1      76304      40   76264    1% /boot
tmpfs                  64369       1   64368    1% /dev/shm

9. Display File System Type

If you notice all the above commands output, you will see there is no file system type mentioned in the results. To check the file system type of your system use the option ‘T‘. It will display file system type along with other information.

[root@tecmint ~]# df -T

Filesystem		Type   1K-blocks  Used      Available Use% Mounted on
/dev/cciss/c0d0p2	ext3    78361192  23188812  51127616  32%   /
/dev/cciss/c0d0p5	ext3    24797380  22273432  1243972   95%   /home
/dev/cciss/c0d0p3	ext3    29753588  25503792  2713984   91%   /data
/dev/cciss/c0d0p1	ext3    295561     21531    258770    8%    /boot
tmpfs			tmpfs   257476         0    257476    0%   /dev/shm

10. Include Certain File System Type

If you want to display certain file system type use the ‘-t‘ option. For example, the following command will only display ext3 file system.

[root@tecmint ~]# df -t ext3

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/cciss/c0d0p2     78361192  23190072  51126356  32% /
/dev/cciss/c0d0p5     24797380  22273432   1243972  95% /home
/dev/cciss/c0d0p3     29753588  25503792   2713984  91% /data
/dev/cciss/c0d0p1       295561     21531    258770   8% /boot

11. Exclude Certain File System Type

If you want to display file system type that doesn’t belongs to ext3 type use the option as ‘-x‘. For example, the following command will only display other file systems types other than ext3.

[root@tecmint ~]# df -x ext3

Filesystem           1K-blocks      Used Available Use% Mounted on
tmpfs                   257476         0    257476   0% /dev/shm

12. Display Information of df Command.

Using ‘–help‘ switch will display a list of available option that are used with df command.

[root@tecmint ~]# df --help

Usage: df [OPTION]... [FILE]...
Show information about the file system on which each FILE resides,
or all file systems by default.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all             include dummy file systems
  -B, --block-size=SIZE use SIZE-byte blocks
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
  -H, --si              likewise, but use powers of 1000 not 1024
  -i, --inodes          list inode information instead of block usage
  -k                    like --block-size=1K
  -l, --local           limit listing to local file systems
      --no-sync         do not invoke sync before getting usage info (default)
  -P, --portability     use the POSIX output format
      --sync            invoke sync before getting usage info
  -t, --type=TYPE       limit listing to file systems of type TYPE
  -T, --print-type      print file system type
  -x, --exclude-type=TYPE   limit listing to file systems not of type TYPE
  -v                    (ignored)
      --help     display this help and exit
      --version  output version information and exit

SIZE may be (or may be an integer optionally followed by) one of following:
kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.

Report bugs to <bug-coreutils@gnu.org>.

Read Also :

  1. 10 fdisk Commands to Manage Linux Disk Partitions
  2. 10 Useful “du” Commands to Find Disk Usage of Files and Directories

Source

Discus – Show Colourised Disk Space Usage in Linux

In our last article, we have explained how to use df (disk filesystem) utility to report file system disk space usage in Linux. We have discovered yet a another great utility for the same purpose but with a prettier output, called discus.

Discus is a df-like, highly configurable utility for checking disk space utilization in Linux, intended to make dfprettier with fancy features such as colored output, bar graphs, and smart formatting of numbers. To configure it, you may copy its main configuration file /etc/discusrc to ~/.discusrc and do your customization in there.

Read AlsoPydf an Alternative “df” Command to Check Disk Usage in Different Colours

The package discus is available to install from the default system repositories using package manager on Linux distribution as shown.

$ sudo apt install discus	#Debian/UBuntu
$ sudo yum install discus	#RHEL/CentOS
$ sudo dnf install discus	#Fedora 22+

After installing discus, learn how to use discus with the following examples.

Discus Command Examples

Run the discus command with the default settings.

$ discus

Check Linux Filesystem Disk Space

Check Linux Filesystem Disk Space

To disable the color, use the -c flag.

$ discus -c

To display device names instead of graphs, use the -d flag:.

$ discus -d

Check Disk Space Usage By Devices

Check Disk Space Usage By Devices

If do not want to use smart formatting, you can disable it using the -s switch as shown.

$ discus -s

You can specify the number of digits to right of decimal place using the -p flag.

$ discus -p 3

To display sizes in kilobytes, gigabytes, megabytes, or terabytes use the -k-g-m, or -t flags respectively. For example.

$ discus -m

Last but not least, if you want to configure it to your preference, copy its main configuration file /etc/discusrc to ~/.discusrc as shown.

$ sudo cp /etc/discusrc ~/.discusrc

Then open the newly created file and perform your customization.

$ vim ~/.discusrc

Discus Configuration Customization

Discus Configuration Customization

For more information, see the discus man page.

$ man discus 

You may also like to read these following useful articles on Linux disk space usage.

  1. 10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories
  2. How to Find Out Top Directories and Files (Disk Space) in Linux

That’s all! Discus is a simple utility intended to make df command prettier. Try it out and let us know of thoughts in the comments section below.

Source

How to Count Number of Files and Subdirectories inside a Given Directory

The easiest way to count number of files and subdirectories in a directory using a tree command, which is best known for displaying files and directories in tree-like form.

Although you can always enable quotas to restrict disk space and inode usage to avoid user abuse, this command may be useful anyway. By default, the current working directory is assumed if no arguments are given:

$ tree -iLf 1
Sample Output
.
./10-Top-Linux-Distributions-of-2015.png
./adobe-flash-player-alternative.jpg
./CentOS-7-Security-Hardening-Guide.png
./coding.png
./d-logo-sketch.png
./Experts-Share-Thoughts-on-25th-Anniversary-of-the-World-Wide-Web-431806-2.jpg
./Get-Default-OS-Logo.png
./InstallCinnamonDesktoponUbuntuandFedora720x345.png
./Install-Nagios-in-CentOS.jpg
./Install-Vmware-Workstation-12-in-Linux.png
./Install-WordPress-on-CentOS-Fedora.png
./Linux-Essentials-Bundle-Course.png
./Linux-Online-Training-Courses.png
./Linux-PDF-Readers-Viewers-Tools.png
./linux-play-game.jpg
./logo.png
./nrpe-3.0.tar.gz
./Python-and-Linux-Administration-Course.png
./Ravi
./teamviewer 11 0 57095 i386
./Telegram
./tsetup.0.10.1.tar.xz
./VBoxGuestAdditions_5.0.0.iso
./Vivaldi-About.png
./VMware-Workstation-Full-12.1.1-3770994.x86_64.bundle

3 directories, 22 files

If you want to view the same information for /var/log, do:

$ tree -iLf 1 /var/log
Sample Output
/var/log
/var/log/alternatives.log
/var/log/apt
/var/log/aptitude
/var/log/auth.log
/var/log/boot.log
/var/log/bootstrap.log
/var/log/btmp
/var/log/btmp.1
/var/log/ConsoleKit
/var/log/cups
/var/log/dmesg
/var/log/dpkg.log
/var/log/faillog
/var/log/fontconfig.log
/var/log/fsck
/var/log/gpu-manager.log
/var/log/hp
/var/log/installer
/var/log/kern.log
/var/log/lastlog
/var/log/mdm
/var/log/mintsystem.log
/var/log/mintsystem.timestamps
/var/log/ntpstats
/var/log/samba
/var/log/speech-dispatcher
/var/log/syslog
/var/log/syslog.1
/var/log/teamviewer11
/var/log/unattended-upgrades
/var/log/upstart
/var/log/vbox-install.log
/var/log/wtmp
/var/log/wtmp.1
/var/log/Xorg.0.log
/var/log/Xorg.0.log.old

13 directories, 23 files

Type the command below to view information about files and subdirectories in the directory ISOs.

$ tree -iLf 1 ISOs 
Sample Output
ISOs
ISOs/CentOS-6.5-x86_64-minimal.iso
ISOs/CentOS-7.0-1406-x86_64-Minimal.iso
ISOs/CentOS-7-x86_64-DVD-1503-01
ISOs/ces-standard-3.3-x86_64.iso
ISOs/debian-8.1.0-amd64-CD-1.iso
ISOs/kali-linux-2.0-i386
ISOs/openSUSE-13.2-DVD-x86_64.iso
ISOs/rhel-server-7.0-x86_64-dvd.iso
ISOs/ubuntu-14.04.2-desktop-amd64.iso
ISOs/ubuntu-14.04.3-server-amd64.iso
ISOs/VL-7.1-STD-FINAL.iso
ISOs/Win10_1511_1_English_x32.iso
ISOs/Win10_1511_1_Spanish_64.iso

2 directories, 11 files

Count Files and Subdirectories in a Directory

Count Files and Subdirectories in a Directory

Explaining tree options used in the command above:

  1. -i – its a graphical option that enables tree to print out indentation lines
  2. -L – specifies the level of depth of the directory tree to be displayed, which in the case above is 1
  3. -f – makes tree print the full path prefix for every file

As you can view from the image above, after listing all the files and subdirectories, tree shows you the total number of directories and files in the directory you specified.

Suggested Read: Encrypt and Decrypt Files and Directories Using Tar and OpenSSL

You can refer to the tree man page to discover more useful options, some configuration files and environment variables to better understand how it works.

Conclusion

Here, we covered an important tip that can help you use the tree utility in a different way as compared to its traditional use, for displaying files and directories in a tree-like form.

You can can build new tips by using the numerous tree options from the man page. Do you have any useful tip concerning the use of tree? Then share it with millions of Linux users around the world through the feedback form below.

Source

Find Top 15 Processes by Memory Usage with ‘top’ in Batch Mode

Similarly to the previous tip about find out top processes by RAM and CPU usage, you can also use top command to view the same information. Perhaps there’s an extra advantage of this approach when compared to the previous one: the “header” of top provides extra information about the current status and usage of the system: the uptime, load average, and total number of processes, to name a few examples.

Find Processes By Memory Usage with top

Find Processes By Memory Usage with top

To display the top 15 processes sorted by memory use in descending order, do:

# top -b -o +%MEM | head -n 22

As opposed to the previous tip, here you have to use +%MEM (note the plus sign) to sort the output in descending order:

List Top 15 Processes By Memory Usage

List Top 15 Processes By Memory Usage

From the command above, the option:

  1. -b : runs top in batch mode
  2. -o : used to specify fields for sorting processes
  3. head utility displays the first few lines of a file and
  4. the -n option is used to specify the number of lines to be displayed.

Note that head utility, by default displays the first ten lines of a file, that is when you do not specify the number of lines to be displayed. Therefore, in the example above, we displayed the first 22 lines of top command output in batch mode.

Redirect or Save ‘top’ Output to File in Linux

Additionally, using top in batch mode allows you to redirect the output to a file for later inspection:

# top -b -o +%MEM | head -n 22 > topreport.txt

As we have seen, the top utility offers us more dynamic information while listing processes on a Linux system, therefore, this approach has an extra advantage compared to using ps utility which we covered in tip one.

But most importantly, you must always run top in batch mode to redirect its output to a file or another process. Additionally, if you have any tips regarding use of top, you can also share them with us via the feedback form below.

Source

15 Practical Examples of ‘echo’ command in Linux

echo is one of the most commonly and widely used built-in command for Linux bash and C shells, that typically used in scripting language and batch files to display a line of text/string on standard output or a file.

echo command

echo command examples

The syntax for echo is:

echo [option(s)] [string(s)]

1. Input a line of text and display on standard output

$ echo Tecmint is a community of Linux Nerds 

Outputs the following text:

Tecmint is a community of Linux Nerds 

2. Declare a variable and echo its value. For example, Declare a variable of x and assign its value=10.

$ x=10

echo its value:

$ echo The value of variable x = $x 

The value of variable x = 10 

Note: The ‘-e‘ option in Linux acts as interpretation of escaped characters that are backslashed.

3. Using option ‘\b‘ – backspace with backslash interpretor ‘-e‘ which removes all the spaces in between.

$ echo -e "Tecmint \bis \ba \bcommunity \bof \bLinux \bNerds" 

TecmintisacommunityofLinuxNerds 

4. Using option ‘\n‘ – New line with backspace interpretor ‘-e‘ treats new line from where it is used.

$ echo -e "Tecmint \nis \na \ncommunity \nof \nLinux \nNerds" 

Tecmint 
is 
a 
community 
of 
Linux 
Nerds 

5. Using option ‘\t‘ – horizontal tab with backspace interpretor ‘-e‘ to have horizontal tab spaces.

$ echo -e "Tecmint \tis \ta \tcommunity \tof \tLinux \tNerds" 

Tecmint 	is 	a 	community 	of 	Linux 	Nerds 

6. How about using option new Line ‘\n‘ and horizontal tab ‘\t‘ simultaneously.

$ echo -e "\n\tTecmint \n\tis \n\ta \n\tcommunity \n\tof \n\tLinux \n\tNerds" 

	Tecmint 
	is 
	a 
	community 
	of 
	Linux 
	Nerds 

7. Using option ‘\v‘ – vertical tab with backspace interpretor ‘-e‘ to have vertical tab spaces.

$ echo -e "\vTecmint \vis \va \vcommunity \vof \vLinux \vNerds" 

Tecmint 
        is 
           a 
             community 
                       of 
                          Linux 
                                Nerds 

8. How about using option new Line ‘\n‘ and vertical tab ‘\v‘ simultaneously.

$ echo -e "\n\vTecmint \n\vis \n\va \n\vcommunity \n\vof \n\vLinux \n\vNerds" 


Tecmint 

is 

a 

community 

of 

Linux 

Nerds 

Note: We can double the vertical tab, horizontal tab and new line spacing using the option two times or as many times as required.

9. Using option ‘\r‘ – carriage return with backspace interpretor ‘-e‘ to have specified carriage return in output.

$ echo -e "Tecmint \ris a community of Linux Nerds" 

is a community of Linux Nerds 

10. Using option ‘\c‘ – suppress trailing new line with backspace interpretor ‘-e‘ to continue without emitting new line.

$ echo -e "Tecmint is a community \cof Linux Nerds" 

Tecmint is a community avi@tecmint:~$ 

11. Omit echoing trailing new line using option ‘-n‘.

$ echo -n "Tecmint is a community of Linux Nerds" 
Tecmint is a community of Linux Nerdsavi@tecmint:~/Documents$ 

12. Using option ‘\a‘ – alert return with backspace interpretor ‘-e‘ to have sound alert.

$ echo -e "Tecmint is a community of \aLinux Nerds" 
Tecmint is a community of Linux Nerds

Note: Make sure to check Volume key, before firing.

13. Print all the files/folder using echo command (ls command alternative).

$ echo * 

103.odt 103.pdf 104.odt 104.pdf 105.odt 105.pdf 106.odt 106.pdf 107.odt 107.pdf 108a.odt 108.odt 108.pdf 109.odt 109.pdf 110b.odt 110.odt 110.pdf 111.odt 111.pdf 112.odt 112.pdf 113.odt linux-headers-3.16.0-customkernel_1_amd64.deb linux-image-3.16.0-customkernel_1_amd64.deb network.jpeg 

14. Print files of a specific kind. For example, let’s assume you want to print all ‘.jpeg‘ files, use the following command.

$ echo *.jpeg 

network.jpeg 

15. The echo can be used with redirect operator to output to a file and not standard output.

$ echo "Test Page" > testpage 

## Check Content
avi@tecmint:~$ cat testpage 
Test Page 
echo Options
 Options  Description
 -n  do not print the trailing newline.
 -e  enable interpretation of backslash escapes.
 \b  backspace
 \\  backslash
 \n  new line
 \r  carriage return
 \t  horizontal tab
 \v  vertical tab

That’s all for now and don’t forget to provide us with your valuable feedback in the comments below.

Source

WP2Social Auto Publish Powered By : XYZScripts.com