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)

Simple usage of xargs, tr, head, tail commands

1 xargs

Similar to -exec

Delete .txt files from current folder

find . -name "*.txt" | xargs rm

Count line numbers in all .txt files

find . -name "*.txt" | xargs wc -l

2 tr

Replace

Replace capital with small case

echo "THIS IS A TEST" | tr "A-Z" "a-z"
 
#Result this is a test

ROT13 Encrypt

echo "Test" | tr "a-zA-Z" "n-za-mN-ZA-m"
 
# Result: Grfg

ROT13 Decrypt

echo "Grfg" | tr "a-zA-Z" "n-za-mN-ZA-m"
 
# Result: Test

Remove digits from the string

echo "This 3 is 1831 a tes2t" | tr -d "0-9"
 
# Result: This  is  a test

Remove redundant space

echo "This is  a       test message     " | tr -s ' '
 
# Result: This is a test message

Remove redundant empty lines form text file

cat text.txt | tr -s '\n'

3 head

Print first 10 lines

head my.log -n 10

4 tail

Print last 10 lines

tail my.log -n 10

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


Basic/Common Special symbols/Special characters in Linux

Home Directory ~

# Back to home directory
cd ~
 
# Change to sub directory within home directory
cd ~/Desktop

Current Directory .

ls -al
ls -al

. in above image means current directory

# Run script.sh in current directory
./script.sh

Parent Directory ..

cd ..
cd ..
cd ..
# Change to /test/ folder in parent folder directory
cd ../test/

Path Separator, System root folder /

ls /etc
# Change to system root folder
cd /

Comment #

#Comments are ignored by Bash shell
Comment
Comment

We can also comment part of the string from variable

# Define variable
test_string="abc def"
 
# echo the variable with abc being commented out
echo ghi ${test_string#abc}
 
# echo full variable
echo $test_string
Comment part of the string/variable
Comment part of the string/variable

Single Character Wildcard ?

? Can be used for this purpose

ls file?.txt
ls file?.txt
ls file?.txt

Since file.txt doesn’t have any characters right after file, it is not in the result.

To match exactly how many characters with ?, we use corresponding number of ?

ls ????.txt
ls ????.txt
ls ????.txt

Wildcard *

Match any character including space

ls file*
ls file*
ls file*

Match any type of files

ls file.*

Character Set Wildcard []

Match at least one of the characters in the []

ls file0[123].txt
ls file0[123].txt
ls file0[123].txt
ls file[012][012].txt
ls file[012][012].txt

Shell Command Separator (Run till the last one anyway) ;

command 1; command 2; command 3
command 1; command 2; command 3
command 1; command 2; command 3

When using Shell Command Separator “;” no matter the previous command succeeded or not, it will run till the last command

Shell Command Separator (Stop if there is error/failed) &&

command 1 && command 2 && command 3
command 1 && command 2 && command 3
command 1 && command 2 && command 3

Background Process &

Add & behind the command to run the command in the background

command &
Run the command in the background
Run the command in the background

1709 is the process ID of this background task

Input Redirection <

command < file
sort test file
sort test file
wc test
 
wx < test

(< does not display source filename)

Output Redirection >

ls > ListOfFiles.txt
 
# To read the file again
cat ListOfFiles.txt

It can be used with stderr, stdin, stdout (See bottom of this page)

cat test.txt 2> err.txt
Use with stderr
Use with stderr

Pipe |

command 1 | command 2 | command 3
cat test | grep [Aa] | sort -r
Demo or pipe
Demo or pipe

1 Use cat to read test, pip to grep command

2 Use grep to filter the test, only left with text including A and a, pipe to sort command

3 Use sort to reverse sort the text

Pipeline logical NOT and History Operator !

[ ! -d ./testfolder ] && echo "Folder testfolder does not exist"

[ ! -d ./testfolder ]: Check if the folder named testfolder exists

If does not exist, echo the text Folder testfolder does not exist

Run history command

!number
 
# e.g.
!210
Run history command
Run history command
# Run last command
!!
Run last command
Run last command

Variable Expressions $

In Bash shell, $ usually means variables

We can use echo to view the values of the variable

echo $PATH
 
echo $USER
 
echo $HOME
Show values in variables
Show values in variables

We can define variables in following ways

year=2020
MyName=Fred
Define variable

We can use {} to perform other advanced manipulation of text

# Define variable
string=12345qwert
 
# Output the string
echo ${string}
 
# Output text begin from index of 3 (Begin from 0)
echo ${string:3}
 
# Output 3 characters begin from index 0
echo ${string:0:3}
 
# Output 2 characters begin from index 2
echo ${string:2:2}

Quoting Special Characters “” ”

Use “” to stop special character functions (But not $)

echo "$string"
Double quotes
Double quotes

Use single quotes ” to disable all special character’s function

echo '$string'
Single quotes
Single quotes

We can also use backslash \ to prevent the following character to be functioning as a special character

echo "\$string"
Backslash
Backslash

Extend Reading

More on redirection, pipeline,stdin,stdout,stderr | Linux – Basics, Useful Terminal commands and Basic File manipulation, (QuickStart)

More on flow control, if else, loop, variable Linux Bash/Shell simple, basic flow control


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)

Powerful Linux Interactive shell

fish (friendly interactive shell) is a smart and user-friendly command line shell for Linux, macOS, and the rest of the family.

Autosuggestions

Autosuggestion Thumbnail

fish suggests commands as you type based on history and completions, just like a web browser. Watch out, Netscape Navigator 4.0!

Glorious VGA Color

Colors Thumbnail

fish supports 24 bit true color, the state of the art in terminal technology. Behold the monospaced rainbow.

Sane Scripting

Scripting Thumbnail

fish is fully scriptable, and its syntax is simple, clean, and consistent. You’ll never write esac again.

Web Based configuration

Web Config Thumbnail

For those lucky few with a graphical computer, you can set your colors and view functions, variables, and history all from a web page.

Man Page Completions

Man Page Completions Thumbnail

Other shells support programmable completions, but only fish generates them automatically by parsing your installed man pages.

Works Out Of The Box

Works Out of the Box Thumbnail

fish will delight you with features like tab completions and syntax highlighting that just work, with nothing new to learn or configure.

fish can be installed easily on most Linux distros with their default package manager.

Linux

# Debian/Ubuntu/Kali Linux etc.
sudo apt install fish
 
# RHEL/CentOS/Fedora
sudo dns install fish
or, for older version
sudo yum install fish
 
# Archlinux
pacman -S fish
 
# gentoo Linux
emerge fish
 
# void-Linux
xbps-install fish-shell
 
# NixOS
nix-env -i fish
 
# Guix
guix package -i fish
 
# Solus
eopkg install fish
 
# Hombrew
brew install fish

BSD

# FreeBSD
pkg install fish
 
# OpenBSD
pkg_add fish

Windows

# Cygwin
fish is available in setup, in the Shells category.
 
# Windows Subsystem for Linux
sudo apt install fish
or
depend on the Linux distro you've chose, refer to the above "Linux" part to find correct command to use
 
# MSYS2
pacman -S fish

masOS

# Homebrew
brew install fish
 
# MacPorts
sudo port install fish
 
# Installer
https://github.com/fish-shell/fish-shell/releases/download/3.1.0/fish-3.1.0.pkg
 
10.6+: Installs to /usr/local/

Bonus

  • To use, type fish in the terminal then hit Enter key

To check fish version

echo $FISH_VERSION

HTML version help document

help

To switch default shell to fish

sudo chsh -s /usr/bin/fish

To switch back to default bash shell

sudo chsh -s /bin/bash

(If your default shell is zsh)

sudo chsh -s /usr/zsh

How to: Check/Change/Set/Modify Linux (Debian/Ubuntu/Kali Linux) date/time/timezone etc. (and Calculate past/future date/time) in Terminal

Check/Calculate time

Show current time

date
date
date

Calculate past/future time

date --date="1 day ago"
 
date --date="2 hours ago"
 
date --date="3 days"
 
date --date="2 hours"
Calculate dates/time
Calculate dates/time

timedatectl
 
timedatectl status
timedatectl
timedatectl
timedatectl status
timedatectl status

Show/Change timezone

Show timezone

timedatectl list-timezones

Set timezone

timedatectl set-timezone Africa/Abidjan

Change time by using “timedatectl”

(HH:MM:SS, in 24 hour format)

sudo timedatectl set-time 00:00:00
Use timedatectl set-time to change time
Use timedatectl set-time to change time

Change time by using “date”

(HH:MM:SS, in 24 hour format)

sudo date +%T -s "23:00:00"

(12 hour format)

sudo date +%T%p -s "2:00:00AM"
 
sudo date +%T%p -s "2:00:00PM"

Change date

Set the date and time to 03 Feb 2001, 01:00:00

sudo date --set="20010203 01:00:00"
 
sudo timedatectl set-time '2001-02-03 01:00:00'

Set date

sudo timedatectl set-time 2001-02-03
 
sudo date --date="2001-02-03"

Create custom date format (+)

sudo date +"Year : %Y Day : %d Month : %m"
 
# Output
Year : 2001 Day : 03 Month : 02
 
sudo +%D
 
# Output
02/03/01
 
sudo date +"%a %b %d %y"
 
# Output
Sat Feb 03 01
 
sudo date +"%A %B %d %Y"
 
# Output
Saturday February 03 2001
 
sudo date +"%A %B %d %Y %T"
 
# Output
Saturday February 03 2001 00:27:30
 
sudo date +"%A %B-%d-%Y %c"
 
# Output
Saturday February-03-2001 Sat 03 Feb 2001 00:28:17 EST

%D: Year/Month/Day format.

Show CMOS Time

sudo hwclock
hwclock
hwclock

How to: Remove junk file from Linux easily

tmpwatch/tmpreaper is the tool we can use for this purpose. It can be used to remove files and folders which haven’t being used for a specific time. (find command can be used to achieve the same result as well)

By default, tmpwatch/tmpreaper can use access time, inode change time, modification time to remove files.

Usually, tmpwatch/tmpreaper is used to remove files from “/tmp” folder and other folders like old log files.

Warning: Do not run this command within root folder “/”!

1 Installation

# CentOS/RHEL/Fedora
sudo dnf install tmpwatch
 
# Older version of CentOS
sudo yum install tmpwatch
 
# Debian/Ubuntu Kali Linux etc.
sudo apt install tmpreaper
 
# OpenSUSE
sudo zypper install tmpwatch

2 Using tmpwatch/tmpreaper

tmpwatch and tmpreaper have identical commands/switches.

2.1 Remove files which haven’t being accessed over X days

tmpreaper 30d /var/log/

30d = 30 days

d: Days

h: hours

m: minutes

s: seconds

By default, without specifying the unit it is considered as hours (In following example, 24 hours)

# Remove files haven't being accessed over 10 hours
tmpreaper 24 /var/log/

2.2 Remove files which haven’t being modified over X days

tmpreaper -m 30d /var/log/

2.3 Remove symbolic links

tmpreaper -s 1d /var/log/

2.4 Remove all files (Include files, folders and symbolic files)

tmpreaper -a 1d /var/log/

2.5 Skip folder/directory when deleting

tmpreaper -am --nodirs /var/log/

2.6 Test deleting

tmpreaper -t 5d /var/log/

2.7 Force deleting

tmpreaper -f 3d /var/log/

2.8 Skip files when deleting

tmpreaper --protect '*.txt' 3d /var/log/

tmpreaper can be used with cron job, e.g. delete tmp or log file from 90 days ago every night at 2:00.