TIPS &TRICKS
Using the proxy server via the command line
Often administrators 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@ proxyserver:port” export https_proxy=”https://username:password@ proxyserver:port” export ftp_proxy=”ftp://username:password@proxyserver:port” export socks_proxy=”socks://username:password@ proxyserver:port”
This will make all your applications use the proxy to access the Internet.
—Nagaraju Dhulipalla, nagarajunice@gmail.com
Enable the EPEL repository in CentOS/Red Hat
Many a time, we need to install additional packages on GNU/Linux distributions but installing them from unknown repositories 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 distributions. One of the biggest advantages is that the repository is 100 per cent open source and free to use. Additionally, it does not provide any core duplicate packages and has no compatibility 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.fedoraproject.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.fedoraproject.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 repositories.
[root]# yum repolist —Narendra Kangralkar, narendrakangralkar@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 graphically with the user. These include notification, message and text information dialogue boxes.
Shown below is an example of a Zenity text information dialogue box:
$zenity --info --text “good morning” --text-info …displays the text information 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 notifications to the user via a notification daemon from the command line. This is useful to inform the desktop user about an event or display some form of information 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 Successfully….”
where, -t 1000 specifies the timeout in milliseconds (1000 milliseconds = 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 documentation 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 directories, 4 files —Amar Shukla, amarshukla123@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 description 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 description 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 description 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