Category Archives: Linux

You got to love Linux. Not only that it is free, but it is also very strong, stable, and widely used.

Enabling SSH (https) for Apache 2 in Ubuntu/Mint/Possibly other Debian distro

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051# Intall apache $ sudo apt-get install apache2   # Enable SSL module $ sudo a2enmod ssl # Restart Apache $ sudo service apache2 restart # Create a directory to store the SSLCertificateFile and SSLCertificateKeyFile $ mkdir  /etc/apache2/ssl # Generate … Continue reading

Posted in Linux, Ubuntu, Web Development | Leave a comment

Directory sharing between Linux and Windows

1. Sharing/serving a Linux directory to Windows $ sudo apt-get install samba $ sudo smbpasswd -a USERNAME $ mkdir /home/USERNAME/sharedfolder $ sudo vi /etc/samba/smb.conf [sharedfolder] path = /home/USERNAME/sharedfolder available = yes valid users = USERNAME read only = no browsable … Continue reading

Posted in Linux, Operating System, Windows 7 | Leave a comment

Getting the current filename using bash

123456789101112131415$ cat ./testfilename.sh #!/bin/bash fullfile=`basename $0` filename=$(basename "$fullfile") echo "filename:"$filename extension="${filename##*.}" echo "extension:"$extension justfilename="${filename%.*}" echo "justfilename:"$justfilename $ ./testfilename.sh filename:testfilename.sh extension:sh justfilename:testfilename

Posted in Linux, Operating System | Leave a comment

Customize your Vim editor using .vimrc

Quick notes: – imap is for when you are in insert mode – map is when your are in command mode Thus when you are in the insert mode, sometime you need to exit to the command mode first using … Continue reading

Posted in Linux | Leave a comment

Search and replace withing a file

1234567sed -i -e"s/SEARCH_TEXT/REPPLACE_TEXT/g" FILENAME.txt # another example using bakup sed -i.bak -e"s/SEARCH_TEXT/REPPLACE_TEXT/g" FILENAME.txt # another example using variable sed -i -e"s/\/pathname/\/pathname-$date/g" "filename-"$date".xml"

Posted in Bash, Linux, Operating System | Leave a comment

Bash Scripting Basics (Variable Assignment, If, Loop)

12345678910111213141516171819202122232425262728293031#!/bin/bash ################################################## # Benchmark the processing time when wkhtmltopdf # converts an html file to a pdf file ################################################## if [[ $1 = "" || $2 = "" || $3 = "" ]]; then         echo "Usage: … Continue reading

Posted in Bash, Linux | Leave a comment

Compress and Extract Files in Linux

Extract: .tar.bz2 To extract a tar (Tape ARchiver) file, type the following in the shell prompt: 1tar xvjf yourFileName.tar.bz2 Which will untar it to the current directory. Depending on the file structure that being compressed, it might create sub-directories. Parameters: … Continue reading

Posted in Bash, Linux | Tagged | Leave a comment

Remote copy using scp

Do you ever need to copy one file from one server to another? If you have ssh access to the remote server then you can do an scp command like so: 1$ scp remoteUsername@remoteServername:remoteFile localFile

Posted in Linux, Operating System | Tagged | Leave a comment

Delete files older than X number of days in Linux

Say you backup your database daily and you need to delete the old backup files. You can issue the command bellow which will erase any files within the specified directory that are older than 7 days. 1$ find /your/target/directory* -mtime … Continue reading

Posted in Bash, Linux, Operating System | Leave a comment

Calling a mysql query from linux or dos command line

There are times when you want to call a mysql command from the bash or dos script then call this script in a scheduler (cron job). The example below will show you how to do so. 1mysql -uYOURUSERNAME -pYOURPASSWORD -DYOURDATABASE … Continue reading

Posted in Database, Linux, MySQL | Leave a comment