How to activate a virtual environment via Bash

Create a file named anything.sh and make it executable Paste following code in file Run ./path-to-file.sh cd path/to/env/dir && source bin/activate

November 11, 2021 · 1 min · 21 words · Saqib Razzaq

How to Import All CSV Files in Directory in MySQL via Bash

Create a file import.sh and make it executable Paste following code in file mysqluser='root' mysqlpass='password' mysqldb='database_name' tablename='mysql_table_name' DIRECTORY='input_directory' for csv in $DIRECTORY/*.csv; do echo "Loading $csv" mysql -u $mysqluser --password=$mysqlpass -D $mysqldb -e "LOAD DATA INFILE '$csv' IGNORE INTO TABLE $tablename FIELDS TERMINATED BY '\t' ENCLOSED BY '\"' LINES TERMINATED BY '\n' IGNORE 1 LINES;" done

November 11, 2021 · 1 min · 56 words · Saqib Razzaq

How to quickly login to MySQL using Bash

I know this method isn’t the most secure way. But when I’m working on personal projects, it gets annoying having to enter credentials every time. Hence, I put together this little script to quickly log me in. I create file mysql.sh with following contents mysql -u username --password='password_here'

November 11, 2021 · 1 min · 48 words · Saqib Razzaq

How to run a script if it is not already running in Linux

Let’s say you have a script called crawl.py and you never want two instances of it running at the same time. The following script can do the job RUNNING="$(ps aux|grep crawl|grep -v grep|wc -l)" if [ $RUNNING -eq 0 ] then python crawl.py else echo "Already running : skipping"; fi

November 11, 2021 · 1 min · 50 words · Saqib Razzaq

How to ZIP all files in directory and send to another server

First install zip if not already install Ubuntu apt-get install zip Centos yum install zip Then create a file.sh and paste following code OUTFILE=outputfile.zip INPUTDIR=inputdir zip -R $OUTFILE $INPUTDIR scp $OUTFILE usrename@outserver:/path/of/ $OUTFILE -i key.pem

November 11, 2021 · 1 min · 35 words · Saqib Razzaq

Ubtunu 20 Post Installation Checklist

Run an update first apt-get update Install necessary dev tools apt-get install -y zip unzip wget curl youtube-dl git subversion dconf-editor build-essential Install Sublime Text apt-get update sudo apt install -y dirmngr gnupg apt-transport-https ca-certificates software-properties-common curl -fsSL https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add - sudo add-apt-repository "deb https://download.sublimetext.com/ apt/stable/" sudo apt install -y sublime-text Install Google chrome apt-get update wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb sudo dpkg -i google-chrome-stable_current_amd64.deb Install Apache, MySQL, PHP, PHPMyAdmin Apache and MySQL apt-get update sudo apt install -y apache2 mysql-server sudo mysql_secure_installation PHP, PHPMyAdmin and some extensions ...

October 18, 2021 · 1 min · 192 words · Saqib Razzaq

How to create a new Apache user in Linux server

Following method can be used for creating a new user in Apache. This comes in real handy for my projects that user Apache authentication. I run following command when I’m asked to create a new user. htpasswd /etc/httpd/.htpasswd username_here

January 11, 2021 · 1 min · 39 words · Saqib Razzaq

How to count files per day in a directory in Linux

find directory -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c

March 11, 2019 · 1 min · 11 words · Saqib Razzaq

How to run commands X number of times in Linux

for i in {1..number_of_loops}; do commandsSeparatedBySemicolon; done;

March 11, 2019 · 1 min · 7 words · Saqib Razzaq

Markdown Syntax Guide

This article offers a sample of basic Markdown syntax that can be used in Hugo content files, also it shows whether basic HTML elements are decorated with CSS in a Hugo theme. ...

March 11, 2019 · 3 min · 446 words · Hugo Authors