Linux: Add a folder to the PATH

I had to compile a separated version of python to run some software without remove the current version that is dependent of other applications inside the server.

When I tried to install some other dependent libraries of this version of python, It was not found because binary folder was not in the path.

To add the binary folder temporary I did in this way:

Before add it, the PATH looked like this:

$ echo $PATH

/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/courier-imap/sbin:/usr/lib/courier-imap/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/usr/local/puppet/sbin:/usr/local/puppet/bin:/root/bin

To add the folder to my PATH you just need to update the value of path in this way:

$ PATH=$PATH:/usr/local/python2.7/bin
 
Now if you print again the PATH values you will se something like this:

$ echo $PATH 

/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/courier-imap/sbin:/usr/lib/courier-imap/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/usr/local/puppet/sbin:/usr/local/puppet/bin:/root/bin:/usr/local/python2.7/bin

 

 

Rename files in Bash with Regular expresions

Sometimes It’s necessary to rename files following some patterns. Do this task manual is a long task, if you thousand of files. For this reason, I use rename command:

Debug and preview:

$ rename’REGULAR EXPRESSION’ files -n

Execute:

$ rename’REGULAR EXPRESSION’ files

Some of the most common expressions I use are:

Convert filename to lowercase:

$rename ‘y/A-Z/a-z/’ *

Add Prefix to filename:

 

$rename ‘s//text-/’ *.mp3

Remove Suffix:

$rename ‘s/ – text//’ *.mp3

Dynamic Rename

rename ‘s/(.*?)-(.*).mp3/$2-$1.mp3/’ *.mp3

More Information in manual of rename:

$man rename

 

 

NAME
       rename – renames multiple files
SYNOPSIS
       rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]
DESCRIPTION
       “rename” renames the filenames supplied according to the rule specified as the first argument.  The
       perlexpr argument is a Perl expression which is expected to modify the $_ string in Perl for at least
       some of the filenames specified.  If a given filename is not modified by the expression, it will not be
       renamed.  If no filenames are given on the command line, filenames will be read via standard input.
       For example, to rename all files matching “*.bak” to strip the extension, you might say
               rename ‘s/\.bak$//’ *.bak
       To translate uppercase names to lower, you’d use
               rename ‘y/A-Z/a-z/’ *
OPTIONS
       -v, –verbose
               Verbose: print names of files successfully renamed.
       -n, –no-act
               No Action: show what files would have been renamed.
       -f, –force
               Force: overwrite existing files.
ENVIRONMENT
       No environment variables are used.