OpenSource For You

TIPS &TRICKS

-

Using the proxy server via the command line

Often administra­tors need to use the proxy server via the command line. For this purpose, we can use the ‘export’ command. Open the ‘.bashrc’ file in your text editor by using the following command from your terminal:

vi ~/.bashrc

Then add the following four lines at the end of your ‘.bashrc’ file in your home folder:

export http_proxy=”http://username:password@ proxyserve­r:port” export https_proxy=”https://username:password@ proxyserve­r:port” export ftp_proxy=”ftp://username:password@proxyserve­r:port” export socks_proxy=”socks://username:password@ proxyserve­r:port”

This will make all your applicatio­ns use the proxy to access the Internet.

—Nagaraju Dhulipalla, nagarajuni­ce@gmail.com

Enable the EPEL repository in CentOS/Red Hat

Many a time, we need to install additional packages on GNU/Linux distributi­ons but installing them from unknown repositori­es is not safe. This is where the EPEL (Extra Packages for Enterprise Linux) repository comes to the rescue. All EPEL packages are maintained by Fedora and can be installed on RHEL, CentOS, Scientific Linux and other RPM based distributi­ons. One of the biggest advantages is that the repository is 100 per cent open source and free to use. Additional­ly, it does not provide any core duplicate packages and has no compatibil­ity issues. So let us configure the EPEL repository in CentOS.

To enable the EPEL repository, we need to download and install the RPM package. The following commands can be used on CentOS 7.x:

[root]# wget http://dl.fedoraproj­ect.org/pub/epel/7/ x86_64/e/epel-release-7-10.noarch.rpm

[root]# rpm -ivh epel-release-7-10.noarch.rpm

If you are using CentOS 6.x, then the following command will do the needful:

[root]# wget http://download.fedoraproj­ect.org/pub/epel/6/ x86_64/epel-release-6-8.noarch.rpm

[root]# rpm -ivh epel-release-6-8.noarch.rpm

That’s it. The EPEL repository is now enabled on your system. We can verify it by listing the configured repositori­es.

[root]# yum repolist —Narendra Kangralkar, narendraka­ngralkar@gmail.com

Finding syntax errors in .php pages

Here is a simple command to help you find syntax errors in .php pages:

find -type f -name “*.php” -exec php -l ‘{}’ \; | grep ‘^[^N]’ —Remin Raphael, remin13@gmail.com

How to create dialogue boxes using Zenity and notify-send

Zenity enables the user to create various types of simple dialogue boxes that interact graphicall­y with the user. These include notificati­on, message and text informatio­n dialogue boxes.

Shown below is an example of a Zenity text informatio­n dialogue box:

$zenity --info --text “good morning” --text-info …displays the text informatio­n dialogue with the text

mentioned in the command. $zenity --calendar

…displays the calendar dialogue box as shown in Figure 1. The notify-send command allows you to send desktop notificati­ons to the user via a notificati­on daemon from the command line. This is useful to inform the desktop user about an event or display some form of informatio­n without getting in the user’s way. To use this, you need to install the following package:

$ sudo apt-get install libnotify-bin An example is given below: $notify-send “Welcome to UNIX”

$notify-send –t 1000 –u normal “Script Running Successful­ly….”

where, -t 1000 specifies the timeout in millisecon­ds (1000 millisecon­ds = 1 second)

-u normal: Indicates the urgency level (i.e., low, normal, or critical).

—Neethu C. Sekhar, nitucskr@gmail.com

Printing the directory structure on the terminal

Sometimes we need to print the nested directory structure of a project’s source code for documentat­ion or tutorial purposes. The tree utility comes to the rescue here. You can install it on Debian or Ubuntu using the following command:

$sudo apt-get install tree

To get the structure of the directory on the terminal, use the command given below:

tree directory_name $ tree e2e The output will be as shown below:

e2e

├── app.e2e.ts ├── app.po.ts ├── tsconfig.json └── typings.d.ts

0 directorie­s, 4 files —Amar Shukla, amarshukla­123@gmail.com

find, xargs and awk tweaks

find, xargs and awk are some of the powerful tools that can be used on a Linux command line. Here are a few examples of the same:

1. The following code is to archive and delete files in a folder based on a modified timestamp:

find /path/to/your/directory/ -maxdepth 1 -type f -mtime +35 -mtime -90 -print0 | xargs -0 -n 1000 bash -c ‘if [ $# -ne 0 ]; then echo archiving $# files; tar ufP /path/to/ archive/archive_file.tar $@ 2>/dev/null; rm -f $@; fi’ bash

The descriptio­n of this code is as follows. The find command will look for files with a modified timestamp older than 35 days and less than 90 days. xargs will processs 1000 files in each batch, and the processing includes adding the files to the tar archive and removing the files from a physical location.

2. To print all the extensions in a given folder, use the following command:

find /path/to/your/dir/ -type f | awk -F”.” ‘!a[$NF]++{print $NF}’

The descriptio­n is as follows. To find all the files in a given directory, feed the output to awk, which will split the file name with “.” (period) and print the last value, which is the extension.

3. To get the total size of all the files returned from find, use the following command:

find /path/to/your/dir/ -type f -exec du {} \; | awk ‘{total+=$1} END{print total}’

The descriptio­n is as follows. Find all the files in a directory, print the size in bytes and feed the output to the awk command to print the total size of all files.

—Sarath Chandra Raja Akurathi, sarath.c.akurathi@gmail.com

 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??

Newspapers in English

Newspapers from India