Ubuntu command line check disk usage

To check hard disk usage on Ubuntu from a terminal (command line), issue the following command  in your terminal.

liping:~$ df -h

-h stands for human which makes it readable by us humans, otherwise the file size will be in bytes:)

After you issue the command, you would  see your disk usage similar to the info given below.

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda7              68G   23G   43G  35% /
udev                   10M     0   10M   0% /dev
tmpfs                 800M  1.6M  798M   1% /run
tmpfs                 5.0M     0  5.0M   0% /run/lock
/dev/sda6             264G  173G   78G  69% /home
tmpfs                 3.2G  992K  3.2G   1% /tmp
.
.
.

For more commonly used Linux commands, check my other posts at here  and here .

Install DB Browser for SQLite on Ubuntu 16.04

This post introduces how to install DB Browser for SQLite on Ubuntu 16.04.

For Ubuntu and derivaties, @deepsidhu1313 provides a PPA with the latest release at here:

https://launchpad.net/~linuxgndu/+archive/ubuntu/sqlitebrowser

Step 1: Add the PPA shown above by issuing the following command in your terminal:

$ sudo add-apt-repository -y ppa:linuxgndu/sqlitebrowser

Step 2: Update the cache using:

$ sudo apt-get update

Step 3: Install the DB Browser for SQLite package by issuing the following command:

$ sudo apt-get install sqlitebrowser

 

Reference:

http://sqlitebrowser.org/

VPN setup on Ubuntu 16.04 (using Cisco AnyConnect client)

This post introduces how to setup VPN on Ubuntu  16.04 LTS using Cisco AnyConnect Client.

Step 1:  Download Cisco AnyConnect client.

Penn Stater can download at here.

Step 2: Extract the file(s) and install as root.

(1) extract the downloaded file;

(2) then cd to the extracted directory where it has an installation .sh file;

(3) then issue the following command to install Cisco AnyConnect Client:

$sudo ./AnyConnectInstall.sh 

# note your .sh file may have slight different name

Step 3:  Run the following command.

$ sudo apt-get install openconnect network-manager-openconnect-gnome

We need to issue this command to  show Cisco Compatible VPN in the list when we open network manager and add a new VPN.

Step 4:  Open Network Manager.

 

Step 5: Add a VPN in the Network Manager

Step6:  Choose Cisco AnyConnect Compatible VPN (openconnect) and click Create.

Step 7: Enter the following info

  • Connection name: Tech Services VPN [Note you can name this as you wish]
  • Gateway: vpn.its.psu.edu  [type in your vpn accordinly]

Click Save.

Step 8: Open Cisco Anyconnect client

Type your VPN address in the connect to textbox, and then enter your username and psw.

Then you are ready to go:)

 

References:

VPN, CISCO AnyConnect, Linux

Cisco VPN client on Ubuntu 16.04 LTS

 

 

 

Read the first line of a file from terminal (on Ubuntu and Mac)

This post introduces how to read the first line of a file from terminal. It works on both Linux (Ubuntu) and Mac OS.

For getting top or bottom 10 files under a director from terminal (on Ubuntu and Mac), check here.

Note: you do not need to install anything, it is built-in on your Ubuntu/Mac OS.

Step 1: open a terminal 

Step 2: cd to the directory where your file (e.g., .txt file) is located 

Step 3: issue the following command

$ head -n 1 example.txt  
# this will read and print the first line of the file in the terminal

$ head -n 2 example.txt 
# this will read and print the first two lines of the file ... you got the idea...

***********************************************

Analogously, see the following command for displaying the last line of a file from terminal:

$ tail -n 1 example.txt # this will read and print the last line of the file in the terminal 

$ tail -n 2 example.txt # this will read and print the last two lines of the file ... you got the idea...

Get top or bottom 10 files under a director from terminal (on Ubuntu and Mac)

This post get top/bottom 10 from the sorted file names in current directory.

For reading the first line of a file from terminal (on Ubuntu and Mac), check here.

Note: you do not need to install anything, it is built-in on your Ubuntu/Mac OS.

Step 1: open a terminal 

Step 2: cd to the directory where your file (e.g., .txt file) is located 

Step 3: issue the following command accordingly

$ ls | head -10

# the pipe symbol (i.e., |) puts the output of the ls command as the input of the head command.

if you would like to get more information of the files, use the following instead:

$ ls -l | head -10

similarly,

if you would like to get the bottom 10 files in the current directory, issue the following command:

$ ls | tail -10

or for detailed information of the files, use

$ ls -l | tail -10

You guessed it, if you would like to get the top/bottom 20, just change the -10 to -20:)

simply, enough, right?

 

For more commonly used Linux commands, check my other posts at here  and here .

Word count in pdf using wc command (on Ubuntu and Mac)

This post introduces how to count the number of words in a pdf file using wc command. It works on both Linux (Ubuntu) and Mac OS.

Note: you do not need to install anything, it is built-in on your Ubuntu/Mac OS.

Step 1: open a terminal 

Step 2: cd to the directory where your pdf file is located 

Step 3: issue the following command

$ ps2ascii example.pdf | wc -w

Step 4: Then you should see the number of words in that example.pdf

 

P.S.   the wc command has several arguments, see below.

wc -l: print the number of lines in a file.

wc -w: print the number of words in a file.

wc -c: print the number of bytes in a file.

wc -m: print the number of characters from a file.

wc -L: print only the length of the longest line in a file.

 

 

 

How to remove the double quotes in a CSV file on Ubuntu

This post introduces the simplest way to remove all double quotes in a csv file on Ubuntu (via terminal).

If you have a CSV file like

#input.csv
"1,2,3,4,9"
"1,2,3,6,24"
"1,2,6,8,28"
"1,2,4,6,30"

and want something like

#output.csv
1,2,3,4,9
1,2,3,6,24
1,2,6,8,28
1,2,4,6,30

Or you have something like this

and want something like this

In your terminal,

cd to the directory where input.csv file is located and then issue the following command:

$ tr -d '"' <input.csv> output.csv

Note: tr stands for translateThe d flag causes tr command to delete all tokens of the specified set of characters from its input.  

References:

8 Linux TR Command Examples (pdf)

tr (Unix)

How to install Visual Studio Code text editor on Ubuntu 16.04

This post introduces how to install the nice text editor Visual Studio Code on Ubuntu.

Step 1: Install gdebi

Open a terminal and type the following command into your terminal.

$ sudo apt-get install gdebi
# use gdebi tool to install external *.deb packages like Visual Studio Code and Google Chrome.
# gdebi will automatically fetch and install all Visual Studio Code dependencies.

Step 2: Download Visual Studio Code

 

In your terminal, cd to the directory where you downloaded the file (for example, in my case, it is in my Downloads folder.)

Step 3: Install Visual Studio Code

$ sudo gdebi code_1.15.1-1502903936_amd64.deb
# your downloaded version might be different from mine, so change it to #your .deb file

Step 4: Click “Search your computer” icon on your tool bar, and type in Visual Studio Code, you will see it’s installed on your Ubuntu.

Step 5: Right click the Visual Studio Code icon on your tool bar and pick Lock to Launcher, your are ready to use your Visual Studio Code editor on your Ubuntu 16.04:)

 

How to install Google Chrome Browser on Ubuntu 16.04

This post introduces how to install Google Chrome Browser on Ubuntu 16.04.

Step 1: Install gdebi

Open a terminal and type the following command into your terminal.

$ sudo apt-get install gdebi
# use gdebi tool to install external *.deb packages like Google Chrome.
# gdebi will automatically fetch and install all Chrome dependencies.

Step 2: Download Google Chrome browser with wget

$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
# use wget command to download a latest version of the Google Chrome browser

Step 3: Install Google Chrome 

$ sudo gdebi google-chrome-stable_current_amd64.deb

Step 4: Click “Search your computer” icon on your tool bar, and type in Chrome, you will see it’s installed on your Ubuntu.

Step 5: Right click the Chrome icon on your tool bar and pick lock to Launcher, your are ready to use your Google Chrome on your Ubuntu 16.04:)

Run a shell script at startup / reboot

This post introduces how to auto run a shell script when your machine reboot.

We can set a crontab for this.

The crontab (short for “cron table”) is a list of commands that are scheduled to run at regular time intervals on your computer system. The crontab command opens the crontab for editing, and lets you add, remove, or modify scheduled tasks.

Just have a line added to your crontab.

Make sure the sh file is executable (you can use the following command to make the file executable)

$ chmod +x /path_to_you_file/your_file

To edit crontab file, enter the following command in your terminal:

$ crontab -e
# Edit your crontab.

The line you need to add:

@reboot  /path_to_you_file/your_file

for example,

@reboot  /home/user/test.sh

after every startup it will run the test.sh script.

To save and exit your crontab from vim,

 

Use the following command to confirm that it is actually been set.

$ crontab -l
# Display ("list") the contents of your crontab.

this will show @reboot sh $HOME/test.sh

To see whether the app that the .sh starts is actually running, you can use ps -ef (check here for more details about ps -ef).

Reboot the server to confirm whether it all works.

References:

Linux crontab command (PDF)

Linux at, batch, atq, and atrm commands (PDF)

How to run a shell script at startup (PDF)