Compress files inside directory

go directory:

cd /var/www/yourfile/
zip -r filename.zip .

import sql to database

mysql -u user -pyourpassword yourdatabase < your-file-db.sql

 

Compress and decompress folder

For compressing:

tar -cvzf tarballname.tar.gz itemtocompress

and for decompression:

tar -xzvf file.tar.gz

Export database settings

simple:

mysqldump -u root -p <database> > /data/raidpsbkp2.sql

with procedures and functions

mysqldump -u root -p -R <database> > /data/raidpsbkp2.sql

//ignore views

mysqldump -u root -p -R --ignore-table=dps.vw_tour --ignore-table=dps.vw_user_booking <database> > /data/raidpsbkp2.sql

//custom tables

mysqldump -u root -p -R --skip-triggers dps photo photo_upload photocategory photocategoryrelation > /data/dpscustomtablesoct.sql

//ignoring triggers and data

mysqldump -u root -p -R --skip-triggers --no-data <database> > /data/raidpsbkp2.sql

//ignoring triggers

mysqldump -u root -p -R --no-create-info --skip-triggers <database> > /data/raidpsbkp2.sql

//stored procedures and triggers

mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt <database> > outputfile.sql

//no triggers, no data, no info

mysqldump -u root -p -R --database <database> --skip-opt --routines --no-create-info --no-data --no-create-db --skip-triggers > /var/www/raidpsproc2

Export all database to one file

mysqldump -u root -p --all-databases > alldb.sql

Compress sql file

gzip -9 /data/yourdatabase.sql

Send from host to other server

scp -r foo [email protected]:/some/remote/directory/bar

Give permissions 755 to files inside folder

First go to folder:

cd /yourfolder/

then give permissions:

chmod -R 755 *

Change owner/group to file inside folder

First go to folder:

cd /yourfolder/

then give permissions:

chown -R www-data:www-data *

Remove all files inside folder

go to folder

rm -rf /yourfolder/*

Backup files of your server

sudo tar -cvpzf backup.tar.gz --exclude=/swapfile --exclude=/backup.tar.gz --one-file-system /

or 

sudo tar -cpzf “$backupfilename”
-v
–exclude=cache
–exclude=/dev/*
–exclude=/lost+found/*
–exclude=/media/*
–exclude=/mnt/*
–exclude=/proc/*
–exclude=/sys/*
–exclude=/tmp/*
–exclude=/var/cache/apt/*
–exclude=/home/$USER/error.log /
2>/home/$USER/error.log

Once the command above has finished its run, look for the backup.tar.gz file inside the / folder and save it to an external file system. If ever you lose some files that need to be restored, just run the following command to restore them:

sudo tar -xvpzf /path/to/backup.tar.gz -C /restore/location --numeric-owner

copy the content of a folder /source to another existing folder /dest

cp -a /source/. /dest/

Using www-data through ssh and ftp

Set a password for www-data

sudo passwd www-data

Define a shell for www-data. You can do this using chsh or by editing /etc/passwd. Replace /usr/sbin/nologin or similar by /bin/bash on the line of the user.

nano /etc/passwd

Give permission for login via ssh, edit /etc/ssh/sshd_config and add the following line (do not forget to enumerate all the users that need ssh access)

AllowUsers www-data root
systemctl restart sshd

Removing apache from server

A very simple and straightforward way that worked for me is as follows:

Stop apache2.

sudo service apache2 stop

Uninstall Apache2 and its dependent packages.

sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common

Use autoremove option to get rid of other dependencies.

sudo apt-get autoremove

Check whether there are any configuration files that have not been removed.

whereis apache2

If you get a response as follows apache2: /etc/apache2 remove the directory and existing configuration files.

sudo rm -rf /etc/apache2

 

Get current date and hour

This command allows you to show date and hour

date "+%H:%M:%S   %d/%m/%y"

 

Modify to a different time zone

first choose the time zone with:

timedatectl list-timezones

and once you have your time zone, just run this command:

sudo timedatectl set-timezone <timeszone>

 

Rinstall post fix and test mail message

After creating a postfix file, run this command:

sudo apt-get purge postfix

And then reinstall postfix:

sudo apt-get --reinstall install postfix

Use the following command to create the necessary email tools, including Postfix:

sudo apt-get install mailutils

During the installation process, Postfix will ask you several settings, use the default setting Internet Site.

Now open the config file “/etc/postfix/main.cf” and change/add these settings:

inet_interfaces = loopback-only
relayhost = [smtp.mailgun.org]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:[email protected]:password
smtp_sasl_security_options = noanonymous

Replace [email protected]:password with the login credential you have created before. 

Save the config file and restart Postfix.

sudo service postfix restart

To check that anything is working you can send this test mail:

echo "This is my email test message" | mail -s "My subject line" [email protected]

 

UNINSTALL OR COMPLETELY REMOVE MYSQL FROM UBUNTU

This incident are cause by mysql server update, while setting up the mysql by apt, its hang on the server and will not work for leaving it around one hours.
So we decide to remove the mysql server and reinstall again, below are the step that we were done.

sudo apt-get remove --purge mysql*
sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get remove dbconfig-mysql
sudo apt-get dist-upgrade
sudo apt-get install mysql-server

then installing mariadb:

sudo apt install mariadb-server mariadb-client
sudo apt install php7.2-mysql
sudo /etc/init.d/mysql start
sudo mysql_secure_installation

these are my often ubuntu commands that I use.

MAP NGINX PROCESS AND KILL IT

map nginx process:

ps aux | grep [n]ginx

kill nginx:

pkill nginx

or

kill $(ps aux | grep 'nginx' | awk '{print $2}')

 

 

Track changes on files

tail -f yourfile.log

Uncompress sql.gz files

gzip -d backup-20100910164109.sql.gz