Listing directory in Graphical format in Bash

ls -R | grep “:$” | sed -e ‘s/:$//’ -e ‘s/[^-][^/]*//–/g’ -e ‘s/^/   /’ -e ‘s/-/|/’

Script from centerkey.com: http://www.centerkey.com/tree/tree.sh

#!/bin/sh
#######################################################
#  UNIX TREE                                          #
#  Version: 2.3                                       #
#  File: ~/apps/tree/tree.sh                          #
#                                                     #
#  Displays Structure of Directory Hierarchy          #
#  ————————————————-  #
#  This tiny script uses “ls”, “grep”, and “sed”      #
#  in a single command to show the nesting of         #
#  sub-directories.  The setup command for PATH       #
#  works with the Bash shell (the Mac OS X default).  #
#                                                     #
#  Setup:                                             #
#     $ cd ~/apps/tree                                #
#     $ chmod u+x tree.sh                             #
#     $ ln -s ~/apps/tree/tree.sh ~/bin/tree          #
#     $ echo “PATH=~/bin:${PATH}” >> ~/.profile      #
#                                                     #
#  Usage:                                             #
#     $ tree [directory]                              #
#                                                     #
#  Examples:                                          #
#     $ tree                                          #
#     $ tree /etc/opt                                 #
#     $ tree ..                                       #
#                                                     #
#  Public Domain Software — Free to Use as You Like  #
#  http://www.centerkey.com/tree  –  By Dem Pilafian  #
#######################################################
echo
if [ “$1” != “” ]  #if parameter exists, use as base folder
   then cd “$1”
   fi
pwd
ls -R | grep “:$” |  
   sed -e ‘s/:$//’ -e ‘s/[^-][^/]*//–/g’ -e ‘s/^/   /’ -e ‘s/-/|/’
# 1st sed: remove colons
# 2nd sed: replace higher level folder names with dashes
# 3rd sed: indent graph three spaces
# 4th sed: replace first dash with a vertical bar
if [ `ls -F -1 | grep “/” | wc -l` = 0 ]   # check if no folders
   then echo ”   -> no sub-directories”
   fi
echo
exit

Add it to your system. Please watch out the code before running it!

curl http://www.centerkey.com/tree/tree.sh > /usr/bin/tree
chmod +x /usr/bin/tree 

 http://stackoverflow.com/questions/3455625/linux-command-to-print-directory-structure-in-the-form-of-a-tree

Compare 2 directory in Linux

Let’s make an example. Create 2 folder and put files in it

mkdir dir{1,2}
touch dir1/{1,2,3,4,5,6}.txt
touch dir2/{2,4,5,7,9}.txt

ls -R dir1
dir1:
1.txt  2.txt  3.txt  4.txt  5.txt  6.txt

ls -R dir2
dir2:
2.txt  4.txt  5.txt  7.txt  9.txt

diff -r dir1 dir2
Only in dir1: 1.txt
Only in dir1: 3.txt
Only in dir1: 6.txt
Only in dir2: 7.txt
Only in dir2: 9.txt

http://stackoverflow.com/questions/16787916/difference-between-2-directories-in-linux

Ubuntu Change Date from IST to ICT

If you try to change your clock, NTP setting and sync to hardware clock but the date still wrong so here’s how

#date
Thu Nov 27 08:16:23 IST 2014  #wrong date time

#dpkg-reconfigure tzdata
Current default time zone: ‘Asia/Ho_Chi_Minh’
Local time is now: Thu Nov 27 09:48:02 ICT 2014.
Universal Time is now: Thu Nov 27 02:48:02 UTC 2014.

#date
Thu Nov 27 09:48:09 ICT 2014  #correct now

Ubuntu Network Manager cannot connect to WPA2/PEAP/MSCHAPv2 network without CA_Certificate

Quick way to fix all the Wireless network that require Certificate, you don’t have to provide your certificate.
Use incrontab to pull the trigger automatically when you connect to Wireless network that require Certificate, the script will add a mozilla External Root Certificate when your Network Manager create Wireless SSiD connection on /etc/NetworkManager/system-connections/

sudo -i
incrontab -e
/etc/NetworkManager/system-connections/ IN_CREATE sleep 3; grep -rl ‘system-ca-certs=true’ /etc/NetworkManager/system-connections/ | xargs sed -i ‘/system-ca-certs=true/a ca-cert=/usr/share/ca-certificates/mozila/AddTrust_External_Root.crt’

Customize default desktop environment settings for Gnome-centric Linux distributions

Customize default desktop environment settings for Gnome-centric Linux distributions

Some of you are probably wondering why would you want to spend your time fiddling with default desktop environment settings customization, when you can easily customize everything to your liking inside you own user account? Most probably you’d want to do this when you’re re-mastering your favorite Linux distribution using tools like OS4 system imager (fork of the now discontinued Remastersys) or Relinux. In this article I’ll show you how to handle this task elegantly using GSettings vendor overrides.

Introduction

First some background. GSettings provides a convenient API for storing and retrieving application settings, similar to system registry inside one of the popular proprietary operating system. Applications can define key/value pairs their application is using by installing .gschema.xml files, and then use GSettings API to manipulate the values. GSettings also provides mechanisms for distribution vendors to override default key/value pairs for specific applications by using .gschema.override files.

Pick the right schema file

First thing we need to do is picking the key/value pair which controls the setting whose defaults we want to modify. We do this using command line tools like “gsettings list-schemas” or “gsettings list-recursively” or using GUI tools like “dconf-editor”. For the sake of simplicity and to better illustrate this process, in this article I’ll use dconf-editor. On a Debian based distributions like Ubuntu we will find dconf-editor inside dconf-tools package:

sudo apt-get install dconf-tools

Now that we have all the tools lets imagine we want to change default fonts our Gnome-centric desktop environment like Gnome 3, Unity or Cinnamon is using. Using dconf-editor we can edit settings for current user account, but most importantly find GSettings schemas and key/value pairs we’re interested in:

org.gnome.desktop.interface

  • font-name
  • document-font-name
  • monospace-font-name

org.gnome.desktop.wm.preferences

  • titlebar-font

Here’s screenshot displaying one section of org.gnome.desktop.interface schema inside dconf-editor:

 

Create .gschema.override file

Now when we have all of the information we can use our favorite editor to create the .gschema.override file:

sudo nano /usr/share/glib-2.0/schemas/60_our-own.gschema.override

The 60 is override priority, here I usually use 60 because most Linux distribution vendors use priority of 50 or less. Now we place following inside that file:

[org.gnome.desktop.interface]font-name=’Ubuntu 12′ document-font-name=’Sans 12′ monospace-font-name=’Ubuntu Mono 14′
[org.gnome.desktop.wm.preferences] titlebar-font=’Ubuntu Bold 12′

We exit and save using Ctrl^X and then compile GSettings schemas to reflect our changes like this:

sudo glib-compile-schemas /usr/share/glib-2.0/schemas/

After system restart desktop environment for all new users and existing users who haven’t changed desktop environment fonts will use fonts we have specified inside our .gschema.override file. This way we can easily tweak almost every aspect of our desktop environment interface, and in the end easily create our own flavor of the Linux distro using remastersys-like tools. That’s what I call flexible operating system, don’t you agree?

How I customize My Cinnamon

gsettings set org.cinnamon.desktop.background picture-uri file:///usr/share/backgrounds/myWallpaper.jpg
gsettings set org.cinnamon.desktop.background picture-options stretched
gsettings set org.cinnamon.settings-daemon.peripherals.touchpad disable-while-typing true
gsettings set org.cinnamon.settings-daemon.peripherals.touchpad motion-acceleration 2
gsettings set org.cinnamon.settings-daemon.peripherals.touchpad motion-threshold 2
gsettings set org.cinnamon.settings-daemon.peripherals.touchpad scroll-method two-finger-scrolling
gsettings set org.cinnamon.settings-daemon.peripherals.touchpad tap-to-click true
gsettings set org.cinnamon.settings-daemon.peripherals.touchpad touchpad-enabled true

How to add your shorcut to Cinnamon

Enable PHP 5.5 Opcache on Ubuntu 14.04 with Nginx and PHP-FPM

OPcache improves PHP performance by storing precompiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request.

Making the switch from APC to Opcache now that it’s standard with Ubuntu 14.04. All the tutorials seemed to be on Apache so thought I’d share what I did. The first change and restarting php I believe is all you need to do while the other changes are for performance and will vary based on your needs. If others have recommendations or additional advice please pipe in!

sudo vim /etc/php5/fpm/php.ini

Change:

;opcache.enable=0 to opcache.enable=1

Change:

;opcache.memory_consumption=64 to opcache.memory_consumption=128

Change:

;opcache.max_accelerated_files=2000 to opcache.max_accelerated_files=4000

Change:

;opcache.revalidate_freq=2 to opcache.revalidate_freq=60

Then restart:

sudo service php5-fpm restart
sudo service nginx restart