Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Thursday, 1 March 2018

Useful docker commands for cleaning up containers, images and volumes

List of useful docker commands for cleaning up containers, images and volumes:

docker stop $(docker ps -aq // Stop all containers
docker rm $(docker ps -aq) // Remove all containers
docker rmi $(docker images -q) // Remove all images
docker volume ls // List all volumes
docker volume ls -q -f dangling=true // List all dangling volumes
docker volume rm `docker volume ls -q -f dangling=true` // remove all dangling volumes

Thursday, 14 May 2015

Deleting all large size files from all directories using Bash in Linux

If you are looking to delete all the files in Linux Web Server by specifing File Name and File Size,
then follow steps below:

1. Login into your server Terminal via root login.
2. Create a new bash file called clean_up.sh in one of the location
e.g. /home/my_script/

3. Then Copy and the below code and Paste into that file and Save it.
clear
echo ' -------------------------------------------------------------------------'
echo '  Cleaning all large size error_log files from all directories.'
echo ' -------------------------------------------------------------------------'

filename="error_log"
filesize="50000"

echo " Deleting all files (including subfolders) having Filename:'$filename', Size: greater than $filesize Kb only."
echo ' '
echo ' Listing all the files which are greater than 50MB'
find / -type f -size +50M -exec du -h {} \; | sort -n

echo ' Deleting all the "error_log" files which are greater than 50MB'
#find -name "error_log" -size +30000k #-delete
find -name "$filename" -size +"$filesize"k -delete

echo ' Listing again all the files which are greater than 50MB'
find / -type f -size +50M -exec du -h {} \; | sort -n

4. Then go to your specified directory where you want to Search and Delete the files by specifying the File Name and File Size as below;

5. Then run the below command
sh  /home/my_script/clean_up.sh

Wednesday, 6 August 2014

How to stop Filezilla as it messes the codes (changing the linebreaks) during upload to server?

If you are pulling your hair when you see the messed up codes/contents as soon as you upload the files(well aligned codes) to the server. Normally, it happens if you are using Filezilla.

By Default, FileZilla is set to "Auto" for File Transfer Type. And, if you have any files which are in ASCII file format, then FileZilla become over-smart and will mess up with those files while transferring to the server.

To Fix that,

1. Go to FileZilla > Edit > Transfers > File Types,
2. Switch to "Binary" and Click "OK"
3. (Optional) You can restart the Filezilla.

Then, Filezilla couldn't able to mess up with your files any more.

Extra Knowledge

What you observe is perfectly normal for ASCII transfers. Different operating systems have different line-ending styles. Windows has $0D0A (), *NIX has $0A () and classic Mac had $0D (). See Data Type.

FTP in ASCII transfer type performs line ending conversion. Example: When uploading in ASCII type from Windows to Linux server, all are converted to . Thus the filesize will shrink, and binary verification tools fail on the target file. Notepad does not support UNIX style line endings and thus shows the file as one line (the rectangles are the chars), but Wordpad does (try opening the file in Wordpad to see for yourself).

Friday, 4 April 2014

To add to one GIT repository to another repository on same machine

Well, what I have done here is I have development and production repositories on my PC which were exclusively linked to their own GitHub repositories.

Now, I would like to update my production repo from development locally and push back to production repository on GitHub.

And here is my commands;

# Go to local "production" repo
 
$ cd project.production/  
RC@MyPC-001 /c/xampp/htdocs/project.production (master)

$ git remote add development /c/xampp/htdocs/hillingdon/dev.hcp.branch
RC@MyPC-001 /c/xampp/htdocs/project.production (master)

$ git fetch development

$ git merge development/
development/forum-devt   development/master // This is because I had two branch on my development repo

$ git merge development/master // I am merging the master branch only

// If you got any conflicts, please resolve them and add them all
 
$ git add --all 

SSH/SCP commands to/from remote server in window/Linux

Syntax for Secure Copy (scp) via HTTP

What is Secure Copy?

scp allows files to be copied to, from, or between different hosts. It uses ssh for data transfer and provides the same authentication and same level of security as ssh.

Examples

Copy the file "foobar.txt" from a remote host to the local host

$ scp your_username@remotehost.edu:foobar.txt /some/local/directory

Copy the file "foobar.txt" from the local host to a remote host

$ scp foobar.txt your_username@remotehost.edu:/some/remote/directory

Copy the directory "foo" from the local host to a remote host's directory "bar"

$ scp -r foo your_username@remotehost.edu:/some/remote/directory/bar

Copy the file "foobar.txt" from remote host "rh1.edu" to remote host "rh2.edu"

$ scp your_username@rh1.edu:/some/remote/directory/foobar.txt \
your_username@rh2.edu:/some/remote/directory/

Copying the files "foo.txt" and "bar.txt" from the local host to your home directory on the remote host

$ scp foo.txt bar.txt your_username@remotehost.edu:~

Copy the file "foobar.txt" from the local host to a remote host using port 2264

$ scp -P 2264 foobar.txt your_username@remotehost.edu:/some/remote/directory

Copy multiple files from the remote host to your current directory on the local host

$ scp your_username@remotehost.edu:/some/remote/directory/\{a,b,c\} .
$ scp your_username@remotehost.edu:~/\{foo.txt,bar.txt\} .

scp Performance

By default scp uses the Triple-DES cipher to encrypt the data being sent. Using the Blowfish cipher has been shown to increase speed. This can be done by using option -c blowfish in the command line.
$ scp -c blowfish some_file your_username@remotehost.edu:~
It is often suggested that the -C option for compression should also be used to increase speed. The effect of compression, however, will only significantly increase speed if your connection is very slow. Otherwise it may just be adding extra burden to the CPU. An example of using blowfish and compression:
$ scp -c blowfish -C local_file your_username@remotehost.edu:~

Reference: http://www.hypexr.org/linux_scp_help.php

Thursday, 6 June 2013

To Install GIT on CentOS 5.2 server using WHM CPanel


It may be slightly different to install GIT on CentOS 5.2 server using WHM CPanel. However, I found below steps working for me to install it.

First, make sure you are logged in as ROOT via SSH using PUTTY application.
Then, do the following;
$ su // (login as root)
$ yum update

// To install yum fastest mirror plugin (yum-plugin-fastestmirror) you can use this command:-

$ yum install yum-fastestmirror

// OR

$ yum install yum-plugin-fastestmirror

Once the installation completed, check the plugins status by editing the file /etc/yum.conf and add the following line to the file:
$ plugins=1
// Install the dependencies

yum install gettext-devel expat-devel curl-devel zlib-devel openssl-devel

// Get the git source code ( http://distfiles.macports.org/git-core/ )
wget http://distfiles.macports.org/git-core/git-1.8.2.tar.gz


// untar/uncompress the git source code
tar xvfz git-1.6.1.tar.gz

// Install the files
cd git-1.6.1.tar.gz

make prefix=/usr/local all

make prefix=/usr/local install

Monday, 18 February 2013

301 Redirection from Multiple Domains

If you have domains: domain1.com, domain2.com and domain3.com and you want to do 301 redirection.
In this case, first:
  1. Just host the domain1.com into the server.
  2. Park the domain2.com and domain3.com under the domain1.com hosting account. 
  3. Then, create a .htaccess file on the domain1.com /public_html folder in the server. 
  4. And, the following code into the .htaccess file which is for making 301 redirection (page to page redirection) to domain1.com.
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domain1\.co\.uk
RewriteRule (.*) http://www.domain1.co.uk/$1 [R=301,L]

Friday, 16 November 2012

Install SQLYog with Wine in Ubuntu 12.04

First, download the SQLYog from here. Before that, make sure that you have already installed the wine into your machine, if you don't know how to install wine, refer to this link.

Afterwards, run the following command in terminal (use CTRL+ALT+T to open terminal).

wine /home/rc/Downloads/SQLYog-10.4.0-2-trial.exe 

Then, it should execute the .exe file, and just follow the SQLYog installation as like normally.
However, if you stuck with some error like below;
  wine is not owned by you , err msg.....

In that case, just run the below command (where rc is the shell user). Then run the above command again once the below command is successfully executed.

sudo chown -R rc:rc ~/.wine 


Enjoy !!!

Install Wine in Ubuntu 12.04, or Linux or Linux Mint


Wine enables Linux, Mac, FreeBSD, and Solaris users to run Windows applications without a copy of Microsoft Windows. Wine is free software under constant development. Other platforms may benefit as well. 
Wine 1.5.4 has just been released and this brief tutorial is going to show you how to install it in Ubuntu 12.04. Wine is an open source application which lets you install and run programs designed for Microsoft Windows systems in Linux systems. Not all your Windows programs will run with Wine, but many popular software that you depend on which run in Windows will run perfectly in Ubuntu using Wine.
With this release, comes many enhancements and bug fixes from the previous released version. You can now run Microsoft Office 2003, 2007 properly, Adobe Premier Pro, support for .NET 4.0 and many other software. For a more detailed release note, click here.
To get started, Open the Terminal ( can use press Ctrl+Alt+T on your keyboard to open Terminal). When it opens, run the commands below to add Wine PPA.

sudo add-apt-repository ppa:ubuntu-wine/ppa
sudo apt-get install winetricks

Finally, run the commands below to update your system and install Wine 1.5
sudo apt-get update && sudo apt-get install wine1.5

Thursday, 15 November 2012

Ubuntu: Upgrade error due to another package management application running


Ubuntu: Upgrade error due to another package management application running 


Please, try some of these steps in order:
If you haven't already done so reboot your machine and try running the update again.
Try to run one of the below command or all on command line as;
sudo apt-get clean
sudo do-release-upgrade
sudo rm /var/lib/dpkg/lock 
Manually remove the lock file and try running the update again.