Installing Google Chrome web browser on Ubuntu 20.04 Focal Fossa step by step instructions

This post provides step by step instruction for how to install Google Chrome web browser  on Ubuntu 20.04LTS from terminal.

Step 1: First install the gdebi and wget packages. By using gdebi to install Google Chrome browser we also ensure that any possible package prerequisites are met during the installation:

$ sudo apt install gdebi-core wget

Step2: Download the Google Chrome browser package:

$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

Step3: Use gdebi command to install the downloaded Google Chrome package from Step 3 above:

$ sudo gdebi google-chrome-stable_current_amd64.deb

Step 4: Check whether google chrome installed successfully

$ google-chrome --version

If you see something like the following, that means your installation is successful.

Google Chrome 86.0.4240.111

 

Install and use htop on Ubuntu 16.04 Desktop and Server

This post introduces an interactive tool for visually monitoring the memory and process usages of your Ubuntu 16.04 Desktop or Server in real time.

  • What is Htop?

Htop is an interactive system-monitor process-viewer and process-manager. It is designed as an alternative to the Unix program top. It shows a frequently updated list of the processes running on a computer, normally ordered by the amount of CPU usage. Unlike top, htop provides a full list of processes running, instead of the top resource-consuming processes. Htop uses color and gives visual information about processor, swap and memory status.

  • Install Htop on Ubuntu 16.04 LTS Desktop and Server

(This works on both an Ubuntu 16.04 Desktop and  Server.)

Installing htop package on Ubuntu 16.04 (Xenial Xerus) is as easy as running the following command on terminal:

Step 1. First make sure that all your system packages are up-to-date by running these following apt-get commands in the terminal.

$ sudo apt-get update

Step 2. Installing Htop. Install htop process monitoring tool using apt-get command:

$ sudo apt-get install htop
  • Use Htop to monitor your Ubuntu 16.04 LTS Desktop and Server in real-time

Now that htop is installed on your server you’ll want to start the program by running the following in a command prompt:

$ htop

This will open the program and you’ll see something similar to the following:

Leave this terminal open, you can use CTRL + ALT + T  to open another new terminal for your other work. Then htop will help you monitor your memory usage in real-time:)  Enjoy!

tmux resources

This post provides a brief introduction to tmux and some commonly used commands and useful resources about tmux.

(Thanks Davide for recommending such a handy tool to me.)

(Stay tuned — I will update this post while I am gaining new skills about tmux.)

======What is tmux?

According to the tmux authors:

tmux is a terminal multiplexer. What is a terminal multiplexer? It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal. And do a lot more.

 

====== tmux sessions, windows, and panes explained

One of these features is the ability to break your session into more discreet components, called windows and panes. These are good for organizing multiple varied activities in a logical way.

Let’s look at how they relate to each other.

Nesting

tmuxnesting

tmux sessions have windows, and windows have panes. Below you can see how how they are conceptualized:

  • Sessions are for an overall theme, such as work, or experimentation, or sysadmin.
  • Windows are for projects within that theme. So perhaps within your experimentation session you have a window titled noderestapi, and one titled lua sample.
  • Panes are for views within your current project. So within your sysadmin session, which has a logs window, you may have a few panes for access logs, error logs, and system logs.

It’s also possible to create panes within a session without first creating a separate window. I do this sometimes. Hopefully it isn’t as horrible as it sounds right after reading about nesting.

Q about differences between sessions and windows and panes:

Can someone explain how they use sessions and windows and panes?
It feels like one too many levels, why both sessions AND windows?
I’m willing to believe there is a use case, but for the life of me I can’t come up with one.

A: 

I use sessions for different projects, and windows and panes within a project. For example, I’ll have a session for my puppet code, and a session for a bash script I’m working on. Within the puppet session, if I’m going to work on a new module, I open a new window. If I’m writing code in vim, I usually split off a pane so I can test running it next to it. Having the error output next to the code makes debugging really fast.

In a lot of ways, it basically acts like a tiling window manager for the terminal. The advantage over a window manager is that the whole layout can be accessed remotely. So if I’m working on a project from work, I can quickly resume working on the project from my home computer after SSH’ing in and reattaching to the tmux session.

 

====== see below for commonly used tmux comands

By default, tmux uses Ctrl-b as its shortcut activation chord, which enables you perform a number of functions quickly.

  • Switch between different windows

Ctrl – b (presee the  ctrl and b keys at the same time and release them at the same time, and then immediately press window number)  window number

  • Cursor move within an active window

Ctrl-b (release the keys, and immediately press the “[” key ) the key with “[“.

when you see the cursor becomes a solid flashing diamond, you can use arrow key to move your cursor in the active terminal window.

Note: Press “q” to exit the cursor move mode.

  • Session management
  • s list sessions
  • $ rename the current session # default session name and window name is number, can rename session names to meaningful ones
  • d detach from the current session

tmux is developed on a client-server model which means that the session is stored on the server and persist beyond ssh logout.

The following command will create a new session called mysession:

tmux new-session -s mysession

To attach to a session run:

tmux attach -t mysession

To list all session run:

tmux ls

You can kill a session using the following command:

tmux kill-session -t mysession

you can grossly kill all tmux processes with the following command:

pkill -f tmux

Frequently used sessions commands

Ctrl-b d	  Detach from the current session 
Ctrl-b (          Go to previous session
Ctrl-b )          Go to next session
Ctrl-b L          Go to previously used session
Ctrl-b s          Choose a session from the sessions list

Ctrl + D    — exit tmux from terminal.

  • Windows (tabs) Management

Each session can have multiple windows. By default all windows are numbered starting from zero.

Frequently used windows (tabs) commands

Ctrl-b 1  Switch to window 1
Ctrl-b c  Create new window
Ctrl-b w  List all windows
Ctrl-b n  Go to next window
Ctrl-b p  Go to previous window
Ctrl-b f  Find window
Ctrl-b ,  Name window
Ctrl-b w  Choose a window from the windows list
Ctrl-b &  Kill the current window

 

  • One of the handy things about tmux is how easy it is to resize panes:

Ctrl +b, followed by holding down Alt, and using the arrow keys to resize.

 

======things about how to save sessions and recover sessions.

If you reboot you computer you will lose the sessions. Sessions cannot be saved. But, they can be scripted. What most do in fact is to script some sessions so that you can re-create them.

======Installing tmux

  • Installation with sudo privilege

Installation is pretty straightforward if you have Ubuntu or any other Debian-based distribution you can install tmux with:

sudo apt-get install tmux

on CentOS/Fedora:

yum install tmux

and on MacOS:

brew install tmux

Note: check the comments for some up-to-date scripts.

 

References and further reading list

This tutorial covers installation of tmux and some commonly used commands.

This is a pretty good introduction to tmux, it includes why tmux and the comaprision between tmux and screen, as well as some tmux shortcuts

 

 

 

Get the number of CPUs/cores in Linux from the command line

This post introduces how to find out the number of CPUs/cores on Linux machines from command line.

  • method 1:

$ nproc –all

20   # this means there are 20 cores on the linux machine.

  • method 2:

$ lscpu

CPU(s):                20

On-line CPU(s) list:   0-19

Thread(s) per core:    2

Core(s) per socket:    10

 

 

Commonly used Linux commands (Ubuntu)

This page lists commonly used Linux commands to help those who are not very familiar with Linux command environment. I have been collecting and recording those from my experience.

I was once a beginner, so I can understand the pain for Linux beginners. I have not yet seen any post that has done comprehensive collection of commands on Linux, so I thought I could help this out. That is why you see this post. Here you go. Happy Learning!

You can see further reading list at the end of this post.

Note: Do not contain space in your filename or directory name, use underscore instead of space.

======Basic commands:

  • cd 

this command will goes back to the home directory of your account, no matter where your current directory is located in your terminal.

  • cd ../

this command will go to the parent directory of your current directory in terminal

  • rmdir 

remove/delete an empty folder.

example:

first cd into the parent folder of the empty folder to remove

rmdir test

  • rm -rf ./*

    first cd to a directory, and this command will empty all of things under the current directory

  • ls  

list all the files and folders under current path

  • ls -l  

list all the files and folders with details like dates.

  • ls -l -t

list files and folders ordered by time.

  • ls -ltrh 

list all the csv files under the current directory in long format by time and in reverse order, the file size in human readable format (e.g., in mb, or gb, instead of byte size)

  • -l List in long format. If the output is to a terminal, a total sum for all the file sizes is output on a line before the long listing.
  • -r Reverse the order of the sort to get reverse lexicographical order or the oldest entries first (or largest files last, if combined with sort by size.
  • -t Sort by time modified (most recently modified first) before sorting the operands by lexicographical order.
  • ls -ltrh *.csv

list all the csv files under the current directory in long format by time and in reverse order, the file size in human readable format (e.g., in mb, or gb, instead of byte size)

  • find

find -name ‘*.jpg’ -exec cp {} ./test/ \;

Find all jpg files  and then copy the found files to the folder test which is subfolder of current path.
Note that: the current path should be the path where the files to search are located. (i.e., use cd to locate to the directory where the files are in before type in the cmd below into terminal.)

  • rm -r -f

-r means recursive, it will remove folders and subfolders and files within the folders and subfolders

-f means force

  • mkdir [folder name]

create new folder

example:

mkdir image

  • cp [filename] [new filename]

copy and rename file

  • cp [filename] [path/to/new/lotcation/filename]

copy the file to another location

if you use this commond to copy a directory, you would meet this error:

cp: omitting directory ...

The error notice means you told cp to copy files and not directories. The warning is about cp finding a directory and informing you it will be skipped.

  • cp -r [directory] [path/to/new/location/directory]

copy a directory to another location.

cp -r means recursive and this option will make cp also include sub-directories.

If you meet permission denied error, add sudo before the command, and it will ask your password.

  • mv [directory] [path/to/new/location/directory]

If you meet permission denied error, add sudo before the command, and it will ask your password.

  • nano [new file name or /path/to/new file/new file name]

example:

nano  myexample   #it will create a new empty file named “myexample” under the current directory

  • nano [file name]

If the file name already exists, it will open the file and you can edit it.

Note: Ctrl+O to save the file, and then hit Enter, and then Ctrl +X to close the file.

 

 

======More advanced commands:

  • cd into directory without having permission

When cd into a directory and the following error occurs

bash: cd: your-dirctory: Permission denied

The solution is:

Enter super user mode, and cd into the directory that you are not permissioned to go into. Sudo requires administrator password.

sudo su  
cd directory  # you will notice that your prompt changes after your enter your root password. now you can cd to the directory.

# to exit "super user" mode, type exit.
  • lspci

check GPU information on Ubuntu

look for “VGA compatible controller:”…

  • sudo nvidia-smi

check GPU info and GPU usage.

  • sudo reboot -h now

reboot a server from terminal

  • sudo shutdown -h now

shut down a server from terminal

Note: If your Ubuntu Server 16.o4 LTS has Black Screen after reboot or shut down, try pressing (simultaneously) Ctrl + Alt + F2 to see whether you can switch to different console

  • vncserver -kill :1  

This is a vncserver command. It is used to kill a port of a GUI by VNC server, where 1 is the port you would like to kill.

  • vncviewer -via username@yourserver_hostname :1

connect to a server via vncviewer from a linux-based client. you need to change the port number 1 to yours.

echo is a built-in command in the bash and C shells that writes its arguments to standard output.

See here, and here, and herefor example usage of it.

  • cat

See here for example usage of cat command.

  • chmod

see here for example usage of chmod command.

 

  • check supercomputing Cluster’s Linux distribution and version

$ lsb_release -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID:    RedHatEnterpriseServer
Description:    Red Hat Enterprise Linux Server release 6.4 (Santiago)
Release:    6.4
Codename:    Santiago

  • show the list of top processes ordered by RAM and CPU  use in descendant form

(remove the pipeline and head if you want to see the full list):

$ ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head

Brief explanation of the options used in the command above:

— The -o (or –format) option of ps allows us to specify the output format.

— the processes’ PIDs (pid), PPIDs (pid)

— the name of the executable file associated with the process (cmd), and

— the RAM and CPU utilization (%mem and %cpu, respectively).

We can use --sort to sort by either %mem or %cpu. By default, the output will be sorted in ascendant form, but usually we prefer to reverse that order by adding a minus sign in front of the sort criteria to make it list in descendant.

To add other fields to the output, or change the sort criteria, refer to the OUTPUT FORMAT CONTROL section in the man page of ps command.


======File Transfer: getting files to/from your account on a server

  • On Linux generally the command line scp command.
 Examples of using the command line are:

scp -p file_name username@yourserver_hostname:destination/directory

  • or for a full directory tree:

scp -pr dir_name username@yourserver_hostname:destination/directory

 

Note that if you want to transfer files from server to your client computer, just reverse the directory.

e.g., scp -pr username@yourserver_hostname:source/directory dir_name_on_your_client

 

======download files

  • wget (tool for downloading files)  (pdf)
  • See Linux wget command (pdf), which provides detailed and comprehensive different tags (options) to use with wget command.

======Save terminal output to a file

  • sudo command -option | tee logThis command will show output on terminal and save to a file at the same time.
  • Save terminal output to a fileredirect the output to a file: someCommand > someFile.txt Or if you want to append data: someCommand >> someFile.txt If you want stderr too use this: someCommand &> someFile.txt or this to append:  someCommand &>> someFile.txt
  • Tail -f log.txt

Python related commands:

  • enter python environment

type python in terminal, and it will show python 2.7 version info and also enter into python 2 environment

  • enter python 3 environment

python3 

and it will show python 3 version info (e.g., python 3.5.2) and also enter into python 3 environment.

 

======Git related commands

  • git clone the url to gitclone

for example:

first cd into the folder you want the models to be cloned to in your terminal, and then issue this command. it will clone the model foder from https://github.com/tensorflow/models under your current folder in your terminal.

git clone https://github.com/tensorflow/models

 

======Some useful shortcuts on linux

  • you can open multiple terminals

open each terminal by pressing Ctrl + Alt + T.

  • Shortcut to bring all open terminals to the front

After you bring one terminal window in the front, press Alt+~ to bring all other terminal windows in the front one by one:

  • CTRL + C − terminate the current command. 

======References and further reading list:

Linux and Unix top 10 command pages  (See here for links to more commands intro)

Below is a listing of the top 10 Unix command pages by the amount of times they have been accessed on the Computer Hope server.

  1. Linux and Unix tar command help
  2. Linux and Unix chmod command help
  3. Linux and Unix ls command help
  4. Linux and Unix find command help
  5. Information about the Linux and Unix grep command
  6. Linux and Unix cp command help
  7. Linux and Unix vi command help
  8. Linux and Unix ifconfig command help
  9. Linux and Unix date command help
  10. Linux and Unix kill command help

======TOC of the nice tutorial: Linux Shell Commands: A Tutorial Quick Reference for Desktop Users

Table of Contents

1. A Short Intro to the Command Line

This chapter will acquaint you with the basics of the command line. To maximize your learning, you should follow along by typing in the example commands given. Every major Linux distribution has a menu item called “shell”, “console”, “terminal” or the like, which will give you a window with a command line interface. In this book, I assume that readers work in a graphical desktop environment and use the Bash shell in a terminal window. Bash is the default shell in all major Linux distributions.

2. Getting Information

The commands presented in this chapter provide valuable information on the state and configuration of your system.

3. Managing Files and Directories

The command line offers you great flexibility in creating, copying, moving and editing files and directories, as this chapter shows.

  • cd (change directory)  (pdf)
  • chgrp (change group ownership)  (pdf)
  • chmod (change file permissions)  (pdf)
  • chown (change file ownership)  (pdf)
  • cp (copy files and directories)  (pdf)
  • dd (write data to devices)  (pdf)
  • find (search for files)  (pdf)
  • ln (make links between files)  (pdf)
  • locate (find files by name)  (pdf)
  • mkdir (create a directory)  (pdf)
  • mount (mount file systems)  (pdf)
  • mv (rename files)  (pdf)
  • rm (remove files or directories)  (pdf)
  • rmdir (remove empty directories)  (pdf)
  • shred (delete a file securely)  (pdf)
  • touch (change file timestamps)  (pdf)
  • umount (unmount file systems)  (pdf)

4. Managing Processes

Linux provides powerful tools for controlling the execution of your programs. Some of the most important tools are presented in this chapter.

  • disown (detach a job from the shell)   (pdf)
  • kill (terminate a process)  (pdf)
  • ps (list running processes)  (pdf)
  • pstree (display a tree of processes)  (pdf)
  • shutdown (halt or reboot the system)  (pdf)
  • sudo (execute a command as root)  (pdf)

5. Working with Text

Processing plain text files is a big strength of Linux. The commands presented in this chapter allow you to display particular parts of files (e.g. head, tail), reorder their contents (e.g. sort), carry out search/replace operations (e.g. grep, sed), and much more.

  • cat (concatenate and output files)  (pdf)
  • cut (output columns from files)  (pdf)
  • diff (show differences between files)  (pdf)
  • grep (print lines matching a pattern)  (pdf)
  • head (output the first part of files)  (pdf)
  • less (view file by pages)  (pdf)
  • pdftk (manipulate PDF files)  (pdf)
  • sed (search and replace text)  (pdf)
  • sort (sort lines of text files)  (pdf)
  • tail (output the last part of files)  (pdf)
  • wc (count lines, words and characters)  (pdf)

6. Being Productive

This chapter collects some commands that can help you accomplish everyday tasks quickly and efficiently. Many of the commands are faster or more reliable replacements for popular graphical applications. For example, wget can replace a graphical download manager.

  • alias (define command shortcuts)  (pdf)
  • alsamixer (audio mixer)  (pdf)
  • bc (command line calculator)  (pdf)
  • history (display command history)  (pdf)
  • rsync (fast, versatile file copying tool)  (pdf)
  • tar (Linux archiving utility)  (pdf)
  • unrar (extract files from RAR archives)  (pdf)
  • unzip (extract files from ZIP archives)  (pdf)
  • wget (tool for downloading files)  (pdf)
  • xmodmap (change key bindings)  (pdf)

======The end of the TOC of the nice tutorialLinux Shell Commands: A Tutorial Quick Reference for Desktop Users

======apt-get usages

======curl command examples

cURL can be used in many different and useful ways. Using cURL, we can download, upload and manage files, check email address, or even update status on some of the social media websites or check the weather outside.

cURL is very useful command line tool to transfer data from / to a server. cURL supports various protocols, including FILE, HTTP, HTTPS, IMAP, IMAPS, LDAP, DICT, LDAPS, TELNET, FTP, FTPS, GOPHER, RTMP, RTSP, SCP, SFTP, POP3, POP3S, SMB, SMBS, SMTP, SMTPS, and TFTP.

This tutorial covers five of the most useful and basic uses of cURL tool:

–Check URL

One of the most common and simplest uses of cURL is typing the command itself, followed by the URL you want to check

curl https://example.com
#This command will display the content of the URL on your terminal

–Save the output of the URL to a file

The output of the cURL command can be easily saved to a file by adding the -o option to the command, as shown below

curl -o website https://example.com
#the output will be save to a file named ‘website’ in the current working directory

–Download files with cURL

curl -O https://example.com/file.zip

# the -O option used for saving files to current working directory without renaming
# e.g.,  the ‘file.zip’ zip archive will be downloaded to the current working directory.
curl -o archive.zip https://domain.com/file.zip

# the ‘file.zip’ archive will be downloaded and saved as ‘archive.zip’.
curl -O https://domain.com/file.zip -O https://domain.com/file2.zip

# cURL can be also used to download multiple files simultaneously
#cURL can be also used to download files securely via SSH

curl -u user sftp://server.domain.com/path/to/file

# Note that the full path of the file to be downloaded is required

–Get HTTP header information from a website

You can easily get HTTP header information from any website you want by adding the -I option (capital ‘i’) to cURL.

curl -I http://example.com

–Access an FTP server

#  access your FTP server with cURL 
curl ftp://ftp.domain.com --user username:password

# cURL will connect to the FTP server and list all files and directories in user’s home directory
curl ftp://ftp.domain.com/file.zip --user username:password
# download a file via FTP using curl
curl -T file.zip ftp://ftp.domain.com/ --user username:password
# upload a file to  the FTP server

–check cURL manual page to see all available cURL options and functionalities

man curl

This post covers detailed and comprehensive explanation of different options to use with curl command.

  • $ free -m

Linux has the habit of caching lots of things for faster performance, so that memory can be freed and used if needed.

  • $ cat /proc/meminfo
  • $ vmstat -s