How to: Set/Configure Static IP Address/DHCP for Ubuntu Server/Desktop 18.04/19.04/19.10 via Terminal using netplan

Before starting the process, make sure you have other ways/backup method to access your server/desktop rather than over LAN/WAN in case if the connect is lost.

Using netplan

(For older versions we can use “sudo apt install netplan.io” to install netplan)

netplan is a YAML network configuration tool [1]

1 First we need to check is there is existing configuration file

# Change current directory to /etc/netplan
cd /etc/netplan
 
# List files under that folder
ls
/etc/netplan folder
/etc/netplan folder

Here we have a file “50-cloud-init.yaml” which we can use

If the folder is empty, we can create the file by using

touch config.yaml

2 Editing the file

(In this example we use default file which is “50-cloud-init.yaml”, if you have created “config.yaml” file it will be empty)

sudo nano 50-cloud-init.yaml

We will see following contents

Note: ens33 is the Ethernet interface, yours can be different don’t change it!!!!

# This file is generated from information provided by                                                                   # the datasource.  Changes to it will not persist across an instance.                                                   # To disable cloud-init's network configuration capabilities, write a file                                              # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:                                              # network: {config: disabled}                                                                                           network:
    ethernets:                                                                                                                  
        ens33:                                                                                                                      
            dhcp4: true                                                                                                     
    version: 2
Editing yaml file for netplan
Editing yaml file for netplan

Now, we can see on interface ens33, it is configured to use dhcp version 4. (dhcp4: true)

If we want to use DHCP for this server/desktop, then this setting is fine, we do not need to change anything. (We can use Ctrl + X to exit the nano program)

If we want to configure a static IP address for this server/desktop, here is what we need to change (We only need to look at “Before” and “After” sections, “Different format” “If we have workgroup” and “Or two domains” are extended reading)

Note: The spaces in front of “ethernets, ens33” etc. etc. they are actually spaces not Tab, we can’t use Tab for those and these spaces are actually indentation, so they are very important as well, do not change indentation or use Tab, otherwise the configuration file will not work.

The yaml is quite self-explanatory:

dhcp4 yes|no|true|false: Enable/Disable DHCP v4

addresses: Static IP Address

gateway4: IPv4 Gateway

nameservers: DNS resolvers

search: domain to search/workgroup

Before

# This file is generated from information provided by                                                                   # the datasource.  Changes to it will not persist across an instance.                                                   # To disable cloud-init's network configuration capabilities, write a file                                              # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:                                              # network: {config: disabled}                                                                                           network:
    ethernets:                                                                                                                  
        ens33:                                                                                                                      
            dhcp4: true                                                                                                     
    version: 2

After

# This file is generated from information provided by                                                                   # the datasource.  Changes to it will not persist across an instance.                                                   # To disable cloud-init's network configuration capabilities, write a file                                              # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:                                              # network: {config: disabled}                                                                                           network:
    ethernets:                                                                                                                  
        ens33:                                                                                                                      
            dhcp4: no
            addresses: [192.168.247.129/24]
            gateway4: 192.168.247.2
            nameservers:
              addresses: [192.168.247.2, 8.8.8.8]                                                                                                     
    version: 2

Different format

# This file is generated from information provided by                                                                   # the datasource.  Changes to it will not persist across an instance.                                                   # To disable cloud-init's network configuration capabilities, write a file                                              # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:                                              # network: {config: disabled}                                                                                           network:
    ethernets:                                                                                                                  
        ens33:                                                                                                                      
            dhcp4: no
            addresses:
            - 192.168.247.129/24
            gateway4:
            - 192.168.247.2
            nameservers:
              addresses:
              - 192.168.247.2
              - 8.8.8.8                                                                                                    
    version: 2

If we have workgroup

# This file is generated from information provided by                                                                   # the datasource.  Changes to it will not persist across an instance.                                                   # To disable cloud-init's network configuration capabilities, write a file                                              # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:                                              # network: {config: disabled}                                                                                           network:
    ethernets:                                                                                                                  
        ens33:                                                                                                                      
            dhcp4: no
            addresses: [192.168.247.129/24]
            gateway4: 192.168.247.2
            nameservers:
              addresses: [192.168.247.2, 8.8.8.8]
              search: [workgroup]                                                                                                     
    version: 2

Or two domains

# This file is generated from information provided by                                                                   # the datasource.  Changes to it will not persist across an instance.                                                   # To disable cloud-init's network configuration capabilities, write a file                                              # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:                                              # network: {config: disabled}                                                                                           network:
    ethernets:                                                                                                                  
        ens33:                                                                                                                      
            dhcp4: no
            addresses: [192.168.247.129/24]
            gateway4: 192.168.247.2
            nameservers:
              addresses: [192.168.247.2, 8.8.8.8]
              search: [domain1.example.com, domain2.example.com]                                                                                                     
    version: 2

3 Save the file

Once finished with editing, we use Ctrl + X, then hit Y, Enter key to exit nano and save the file

4 Apply the changes

sudo netplan apply

5 To check the IP address

ip a
 
or
 
ip addr
 
or 
 
ip address
ip a
ip a

Resources

[1] “Netplan configuration examples”, Netplan.io, 2020. [Online]. Available: https://netplan.io/examples.

How to: Create Docker Swarm Cluster (With 3 servers) Easily (And install portainer to manage them)

Purpose of this guide

We will learn how to create a docker swarm cluster with 1 manager node and 2 worker nodes

What do we need to follow this guide

  • A spare computer with Windows operating system (Windows/macOS/Linux) as working PC
  • 3 up to date Ubuntu Server 19.10 /Linux servers (Can be real server can be virtual machines, in this guide we are using Ubuntu server 19.10) [Tips: Virtual machine is recommended for this guide, since we can easily take snapshots and restore easily if something goes wrong]
  • Each of them should at least have 2 GB RAM
  • Servers and the working PC have access to internet
  • Server must be connected to a same LAN
  • SSH client on the working PC (It’s will be easier when copy/paste join tokens among servers)

Tasks in this guide

  1. Before creating the docker swarm cluster, we will need to configure static IP address for each server
  2. Install docker on each server
  3. Configure Manager node
  4. Configure worker node 1
  5. Configure worker node 2
  6. Check docker nodes connection
  7. Bonus: Install portainer to manage a Linux swarm cluster with portainer server and the portainer agent (Not required for the docker swarm cluster)

Begin the journey

1 Configure static IP addresses for 3 servers

(Important Note: You do not have to use same IP address as in this guide, the IP address assigned form your router’s DHCP can be used to configure as static IP address on the server as a temporary solution, e.g. if your computer is getting address like 10.0.0.10, you can use 10.0.0.100, 10.0.0.101, 10.0.0.102 as their static address. For long term usage, we should take those address out of the DHCP address pool, or IP address conflict/duplicate IP address issue can occur, you can also configure static IP address from your router as well rather than on the server although configure on the server is preferred )

Manager node – 192.168.247.129

If you don’t understand or can’t follow Step 1.1 to Step 1.6, have a look on this guide first to understand how to use netplan/configure static IP address with netplan: How to: Set/Configure Static IP Address/DHCP for Ubuntu Server/Desktop 18.04/19.04/19.10 via Terminal using netplan then continue from here

1.1 Change current directory to “/etc/netplan”

cd /etc/netplan

1.2 List files within the folder

ls

There should be a file ending with “.yaml”, in this example we have “50-cloud-init.yaml” your might be different, if so, use that one from your directory

1.3 We need to modify that file to configure static IP address

sudo nano 50-cloud-init.yaml

1.4 Change from “Before” to “After”, make sure you have correct IP address configured, again, you do not need to use the same IP address form here, make sure you have configured IP address, gateway4 and nameservers correctly.

Before

# This file is generated from information provided by                                                                   # the datasource.  Changes to it will not persist across an instance.                                                   # To disable cloud-init's network configuration capabilities, write a file                                              # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:                                              # network: {config: disabled}                                                                                           network:
    ethernets:                                                                                                                  
        ens33:                                                                                                                      
            dhcp4: true                                                                                                     
    version: 2

After

# This file is generated from information provided by                                                                   # the datasource.  Changes to it will not persist across an instance.                                                   # To disable cloud-init's network configuration capabilities, write a file                                              # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:                                              # network: {config: disabled}                                                                                           network:
    ethernets:                                                                                                                  
        ens33:                                                                                                                      
            dhcp4: no
            addresses: [192.168.247.129/24]
            gateway4: 192.168.247.2
            nameservers:
              addresses: [192.168.247.2, 8.8.8.8]                                                                                                     
    version: 2

1.5 Use Ctrl + X, then Hit Y, then hit Enter key to save and exit the nano editor

1.6 Apply changes

sudo netplan apply

1.7 Make sure the IP address is configured correctly

ip a
ip a
ip a

1.8 Make sure the configured IP and DNS works by using following commands

# Check DNS server, IP address should be returned
dig bing.com
 
# Check the network, time of round trip should be returned
ping bing.com -c 5

Worker node 1 – 192.168.247.130

1.9 Same step as from Step 1.1 to Step 1.7 but with different IP address

Worker node 2 – 192.168.247.131

1.10 Same step as from Step 1.1 to Step 1.7 but with different IP address

2 Install docker on each server

Manager node – 192.168.247.129

2.1 Install docker

sudo apt install -y docker.io

Worker node 1 – 192.168.247.130

2.2 Install docker

sudo apt install -y docker.io

Worker node 1 – 192.168.247.131

2.3 Install docker

sudo apt install -y docker.io

3 Configure Manager node – 192.168.247.129

3.0 Preparation/Suggestion for using SSH client

(Use SSH client to connect to the server from the working PC, for Windows we can use PowerShell or Windows Terminal with ssh command, for Linux and macOS we can just use terminal with ssh command)

e.g.

(To connect to 192.168.247.129, we can use following command, then type yes, hit Enter key, type password to connect)

# Format
ssh [email protected]
 
# Example For this guide
ssh [email protected]

3.1 Initialize docker swarm manager [1]

sudo docker swarm init
sudo docker swarm init
sudo docker swarm init

3.2 Copy the command for adding a worker to this swarm, the following is for this guide, yours will be different, you will have to use yours

docker swarm join --token SWMTKN-1-5vphj6kj8t6z5yz45jq97vpe742avhl7md4905o796kkupnu1t-5oypobnbtpb3kksvv5s2k15f5 192.168.247.129:2377

Note: If you have missed that token somehow, in order to show the token again

# Show token for adding worker
sudo docker swarm join-token worker
 
# Show token for adding manager
sudo docker swarm join-token manager
Show docker swarm token for adding worker and manager nodes
Show docker swarm token for adding worker and manager nodes

4 Configure worker node 1 – 192.168.247.130

4.1 Adding worker node 1 to swarm as a worker (Execute following command on worker node 1) (The command was copied from Step 3.2)

sudo docker swarm join --token SWMTKN-1-5vphj6kj8t6z5yz45jq97vpe742avhl7md4905o796kkupnu1t-6mrz20tzuovi3rivfw3ivm6wv 192.168.247.129:2377
Successfully executed command on worker node 1, worker node 1 added to swarm as a worker
Successfully executed command on worker node 1, worker node 1 added to swarm as a worker

5 Configure worker node 2 – 192.168.247.131

5.1 Adding worker node 2 to swarm as a worker (Execute following command on worker node 2) (The command was copied from Step 3.2)

sudo docker swarm join --token SWMTKN-1-5vphj6kj8t6z5yz45jq97vpe742avhl7md4905o796kkupnu1t-6mrz20tzuovi3rivfw3ivm6wv 192.168.247.129:2377
Successfully executed command on worker node 2, worker node 2 added to swarm as a worker
Successfully executed command on worker node 2, worker node 2 added to swarm as a worker

6 Check docker nodes connection

6.1 Execute following command on manager node

sudo docker node ls
sudo docker node ls output on manager node
sudo docker node ls output on manager node

Now the docker swarm cluster is created and ready for use

7 Bonus: Install portainer to manage a Linux swarm cluster with portainer server and the portainer agent (Not required for the docker swarm cluster)

7.1 Execute following commands on the manager node [2]

curl -L https://downloads.portainer.io/portainer-agent-stack.yml -o portainer-agent-stack.yml
 
docker stack deploy --compose-file=portainer-agent-stack.yml portainer
Install portainer to manage the LLLinux swarm cluster with portainer server and the portainer agent
Install portainer to manage the LLLinux swarm cluster with portainer server and the portainer agent

7.2 Open portainer web GUI, configure username and password (http://manager node’s IP address:9000) then click on “Create user”

In this guide it is http://192.168.247.129:9000

portainer web GUI
portainer web GUI
portainer home page
portainer home page

Now the portainer installation and configuration is done for managing Linux swarm cluster with portainer server and portainer agent

Click on “primary” we can view the dashboard

portainer dashboard
portainer dashboard

Click on “Go to cluster visualizer” we can see the swarm cluster details

Swarm, Cluster visualizer
Swarm, Cluster visualizer

App Templates – stack

App Templates - stack
App Templates – stack

Stacks

Stacks
Stacks

Services

Services
Services

Containers

Containers
Containers

Images

Images
Images

Networks

Networks
Networks

Volumes

Volumes
Volumes
Volumes
Volumes

Configs

Configs
Configs

Secrets

Secrets
Secrets

Swarm

Swarm
Swarm

Resources

[1] “Run Docker Engine in swarm mode”, Docker Documentation, 2020. [Online]. Available: https://docs.docker.com/engine/swarm/swarm-mode.

[2] “Installation”, Portainer.io, 2020. [Online]. Available: https://www.portainer.io/installation


How to: Fix Ubuntu Server 19 “Cockpit Cannot refresh cache whilst offline” and “Cannot refresh cache whilst offline” Errors

The Error

When cockpit is installed on Ubuntu Server 19, we might get following errors

Cockpit Cannot refresh cache whilst offline

Cannot refresh cache whilst offline

The Fix

By disabling the network-manager, we can resolve those errors (Yes, It’s more of workaround rather than fix)

Warning: Do not run these commands on production server, unless you know what you are doing.

1 Disable network-manager service and stop it immediately, then restart the system

sudo systemctl disable network-manager.service
 
sudo systemctl stop network-manager.service
 
sudo reboot

2 Now, get back to cockpit, errors won’t be there anymore


How to: Install Portainer on Ubuntu (Linux etc.) (Single node/Standalone Linux Docker host/Single node swarm cluster)

What is portainer?

An lightweight, open source and easy to use tool for managing Docker environment with web GUI, it can also manage docker swarm cluster.

If you are after some heavy weight management software alternatives, Rancher can be a good one to look into. It’s an open source multi-cluster orchestration platform.

How to Install portainer from scratch?

1 Install docker first

# For Ubuntu
sudo apt install docker.io

2 Install portainer

$ sudo docker volume create portainer_data
$ sudo docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

3 Check server IP address

ip a

4 Login to portainer and configure desired Username and Password, then click on “Create user” to proceed

http://ipaddress:9000
Configure portainer login details
Configure portainer login details

5 If you know what you are doing you can configure portainer by selecting “Remote” or “Agent” or “Azure” otherwise, we select “Local” then click on “Connect”

Configure portainer - Local
Configure portainer – Local

6 We have successfully installed, configured and logged into portainer

portainer home screen
portainer home screen

Bonus

portainer – Home

portainer - home
portainer – home

portainer – Local Dashboard

portainer - local Dashboard
portainer – local Dashboard

portainer – App Templates

portainer - App Templates
portainer – App Templates

portainer – Stacks

portainer - Stacks
portainer – Stacks

portainer – Containers

portainer - Containers
portainer – Containers

portainer – Images

portainer - Images
portainer – Images

portainer – Networks

portainer - Networks
portainer – Networks

portainer – Volumes

portainer - Volumes
portainer – Volumes

portainer – Events

portainer - Events
portainer – Events

portainer – Host

portainer - Host
portainer – Host

Resources

portainer: https://www.portainer.io

Rancher: https://rancher.com


How to: Monitor CPU/GPU/HDD temperature in Linux (Debian/Ubuntu/Kali Linux/CentOS/RHEL etc.) easily

1 glances

Monitors CPU usage, RAM usage, SWAP usage, system load, process list, hard drive I/O, Network I/O, sensors (temperature), battery, file system usage, Docker, Monitor, alarm, system information, up time etc.

Install on Debian/Ubuntu/Kali Linux

sudo apt install glances -y

Usage

sudo glances
glances
glances

2 sensor

By default, it’s installed on some Linux distros like Ubuntu etc. It can show CPU, HDD, temperature, fan RPM etc.

Install on Debian/Ubuntu/Kali Linux

sudo apt install lm-sensors

Usage

# Initialize/Detect sensors
sudo sensors-detect
 
# Show sensors information
sudo sensors

Output

coretemp-isa-0000 Adapter: ISA adapter Core 0:       +47.0°C  (high = +105.0°C, crit = +105.0°C) Core 1:       +46.0°C  (high = +105.0°C, crit = +105.0°C) acpitz-virtual-0 Adapter: Virtual device temp1:        +51.0°C  (crit = +105.0°C) thinkpad-isa-0000 Adapter: ISA adapter fan1:         674 RPM temp1:        +50.0°C temp2:        +51.0°C temp3:        +52.0°C temp4:         -1.0°C temp5:         +0.0°C temp6:         +0.0°C temp7:        +32.0°C temp8:         +0.0°C

How to: Allow/Setup multiple simultaneous remote users on Ubuntu 19.10 quickly with free/open source software (Under 10 Minutes)

There are many choices for remote session/remote desktop, e.g. How to: Install Xrdp (Remote Desktop) on CentOS 8 – (How to: Use Windows to remote control CentOS 8)

In this guide we will use open source X2Go to achieve this

Table of Contents

  1. Install X2Go Server on Ubuntu
  2. Install tasksel & Desktop environment for remote users
  3. Find out X2Go server’s IP address
  4. Download X2Go client
  5. Configure X2Go client and connect to X2Go server

1 Install X2Go server on Ubuntu

1.1 Launch terminal

1.2 Add the X2Go PPA software repository, update

sudo add-apt-repository ppa:x2go/stable
sudo apt update

1.3 Use following command to install X2Go server

sudo apt-get install x2goserver

2 Install tasksel & Desktop environment for remote users

2.1 Use following command to install tasksel

sudo apt install tasksel

(Currently, gnome 3 is not supported by X2Go, so we have to use other alternative desktop environments for remote users)

2.2 Launch tasksel

sudo tasksel
tasksel
tasksel

Use Up & Down Arrow keys to navigate through the list

2.3 Install desktop environment for remote users

Use Space key to mark the desktop environment, Use Tab key to highlight “<Ok>” then Hit Enter key to begin installation process.

“Xubuntu desktop” is suggested, since Xfce desktop uses less system resources, we can also use “Ubuntu MATE desktop” which uses more system resources than Xfce. We can install one or both of them. In this case, we are installing both “Ubuntu MATE desktop” and “Xubuntu desktop” which is Ubuntu with Xfce deskcp environment.

Selected MATE and Xfce
Selected MATE and Xfce

After hitting OK button, the installation process will begin

Installing packages
Installing packages

When it’s done, it will ask which display manager we want to use. Select the one you prefer, here we chose “gdm3” (Hit Enter key to use gdm3 or use arrow keys to select between gdm3 and lightdm)

Configuring lightdm
Configuring lightdm

It will continue to install packages

Installing packages
Installing packages

2.4 Install Desktop Bindings

This will improve usability, X2Go provides Desktop Binding tools for several desktop environments

For MATE desktop

sudo apt install x2gomatebindings

For LXDE

sudo apt all x2golxdebindings

3 Find out X2Go server’s IP address

3.1 We can use following command in terminal to find out the IP address of X2Go server

ip address

4 Download X2Go client

4.1 We can download X2Go client from heir official website

https://wiki.x2go.org/doku.php/download:start

We can download “mswin” which is for Windows then install, if you want to use another Ubuntu to connect just use “sudo apt install x2goclient” to install the X2G0 client on Ubuntu

PyHoca-GUI can be used for Windows and Ubuntu as well

Download X2Go client
Download X2Go client

5 Configure X2Go client and connect to X2Go server

5.1 Launch X2Go if the “Session preferences – New session” window is not showing, we can click on this icon “New session” to bring up the session configuration window in 5.2

X2Go Main Window
X2Go Main Window

5.2 Session preferences – New session

Session preferences - New session
Session preferences – New session

5.3 Populate the necessary information for connecting the X2Go.

Session name: Any name you like for this session, e.g. Work, Lab etc.

Host: IP address of the X2Go server

Login: Username for login to remote server

Session type: Select MATE for “Ubuntu MATE desktop”, Select Xfce for “Xubuntu desktop”

Session preferences - New session, Configured
Session preferences – New session, Configured

Click OK when done.

5.4 Double click on the session we have just created

X2Go with new session configuration
X2Go with new session configuration

5.5 Enter password for login to the remote server

Enter password
Enter password

5.6 Now it’s successfully connected

X2Go client connected to the server
X2Go client connected to the server

After it’s configured, now we can add multiple users to the X2Go server, so that multiple users will be able to login and use their desktop environment simultaneously.


ls command examples, Introduction to ls command in Linux, How to: Use ls in Linux

ls is a command used to list files and folders within a directory or folder

1 ls command

ls
ls
ls

2 Use long listing format

ls -l

-l: Long listing format

ls with long listing format
ls with long listing format

Column 1: drwxr-xr-x:

The first d means it’s directory if it’s – rather than d means it’s file, if it’s not d or – but l means it’s symbolic link.

Following 9 characters represents the file permission. First 3 rwx represents the file owner’s permission, Second 3 rwx represents the group’s file permission, Third 3 rwx represents others’ file permission

Column 2: 26: How many symbolic link points to this file

Column 3: abc: File/Directory owner

Column 4: abc: File/Directory group

Column 5: 4096: File/Directory size in bytes. For directories, it will always show 4096 bytes

Column 6: Mar 2 22:50: Last time the file was modified

Column 7: annaconda3: File/Directory name

For more information on permission/ Privilege, refer to: Unix/Linux (Ubuntu, Debian, Kali Linux etc.) Privilege Management

3 Show file size

ls -hl
 
or
 
ls -lsi

-h: human readable units (1024)

-si: human readable units (1000)

ls - hl
ls – hl
ls -lsi
ls -lsi

4 Sort the results by size

ls -hlS

-S: sort by file size, largest first

ls -hlS
ls -hlS

5 Specify units

ls -l --block-size=G
K = Kilobyte
M = Megabyte
G = Gigabyte
T = Terabyte
P = Petabyte
E = Exabyte
Z = Zettabyte
Y = Yottabyte
ls -l --block-size=G
ls -l –block-size=G

6 Show hidden files

In Linux, files begin with “.” are hidden. we can use -a switch with ls to show them

ls -a
ls -a
ls -a

7 Only list directories

ls -d */
Only list directories
Only list directories

8 Do not list owner

ls -g
Do not list owner
Do not list owner

9 Do not list group names in a long listing

ls -lG
Do not list group names in a long listing
Do not list group names in a long listing

10 Show UID and GID

ls -n
Show UID and GID
Show UID and GID

11 Print without colour

ls --color=never
Print without colour
Print without colour

12 Show index number of each file (inode)

ls -li
Show index number of each file (inode)
Show index number of each file (inode)

13 Append / indicator to directories

ls -p
Append / indicator to directories
Append / indicator to directories

14 Reverse sorting results

ls -r
Reverse sorting results
Reverse sorting results

15 List subdirectories recursively

ls -R
List subdirectories recursively
List subdirectories recursively

16 Sort alphabetically by entry extension

ls -lX
Sort alphabetically by entry extension method 1
Sort alphabetically by entry extension method 1

OR

ls -sort=extension
Sort alphabetically by entry extension method 2
Sort alphabetically by entry extension method 2

17 Sort by modification time (Latest at the top)

ls -lt
Sort by modification time (Latest at the top)
Sort by modification time (Latest at the top)

18 List folders/files for home directory

ls ~
List folders/files for home directory
List folders/files for home directory

19 List folders/files for parent directory

ls ../
List folders/files for parent directory
List folders/files for parent directory

List directory/files for parent of parent directory

ls ../../
List directory/files for parent of parent directory
List directory/files for parent of parent directory

20 Show ls version information

ls -version
Show ls version information
Show ls version information

Help page of ls

Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..
      --author               with -l, print the author of each file
  -b, --escape               print C-style escapes for nongraphic characters
      --block-size=SIZE      with -l, scale sizes by SIZE when printing them;
                               e.g., '--block-size=M'; see SIZE format below
  -B, --ignore-backups       do not list implied entries ending with ~
  -c                         with -lt: sort by, and show, ctime (time of last
                               modification of file status information);
                               with -l: show ctime and sort by name;
                               otherwise: sort by ctime, newest first
  -C                         list entries by columns
      --color[=WHEN]         colorize the output; WHEN can be 'always' (default
                               if omitted), 'auto', or 'never'; more info below
  -d, --directory            list directories themselves, not their contents
  -D, --dired                generate output designed for Emacs' dired mode
  -f                         do not sort, enable -aU, disable -ls --color
  -F, --classify             append indicator (one of */=>@|) to entries
      --file-type            likewise, except do not append '*'
      --format=WORD          across -x, commas -m, horizontal -x, long -l,
                               single-column -1, verbose -l, vertical -C
      --full-time            like -l --time-style=full-iso
  -g                         like -l, but do not list owner
      --group-directories-first
                             group directories before files;
                               can be augmented with a --sort option, but any
                               use of --sort=none (-U) disables grouping
  -G, --no-group             in a long listing, don't print group names
  -h, --human-readable       with -l and -s, print sizes like 1K 234M 2G etc.
      --si                   likewise, but use powers of 1000 not 1024
  -H, --dereference-command-line
                             follow symbolic links listed on the command line
      --dereference-command-line-symlink-to-dir
                             follow each command line symbolic link
                               that points to a directory
      --hide=PATTERN         do not list implied entries matching shell PATTERN
                               (overridden by -a or -A)
      --hyperlink[=WHEN]     hyperlink file names; WHEN can be 'always'
                               (default if omitted), 'auto', or 'never'
      --indicator-style=WORD  append indicator with style WORD to entry names:
                               none (default), slash (-p),
                               file-type (--file-type), classify (-F)
  -i, --inode                print the index number of each file
  -I, --ignore=PATTERN       do not list implied entries matching shell PATTERN
  -k, --kibibytes            default to 1024-byte blocks for disk usage;
                               used only with -s and per directory totals
  -l                         use a long listing format
  -L, --dereference          when showing file information for a symbolic
                               link, show information for the file the link
                               references rather than for the link itself
  -m                         fill width with a comma separated list of entries
  -n, --numeric-uid-gid      like -l, but list numeric user and group IDs
  -N, --literal              print entry names without quoting
  -o                         like -l, but do not list group information
  -p, --indicator-style=slash
                             append / indicator to directories
  -q, --hide-control-chars   print ? instead of nongraphic characters
      --show-control-chars   show nongraphic characters as-is (the default,
                               unless program is 'ls' and output is a terminal)
  -Q, --quote-name           enclose entry names in double quotes
      --quoting-style=WORD   use quoting style WORD for entry names:
                               literal, locale, shell, shell-always,
                               shell-escape, shell-escape-always, c, escape
                               (overrides QUOTING_STYLE environment variable)
  -r, --reverse              reverse order while sorting
  -R, --recursive            list subdirectories recursively
  -s, --size                 print the allocated size of each file, in blocks
  -S                         sort by file size, largest first
      --sort=WORD            sort by WORD instead of name: none (-U), size (-S),
                               time (-t), version (-v), extension (-X)
      --time=WORD            with -l, show time as WORD instead of default
                               modification time: atime or access or use (-u);
                               ctime or status (-c); also use specified time
                               as sort key if --sort=time (newest first)
      --time-style=TIME_STYLE  time/date format with -l; see TIME_STYLE below
  -t                         sort by modification time, newest first
  -T, --tabsize=COLS         assume tab stops at each COLS instead of 8
  -u                         with -lt: sort by, and show, access time;
                               with -l: show access time and sort by name;
                               otherwise: sort by access time, newest first
  -U                         do not sort; list entries in directory order
  -v                         natural sort of (version) numbers within text
  -w, --width=COLS           set output width to COLS.  0 means no limit
  -x                         list entries by lines instead of by columns
  -X                         sort alphabetically by entry extension
  -Z, --context              print any security context of each file
  -1                         list one file per line.  Avoid '\n' with -q or -b
      --help     display this help and exit
      --version  output version information and exit
The SIZE argument is an integer and optional unit (example: 10K is 10*1024).
Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).
The TIME_STYLE argument can be full-iso, long-iso, iso, locale, or +FORMAT.
FORMAT is interpreted like in date(1).  If FORMAT is FORMAT1<newline>FORMAT2,
then FORMAT1 applies to non-recent files and FORMAT2 to recent files.
TIME_STYLE prefixed with 'posix-' takes effect only outside the POSIX locale.
Also the TIME_STYLE environment variable sets the default style to use.
Using color to distinguish file types is disabled both by default and
with --color=never.  With --color=auto, ls emits color codes only when
standard output is connected to a terminal.  The LS_COLORS environment
variable can change the settings.  Use the dircolors command to set it.
Exit status:
 0  if OK,
 1  if minor problems (e.g., cannot access subdirectory),
 2  if serious trouble (e.g., cannot access command-line argument).
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation at: <https://www.gnu.org/software/coreutils/ls>
or available locally via: info '(coreutils) ls invocation'

Man page of ls

LS(1)                                    User Commands                                   LS(1)
NAME
       ls - list directory contents
SYNOPSIS
       ls [OPTION]... [FILE]...
DESCRIPTION
       List  information about the FILEs (the current directory by default).  Sort entries al‐
       phabetically if none of -cftuvSUX nor --sort is specified.
       Mandatory arguments to long options are mandatory for short options too.
       -a, --all
              do not ignore entries starting with .
       -A, --almost-all
              do not list implied . and ..
       --author
              with -l, print the author of each file
       -b, --escape
              print C-style escapes for nongraphic characters
       --block-size=SIZE
              with -l, scale sizes by SIZE when printing  them;  e.g.,  '--block-size=M';  see
              SIZE format below
       -B, --ignore-backups
              do not list implied entries ending with ~
       -c     with -lt: sort by, and show, ctime (time of last modification of file status in‐
              formation); with -l: show ctime and sort by name; otherwise: sort by ctime, new‐
              est first
       -C     list entries by columns
       --color[=WHEN]
              colorize  the  output;  WHEN  can  be  'always' (default if omitted), 'auto', or
              'never'; more info below
       -d, --directory
              list directories themselves, not their contents
       -D, --dired
              generate output designed for Emacs' dired mode
       -f     do not sort, enable -aU, disable -ls --color
       -F, --classify
              append indicator (one of */=>@|) to entries
       --file-type
              likewise, except do not append '*'
       --format=WORD
              across -x, commas -m, horizontal -x, long -l, single-column -1, verbose -l, ver‐
              tical -C
       --full-time
              like -l --time-style=full-iso
       -g     like -l, but do not list owner
       --group-directories-first
              group directories before files;
              can  be augmented with a --sort option, but any use of --sort=none (-U) disables
              grouping
       -G, --no-group
              in a long listing, don't print group names
       -h, --human-readable
              with -l and -s, print sizes like 1K 234M 2G etc.
       --si   likewise, but use powers of 1000 not 1024
       -H, --dereference-command-line
              follow symbolic links listed on the command line
       --dereference-command-line-symlink-to-dir
              follow each command line symbolic link
              that points to a directory
       --hide=PATTERN
              do not list implied entries matching shell PATTERN (overridden by -a or -A)
       --hyperlink[=WHEN]
              hyperlink file names; WHEN can be 'always'  (default  if  omitted),  'auto',  or
              'never'
       --indicator-style=WORD
              append  indicator  with  style  WORD to entry names: none (default), slash (-p),
              file-type (--file-type), classify (-F)
       -i, --inode
              print the index number of each file
       -I, --ignore=PATTERN
              do not list implied entries matching shell PATTERN
       -k, --kibibytes
              default to 1024-byte blocks for disk usage; used only with -s and per  directory
              totals
       -l     use a long listing format
       -L, --dereference
              when showing file information for a symbolic link, show information for the file
              the link references rather than for the link itself
       -m     fill width with a comma separated list of entries
       -n, --numeric-uid-gid
              like -l, but list numeric user and group IDs
       -N, --literal
              print entry names without quoting
       -o     like -l, but do not list group information
       -p, --indicator-style=slash
              append / indicator to directories
       -q, --hide-control-chars
              print ? instead of nongraphic characters
       --show-control-chars
              show nongraphic characters as-is (the default, unless program is 'ls' and output
              is a terminal)
       -Q, --quote-name
              enclose entry names in double quotes
       --quoting-style=WORD
              use  quoting  style  WORD for entry names: literal, locale, shell, shell-always,
              shell-escape, shell-escape-always, c, escape (overrides  QUOTING_STYLE  environ‐
              ment variable)
       -r, --reverse
              reverse order while sorting
       -R, --recursive
              list subdirectories recursively
       -s, --size
              print the allocated size of each file, in blocks
       -S     sort by file size, largest first
       --sort=WORD
              sort by WORD instead of name: none (-U), size (-S), time (-t), version (-v), ex‐
              tension (-X)
       --time=WORD
              with -l, show time as WORD instead of default modification time: atime or access
              or  use  (-u);  ctime  or  status  (-c);  also use specified time as sort key if
              --sort=time (newest first)
       --time-style=TIME_STYLE
              time/date format with -l; see TIME_STYLE below
       -t     sort by modification time, newest first
       -T, --tabsize=COLS
              assume tab stops at each COLS instead of 8
       -u     with -lt: sort by, and show, access time; with -l: show access time and sort  by
              name; otherwise: sort by access time, newest first
       -U     do not sort; list entries in directory order
       -v     natural sort of (version) numbers within text
       -w, --width=COLS
              set output width to COLS.  0 means no limit
       -x     list entries by lines instead of by columns
       -X     sort alphabetically by entry extension
       -Z, --context
              print any security context of each file
       -1     list one file per line.  Avoid '\n' with -q or -b
       --help display this help and exit
       --version
              output version information and exit
       The SIZE argument is an integer and optional unit (example: 10K is 10*1024).  Units are
       K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).
       The TIME_STYLE argument can be full-iso, long-iso, iso, locale, or +FORMAT.  FORMAT  is
       interpreted  like  in  date(1).  If FORMAT is FORMAT1<newline>FORMAT2, then FORMAT1 ap‐
       plies to non-recent files and  FORMAT2  to  recent  files.   TIME_STYLE  prefixed  with
       'posix-'  takes  effect only outside the POSIX locale.  Also the TIME_STYLE environment
       variable sets the default style to use.
       Using  color  to  distinguish  file  types  is  disabled  both  by  default  and   with
       --color=never.   With  --color=auto,  ls emits color codes only when standard output is
       connected to a terminal.  The LS_COLORS environment variable can change  the  settings.
       Use the dircolors command to set it.
   Exit status:
       0      if OK,
       1      if minor problems (e.g., cannot access subdirectory),
       2      if serious trouble (e.g., cannot access command-line argument).
AUTHOR
       Written by Richard M. Stallman and David MacKenzie.
REPORTING BUGS
       GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
       Report ls translation bugs to <https://translationproject.org/team/>
COPYRIGHT
       Copyright  ©  2018 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3 or
       later <https://gnu.org/licenses/gpl.html>.
       This is free software: you are free to change and redistribute it.  There  is  NO  WAR‐
       RANTY, to the extent permitted by law.
SEE ALSO
       Full documentation at: <https://www.gnu.org/software/coreutils/ls>
       or available locally via: info '(coreutils) ls invocation'
GNU coreutils 8.30                        August 2019                                    LS(1)

Different ways to search in Linux/Debian/Ubuntu/Kali Linux/CentOS/RHEL etc.

locate – Locate files

It can find files quickly but it depends on updatedb to update the index, updatedb runs once everyday but we can run it manually.

# Update the index manually if necessary
sudo updatedb
 
# Find/Search for "myfile"
locate myfile

whereis, which – Locate command/executable files

whereis ProgramName
 
which ProgramName

whereis: Will search for executable, source code and documents from default installation folder (Usually, it’s the default folder when installing with root)

Default folders are:

/bin
/sbin
/usr/bin
/usr/lib
/usr/local/ma
etc.

which: Will show results from environment variables, it’s very useful for finding where the actual program/executable located

e.g. Copy source code to current directory without typing complete path

cp 'which myScript.sh'

If which ProgramName returns /usr/bin/which: no ProgramName in (/home/usr/bin:/bin), it means the ProgramName is not located in environment variables, it can’t be executed directly by it’s name

find – Find files with multiple conditions

Search by folder

# Find files with name "myFile" under root directory
find / -name myFile

If executing the above command with non-root user, it will return many errors (Permission denied), we can use following command to ignore all errors but keep normal output

find / -name 2>/dev/null

What is 2>/dev/null ?: Refer to “I/O redirection in Linux” section in Linux – Basics, Useful Terminal commands and Basic File manipulation, (QuickStart)

Search by time

Show log files which were modified within 5 minutes in current working directory

find . -name '*.log' -mmin -5

(To show log files which were modified within 1 day in current working directory)

find . -name '*.log' -mtime -1

Search by Size

e.g. Search all jpg and bmp files

find . \( -name "*.jpg" -o -name "*.bmp" ) | less
 
or
 
find . -regex ".*\(\.jpg\|\.bmp\)$"
 
# Find files over 10G
find . -type f -size +100G

Limit search folder depth

Search for any .txt files within maximum 3 folder depth

find . -maxdepth 3 -name *.txt

Search for files which are not…

Search for files which are not .txt files

find . -not -name *.txt

find, grep Search for file contents

To list name of all .txt files with Mytext in the content

find . -name *.txt -exec grep -l 'Mytext' {} \;
 
or
 
find . -name *.txt | xargs grep -l 'Mytext'
 
or
 
grep -rl 'Mytext'

To view matched previous 2 lines and next 3 lines

grep -A 3 -B 2 'Mytext' a.txt

To view match counts

# Exact match
grep -c 'Mytext' a.txt
 
# Ignore case
grcp -ci 'Mytext' a.txt

Count number of series in FASTA and FASTQ

grep '^>' test.fa
 
grep '^+$' test.fq

^: Start with …

$: End with …

Match/Show unmatched lines

grep -v 'Mytext' a.txt

Regular Expression

By default, grep uses basic regular expression, add -E switch to use extended regular expression, add -P switch to use perl format regular expression

e.g. Remove all blank lines from text file

grep -v '^$' a.txt >a-without-blank-lines.txt

Extended reading

More about “find” command can be found here: How to: Use “find” command in Linux (Debian, Ubuntu, Kali Linux, CentOS, RHEL/RedHat etc.)

Other techniques related to grep can be found here: How to: Search in Linux, How to: Use grep command, How to: Use grep to search

More on whereis, which commands: Linux, Ubuntu etc. How to find where the program is installed


How to: Install VMware Tools in Linux

Install from ISO

1 Launch VMware Workstation

2 Start the Virtual Machine

3 Right click on the Virtual Machine Name on the tab

4 Click on “Install VMware Tools”

Parameter for “./vmware-install.pl”

-d: Use default/suggested answers for questions

-f: Force install

# Debian/Ubuntu etc.
#Mount to /mnt
sudo mount /dev/sr0 /mnt
#Extract, install
tar -zxvf /mnt/VMwareTools-versionNumber.tar.gz -C ~
cd vmware-tools-distrib/
sudo ./vmware-install.pl -f -d

When done, eject the ISO, reboot the operating system

sudo unmout /mnt
eject
sudo reboot

# CentOS/Fedora/RHEL etc.
#Mount to /mnt
mount /dev/sr0 /mnt
#Extract, install
tar -zxvf /mnt/VMwareTools-versoinNumber.tar.gz -C ~
cd vmware-tools-distrib/
./vmware-install.pl -f -d

Install VMware Tools from Online source/Package Manager

# Debian/Ubuntu etc.
#System without desktop environment
sudo apt install open-vm-tools
 
#System with desktop environment
sudo apt install open-vm-tools-desktop
# CentOS/Fedora/RHEL etc.
#System without desktop environment
dnf -y install open-vm-tools
or
yum -y install open-vm-tools
 
#System with desktop environment
dnf -y install open-vm-tools-desktop
or
yum -y install open-vm-tools-desktop

How to: Check Linux disk/partition information (Alternative to df)

To check Linux partition/disk usage, mount, file system types information etc. we can use df command which mentioned in “Useful commands to look up system information, install package etc. (Linux, Debian, Ubuntu, Kali Linux, RedHat, CentOS etc.)

We can also use another alternative to df which is di

1 Install

# Debian/Ubuntu/Kali Linux etc.
sudo apt install di
 
# CentOS/Fedora/RHEL
sudo dnf install di

2 Usage

2.1 Default output

[email protected]:~$ di
Filesystem         Mount               Size     Used    Avail %Used  fs Type
/dev/sda2          /                 196.3G    15.2G   171.1G   13%  ext4   
/dev/sda1          /boot/efi         511.0M     0.1M   510.8M    0%  vfat   
tmpfs              /dev/shm            1.9G     0.0G     1.9G    0%  tmpfs  
tmpfs              /run              391.3M    15.8M   375.4M    4%  tmpfs  
tmpfs              /run/lock           5.0M     0.0M     5.0M    0%  tmpfs  
tmpfs              /run/user/1000    391.3M     0.0M   391.3M    0%  tmpfs  
tmpfs              /sys/fs/cgroup      1.9G     0.0G     1.9G    0%  tmpfs
di
di

(By default di uses human readable units, with df we need to use -h switch “df -h”)

2.2 Show detailed mount point information, special device name etc.

di -A
[email protected]:~$ di -A
Mount          fs Type Filesystem 
        Options                                                                                               
            Size     Used     Free %Used  %Free 
            Size     Used    Avail %Used  %Free 
            Size     Used    Avail %Used  
           Inodes     IUsed     IFree %IUsed
/              ext4    /dev/sda2  
        rw,relatime,errors=remount-ro                                                                         
          196.3G    15.2G   181.2G    8%    92%  
          196.3G    25.2G   171.1G   13%    87%  
          186.3G    15.2G   171.1G    8%  
         13165632    570127  12595505    4% 
/boot/efi      vfat    /dev/sda1  
        rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 
          511.0M     0.1M   510.8M    0%   100%  
          511.0M     0.1M   510.8M    0%   100%  
          511.0M     0.1M   510.8M    0%  
                0         0         0    0% 
/dev/shm       tmpfs   tmpfs      
        rw,nosuid,nodev                                                                                       
            1.9G     0.0G     1.9G    0%   100%  
            1.9G     0.0G     1.9G    0%   100%  
            1.9G     0.0G     1.9G    0%  
           500837         1    500836    0% 
/run           tmpfs   tmpfs      
        rw,nosuid,nodev,noexec,relatime,size=400672k,mode=755                                                 
          391.3M    15.8M   375.4M    4%    96%  
          391.3M    15.8M   375.4M    4%    96%  
          391.3M    15.8M   375.4M    4%  
           500837       668    500169    0% 
/run/lock      tmpfs   tmpfs      
        rw,nosuid,nodev,noexec,relatime,size=5120k                                                            
            5.0M     0.0M     5.0M    0%   100%  
            5.0M     0.0M     5.0M    0%   100%  
            5.0M     0.0M     5.0M    0%  
           500837         4    500833    0% 
/run/user/1000 tmpfs   tmpfs      
        rw,nosuid,nodev,relatime,size=400668k,mode=700,uid=1000,gid=1000                                      
          391.3M     0.0M   391.3M    0%   100%  
          391.3M     0.0M   391.3M    0%   100%  
          391.3M     0.0M   391.3M    0%  
           500837        28    500809    0% 
/sys/fs/cgroup tmpfs   tmpfs      
        ro,nosuid,nodev,noexec,mode=755                                                                       
            1.9G     0.0G     1.9G    0%   100%  
            1.9G     0.0G     1.9G    0%   100%  
            1.9G     0.0G     1.9G    0%  
           500837        17    500820    0% 
di -A
di -A

2.3 Show all mounted devices

di -a
[email protected]:~$ di -a
Filesystem         Mount               Size     Used    Avail %Used  fs Type            
/dev/sda2          /                 196.3G    15.2G   171.1G   13%  ext4               
/dev/sda1          /boot/efi         511.0M     0.1M   510.8M    0%  vfat               
udev               /dev                1.9G     0.0G     1.9G    0%  devtmpfs           
hugetlbfs          /dev/hugepages      0.0M     0.0M     0.0M    0%  hugetlbfs          
mqueue             /dev/mqueue         0.0M     0.0M     0.0M    0%  mqueue             
devpts             /dev/pts            0.0M     0.0M     0.0M    0%  devpts             
tmpfs              /dev/shm            1.9G     0.0G     1.9G    0%  tmpfs              
proc               /proc               0.0M     0.0M     0.0M    0%  proc               
systemd-1          /proc/sys/fs/bi     0.0M     0.0M     0.0M    0%  autofs             
binfmt_misc        /proc/sys/fs/bi     0.0M     0.0M     0.0M    0%  binfmt_misc        
tmpfs              /run              391.3M    15.8M   375.4M    4%  tmpfs              
tmpfs              /run/lock           5.0M     0.0M     5.0M    0%  tmpfs              
sunrpc             /run/rpc_pipefs     0.0M     0.0M     0.0M    0%  rpc_pipefs         
tmpfs              /run/user/1000    391.3M     0.0M   391.3M    0%  tmpfs              
/dev/fuse          /run/user/1000/     0.0M     0.0M     0.0M    0%  fuse               
gvfsd-fuse         /run/user/1000/     0.0M     0.0M     0.0M    0%  fuse.gvfsd-fuse    
vmware-vmblock     /run/vmblock-fu     0.0M     0.0M     0.0M    0%  fuse.vmware-vmblock
sysfs              /sys                0.0M     0.0M     0.0M    0%  sysfs              
efivarfs           /sys/firmware/e     0.0M     0.0M     0.0M    0%  efivarfs           
none               /sys/fs/bpf         0.0M     0.0M     0.0M    0%  bpf                
tmpfs              /sys/fs/cgroup      1.9G     0.0G     1.9G    0%  tmpfs              
cgroup             /sys/fs/cgroup/     0.0M     0.0M     0.0M    0%  cgroup             
cgroup             /sys/fs/cgroup/     0.0M     0.0M     0.0M    0%  cgroup             
cgroup             /sys/fs/cgroup/     0.0M     0.0M     0.0M    0%  cgroup             
cgroup             /sys/fs/cgroup/     0.0M     0.0M     0.0M    0%  cgroup             
cgroup             /sys/fs/cgroup/     0.0M     0.0M     0.0M    0%  cgroup             
cgroup             /sys/fs/cgroup/     0.0M     0.0M     0.0M    0%  cgroup             
cgroup             /sys/fs/cgroup/     0.0M     0.0M     0.0M    0%  cgroup             
cgroup             /sys/fs/cgroup/     0.0M     0.0M     0.0M    0%  cgroup             
cgroup             /sys/fs/cgroup/     0.0M     0.0M     0.0M    0%  cgroup             
cgroup             /sys/fs/cgroup/     0.0M     0.0M     0.0M    0%  cgroup             
cgroup             /sys/fs/cgroup/     0.0M     0.0M     0.0M    0%  cgroup             
cgroup2            /sys/fs/cgroup/     0.0M     0.0M     0.0M    0%  cgroup2            
fusectl            /sys/fs/fuse/co     0.0M     0.0M     0.0M    0%  fusectl            
pstore             /sys/fs/pstore      0.0M     0.0M     0.0M    0%  pstore             
debugfs            /sys/kernel/deb     0.0M     0.0M     0.0M    0%  debugfs            
securityfs         /sys/kernel/sec     0.0M     0.0M     0.0M    0%  securityfs
di -a
di -a

2.4 Produce CSV style output

di -c
[email protected]:~$ di -c
s,m,b,u,v,p,T
"/dev/sda2","/","196.3G","15.2G","171.1G",13%,"ext4"
"/dev/sda1","/boot/efi","511.0M","0.1M","510.8M",0%,"vfat"
"tmpfs","/dev/shm","1.9G","0.0G","1.9G",0%,"tmpfs"
"tmpfs","/run","391.3M","15.8M","375.4M",4%,"tmpfs"
"tmpfs","/run/lock","5.0M","0.0M","5.0M",0%,"tmpfs"
"tmpfs","/run/user/1000","391.3M","0.0M","391.3M",0%,"tmpfs"
"tmpfs","/sys/fs/cgroup","1.9G","0.0G","1.9G",0%,"tmpfs"
di -c
di -c

2.5 Output size in Gigabyte

di -g

We can also use -k or -m to indicate output in K or M

[email protected]:~$ di -g
Filesystem         Mount              Gibis     Used    Avail %Used  fs Type
/dev/sda2          /                  196.3     15.2    171.1   13%  ext4   
/dev/sda1          /boot/efi            0.5      0.0      0.5    0%  vfat   
tmpfs              /dev/shm             1.9      0.0      1.9    0%  tmpfs  
tmpfs              /run                 0.4      0.0      0.4    4%  tmpfs  
tmpfs              /run/lock            0.0      0.0      0.0    0%  tmpfs  
tmpfs              /run/user/1000       0.4      0.0      0.4    0%  tmpfs  
tmpfs              /sys/fs/cgroup       1.9      0.0      1.9    0%  tmpfs
di -g
di -g

2.6 Display information for specific file system

di -I filesystem
 
e.g.
di -I tmpfs
[email protected]:~$ di -I tmpfs 
Filesystem         Mount               Size     Used    Avail %Used  fs Type
tmpfs              /dev/shm            1.9G     0.0G     1.9G    0%  tmpfs  
tmpfs              /run              391.3M    15.8M   375.4M    4%  tmpfs  
tmpfs              /run/lock           5.0M     0.0M     5.0M    0%  tmpfs  
tmpfs              /run/user/1000    391.3M     0.0M   391.3M    0%  tmpfs  
tmpfs              /sys/fs/cgroup      1.9G     0.0G     1.9G    0%  tmpfs
di -I tmpfs
di -I tmpfs

2.7 Skip title row

di -n
[email protected]:~$ di -n
/dev/sda2          /                 196.3G    15.2G   171.1G   13%  ext4   
/dev/sda1          /boot/efi         511.0M     0.1M   510.8M    0%  vfat   
tmpfs              /dev/shm            1.9G     0.0G     1.9G    0%  tmpfs  
tmpfs              /run              391.3M    15.8M   375.4M    4%  tmpfs  
tmpfs              /run/lock           5.0M     0.0M     5.0M    0%  tmpfs  
tmpfs              /run/user/1000    391.3M     0.0M   391.3M    0%  tmpfs  
tmpfs              /sys/fs/cgroup      1.9G     0.0G     1.9G    0%  tmpfs
di -n
di -n

2.8 Show total count at the bottom of the output

di -t
[email protected]:~$ di -t
Filesystem         Mount               Size     Used    Avail %Used  fs Type
/dev/sda2          /                 196.3G    15.2G   171.1G   13%  ext4   
/dev/sda1          /boot/efi         511.0M     0.1M   510.8M    0%  vfat   
tmpfs              /dev/shm            1.9G     0.0G     1.9G    0%  tmpfs  
tmpfs              /run              391.3M    15.8M   375.4M    4%  tmpfs  
tmpfs              /run/lock           5.0M     0.0M     5.0M    0%  tmpfs  
tmpfs              /run/user/1000    391.3M     0.0M   391.3M    0%  tmpfs  
tmpfs              /sys/fs/cgroup      1.9G     0.0G     1.9G    0%  tmpfs  
                   Total             201.4G    15.2G   176.2G   13%
di -t
di -t

2.9 Sort the output

# Sort by name of the mount point
di -sm
[email protected]:~$ di -sm
Filesystem         Mount               Size     Used    Avail %Used  fs Type
/dev/sda2          /                 196.3G    15.2G   171.1G   13%  ext4   
/dev/sda1          /boot/efi         511.0M     0.1M   510.8M    0%  vfat   
tmpfs              /dev/shm            1.9G     0.0G     1.9G    0%  tmpfs  
tmpfs              /run              391.3M    15.8M   375.4M    4%  tmpfs  
tmpfs              /run/lock           5.0M     0.0M     5.0M    0%  tmpfs  
tmpfs              /run/user/1000    391.3M     0.0M   391.3M    0%  tmpfs  
tmpfs              /sys/fs/cgroup      1.9G     0.0G     1.9G    0%  tmpfs
di -sm
di -sm

-s: sort

m: Order by mountpoint (Default)

n: Do not sort (Use the order from “/etc/fstab”)

s: Order by name of special device

t: Order by type of fil esystem

r: Reverse the order

Sort switch can be mixed, e.g. di -stsrm: Type, Device, Mount point in reverse order. di strsrm: Type, Device in reverse order, mount point.

2.10 Specify output format

# Output mount point name
di -fm
 
# Output file system type
di -ft
[email protected]:~$ di -fm
Mount          
/              
/boot/efi      
/dev/shm       
/run           
/run/lock      
/run/user/1000 
/sys/fs/cgroup
di -fm
di -fm
di -ft
di -ft

man page of di

di(1)                                                                                                  General Commands Manual                                                                                                  di(1)
Name
       di - disk information
Synopsis
       di [-AacghHklLmnPqRtZ] [-B block-size] [-d display-size] [-f format] [-I include-fstyp-list] [-s sort-type] [-w block-width] [-W inode-width] [-x exclude-fstyp-list] [-X debug-level] [-z zone-name] [file [...]]
       mi
Description
       di  Displays  usage information on mounted filesystems.  Block values are reported in a human readable format.  If the user or group has a disk quota, the values reported are adjusted according the quotas that apply to the
       user.
       If file is specified, the usage information for the partition on which file is located is printed.
       Unless the -a flag is specified, the following mounted filesystems will not normally be displayed: filesystems with total space <= 0; loopback filesystems that are duplicates of other normally mounted filesystems (filesys‐
       tem type of 'lofs' , 'none', or 'nullfs'); loopback filesystems that are part of a zone (Solaris).
       Filesystems that the user does not have permissions to access will not be displayed at all.
       mi Displays the mounted filesystem information.
       Several options may be specified to control the output of di and mi:
       -A     Print all fields (used for debugging).  Mount points and special device names are printed at full width.
       -a     (compatibility: --all)
              Prints all mounted devices (normally, those with 0 total space are not printed - e.g. /dev/proc, /dev/fd).
       -B     block-size (compatibility: --block-size, -b)
              Change the base block size from 1024 (default) to the size specified.  block-size may be one of: k - 1024 bytes, si - 1000 bytes, or a specific size.
       -c     (alias: --csv-output)
              Comma separated values are output.  The titles are output as the format string specifiers.  Totals are turned off. See also the -n flag.
       -C     (alias: --csv-tabs)
              Values are output with tab separators.  See also the -c option.
       -d     display-size (alias: --display-size)
              Display  the  usage  in  units  specified  by  display-size.   Note  that if the base block size is SI units of 1000 bytes, the display size is calculated using those units.  display-size may be one of: 512 - POSIX,
              k - kilobytes, m - megabytes, g - gigabytes, t - terabytes, p - petabytes, e - exabytes, z - zettabytes, y - yottabytes, h - Scaled alternative 1, H - Scaled alternative 2, or a specific value to use  as  the  block
              size.
              Block display sizes greater than 1024 bytes are displayed with a precision of one decimal place after the radix.
              The Scaled alternatives scale the sizes displayed and appends a suffix (e.g. 48.0k, 3.4M).
              With scaled alternative 1, sizes within a line may scale to different units.
              Scaled alternative 2 scales all the sizes in each individual line to the same unit size (the largest needed).
       -f     format Use the specified format string format.  See the Format Strings section.
       -g     (alias for: -dg)
              Display sizes in gigabytes.
       -h     (alias for: -dh)
              Display partition sizes in scaled alternative 1 format.
       --help
              Display some basic usage information.
       -H     (alias for: -dH; compatibility: --human-readable)
              Display partition sizes in scaled alternative 2 format.
       -I     include-fstype-list (compatibility: -F, --type)
              Include  only  the  file  system  types listed in include-fstyp-list.  The list is a comma separated list of file system types.  Multiple -I options may be specified.  If the 'fuse' filesystem type is specified, all
              fuse* filesystems will be included.
              e.g. -I nfs,tmpfs or -I nfs -I tmpfs.
       --inodes
              Ignored.  Use the -f option.
       -k     (alias for: -dk)
              Display sizes in Kbytes.
       -l     (compatibility: --local)
              Display only local file systems.
       -L     Turn off check for duplicate filesystems (loopback (lofs/none) mounts).
       -m     (alias for: -dm)
              Display sizes in megabytes.
       -n     Do not print a header line above the list of file systems.  Useful when parsing the output of di.
       --no-sync
              Ignored.
       -P     (compatibility: --portability)
              Output format is POSIX standard.  512 byte block size is the default.  The -k option may be used.
       --print-type
              Ignored.  Use the -f option.
       -q     Disable quota checks.
       -R     (also: --dont-resolve-symlinks)
              Do not resolve symlinks (for mount points that have a trailing UUID).
       -s     sort-type
              Use sort-type to sort the output.  The output of di is normally sorted by mount point.  The following sort flags may be used to change the sort order: m - by mount point (default); n - leave unsorted (as it  appears
              in  the  mount  table); s - by special device name; T - by total space; f - by free space; a - by available space; t - by filesystem type; r - reverse the sort order; This will apply to all sort flags following this
              sort flag.
              These sort options may be combined in any order.  e.g.:
              di -stsrm # by type, special, reversed mount;
              di -strsrm # by type, reversed special, mount.
       --si   An alias for -dH -Bsi.
       --sync Ignored.
       -t     (compatibility: --total)
              Print a totals line below the list of file systems.  Pooled filesystems (zfs, advfs) have only the main pool added to the total.  It is up to the user to exclude (using the -x option)  read-only  filesystems  (cdfs,
              iso9660), swap-based (memfs, mfs, tmpfs) filesystems and user (fuse*) filesystems.  Excluding the 'fuse' filesystem will exclude all fuse* filesystems.
       -w     block-width
              Set the print width for block values.  The default is eight.
       -v     Ignored.
       --version
              Display di's version and default format string.
       -W     inode-width
              Set the print width for inode values.  Default is seven.
       -x     exclude-fstype-list (compatibility: --exclude-type)
              Exclude  the  file  system  types  listed in exclude-fstyp-list.  The list is a comma separated list of file system types.  Multiple -x options may be specified.  If the 'fuse' filesystem type is excluded, all fuse*
              filesystems will be excluded.  e.g. -x nfs,tmpfs or -x nfs -x tmpfs.
       -X     level
              Set the program's debugging level to debug-level.
       -z     zone-name
              Display the filesystems for the specified zone.  The zone must be visible to the user.
       -Z     (alias for: -z all)
              Display the filesystems for all visible zones.
Format Strings
       The output of di may be specified via a format string.  This string may be given either via the -f command line option or as part of the DI_ARGS environment variable.  The format string may specify the following columns:
       m      Print the name of the mount point.
       M      Print the name of the mount point, at full length.  The mount point is formatted to the maximum width necessary for the longest mount point name.
       s      Print the file system name (special device or remote mount point).
       S      Print the file system name (special device or remote mount point), at full length.  The file system name is formatted to the maximum width necessary for the longest file system name.
       t      Print the file system type.
       T      Print the file system type at full length.  The file system type is formatted to the maximum width necessary for the longest file system type.
       Total Available
       b      Print the total number of megabytes on the file system.
       B      Print the total number of megabytes on the file system available for use by normal users.
       In Use
       u      Print the number of megabytes in use on the file system (actual number of megabytes used = total - free).
       c      Print the number of megabytes not available for use by normal users (total - available).
       Free
       f      Print the number of free (unused) megabytes on the file system.
       v      Print the number of megabytes available for use by normal users.
       Percentage Used
       p      Print the percentage of megabytes not available for use by normal users (number of megabytes not available for use / total disk space).
       1      Print the percentage of total megabytes in use (actual number of megabytes used / total disk space).
       2      Print the percentage of megabytes in use, BSD-style.  Represents the percentage of user-available space in use.  Note that values over 100% are possible (actual number of megabytes used /  disk  space  available  to
              non-root users).
       Percentage Free
       a      Print the percentage of megabytes available for use by normal users (number of megabytes available for use / total disk space).
       3      Print the percentage of total megabytes free (actual number of megabytes free / total disk space).
       Inodes
       i      Print the total number of file slots (inodes) that can be created on the file system.
       U      Print the number of file slots in use.
       F      Print the number of file slots available.
       P      Print the percentage of file slots in use.
       Mount Information
       I      Print the time the filesystem was mounted.  This column is not supported on all systems.
       O      Print the filesystem mount options.
       The default format string for di is smbuvpT.
       The default format string for mi is MSTIO.
       The format string may also contain any other character not listed above.  The character will be printed as is.  e.g. di -f 'mbuvp|iUFP' will print the character '|' between the disk usage and the file slot usage.  The com‐
       mand sequence:
              di -f 'mbuvp
              miUFP'
       will print two lines of data for each filesystem.
Examples
       Various df equivalent format strings for System V release 4 are:
              /usr/bin/df -v     di -P -f msbuf1
              /usr/bin/df -k     di -dk -f sbcvpm
              /usr/ucb/df        di -dk -f sbuv2m
       GNU df:
              df                 di -dk -f SbuvpM -w 10
              df -T              di -dk -f STbuvpM -w 10
       AIX df:
              df                 di -d 512 -f Sbf1UPM -w 10
              df -I              di -d 512 -f Sbuf1M
              df -I -M           di -d 512 -f SMbuf1 -w 10
       HP-UX bdf:
              bdf                di -d k -f Sbuv2M
              bdf -i             di -d k -f Sbuv2UFPM
       If you like your numbers to add up/calculate the percentage correctly, try one of the following format strings:
              di -f SMbuf1T
              di -f SMbcvpT
              di -f SMBuv2T
Environment Variables
       The DI_ARGS environment variable may be used to specify command line arguments.  e.g. If you always want gigabytes displayed, set DI_ARGS equal to "-dg".  Any command line arguments specified will override the DI_ARGS  en‐
       vironment variable.
       The DI_LOCALE_DIR environment variable may be used to specify the location of the di program's locale message files.
       The GNU df POSIXLY_CORRECT, and DF_BLOCK_SIZE and the BSD BLOCKSIZE environment variables are honored.
Note
       For filesystems that do not report available space (e.g. System V release 3), the number of available space is set to the free space.
WARNING
       Do not replace your system's df command with this program.  You will in all likelihood break your installation procedures.
See Also
       df(1), fstab(5), getmnt(2), getmntinfo(2), mnttab(4), mount(1M) statfs(2), statvfs(2)
Bugs
       Send bug reports to: brad.lanam.di_at_gmail.com
       Known Issues:
       di will probably not process a zettabyte or yottabyte sized filesystem properly due to overflow of a long long.
Website
       https://gentoo.com/di/
Author
       This program is Copyright 1994-2011 by Brad Lanam.
       Brad Lanam, Walnut Creek, CA (brad.lanam.di_at_gmail.com)
                                                                                                             17 Jan 2013                                                                                                        di(1)