Showing posts with label Commands. Show all posts
Showing posts with label Commands. Show all posts

Thursday, June 1, 2023

Docker Commands-Updated

  • docker -v  returns docker version 
  • docker login login to docker hub using command line
  • docker pull hello-world retrieve hello-world docker image from docker hub
  • docker run hello-world execute hello-world docker image

  • docker ps -a list all processes in docker
  • docker rmi hello-world --force delete hello-world image from docker forcefully 
  • docker rm container_id --force delete container from docker forcefully 

  • docker run -d nginx run nginx server in background
  • docker ps list running processes in docker
  • docker container inspect container_id get the all information about docker container 
  • docker run -d -p 3600:80 --name sujith-nginx nginx port forwarding with docker images execution 
  • docker exec -it container_d redis redis-cli access redis-cli after docker image execution
    • set myvalue 5 set value redis
    • get myvalue retrieve value

  • docker run -it ubuntu bash run ubuntu with bash access in docker
    • apt-get install git tree -y install git inside ubuntu
    • ctrl + p + q exit to run git in background 

  • docker container commit --author "sujith" -m "my custom image" running_container_id my_ubuntu_git_image create image using running git installed ubuntu container
  • docker docker tag my_ubuntu_git_image sujithdc/my_ubuntu_git_image tagging docker image to push to docker hub
  • docker push sujithdc/my_ubuntu_image push image to docker hub

Saturday, July 17, 2021

Kill processes created under specific user in Linux

 You can use following commands to kill processes created under specific user in Linux.

for k in `ps -ef | grep usr01| grep ssh | awk '{print $2}'` ; do kill -9 $k ; done

Here, it is killing ssh sessions created by usr01 user.


Tuesday, August 11, 2020

Search files in sub directories in Linux

Following command can use to list files staring with 1234 in all sub directories. 

ls –R | grep 1234*

Sunday, March 24, 2019

Sub directory size in Linux/Solaris

Following command can be used to retrieve directory sizes in Linux. Below command returns 5 largest files in any sub directory in /apps/ directory.

find /apps/ -type f -ls | sort -k 7 -r -n | head -5

Monday, August 13, 2018

Retrieve application running on ports in windows

Use netstat command to get application list running on specific ports.

netstat -anob

Run the above command as administrator in command prompt.


Tuesday, August 29, 2017

Find files in Linux and move files

Following command can be used to find files in a directory and move found files into /home/sujith/files/ location.

find . -name "*" -maxdepth 1 -exec mv -t /home/sujith/files {} +

Monday, August 28, 2017

Copy large number of files between Linux servers

You can use "rsync" command to sync data between two locations.

rsync -r dir1/ dir2
sync the contents of dir1 to dir2 on the same system (-r option for recursive)

rsync -a dir1 username@remote_host:destination_directory
sync directory from the local system to a remote system ( pushing files to destination)

rsync -a username@remote_host:/home/dir1 place_to_sync_on_local_machine
sync a remote directory to the local system (pulling files from remote machine)

Also, you can compressed and sync files between locations using following command.

rsync -az source destination

https://www.digitalocean.com/community/tutorials/how-to-use-rsync-to-sync-local-and-remote-directories-on-a-vps

Thursday, August 24, 2017

Linux shell script to find files and copy into another location

You can use following shell script to find files in directories and copy into another location.

#!/bin/bash
for k in `cat errlog_tmp.txt`; 
do 
arr=( $(find . -name "$k*" -type f));
echo $arr;( cp $arr "./error1$k"); 
done;

Above shell will cat file names in "errlog.txt" and find in the current directories. After successful file found, it is copied into "./error/" directory.

Thursday, December 29, 2016

Remove last char in vi

Following Linux commands can be used to replace last character in vi editor.

1. Open file using vi editor
2. Run the following command to replace last char

:%s/.$//g

3. Save file using :wq!

Sunday, December 18, 2016

Create soft link in Linux

Suppose you want to create shortcuts in Linux, you can use 'ln -s' command to create soft links.

Ex :- If you need to run JAVA6 and JAVA8 both from terminal, you have to add java6 and java8 commands to /usr/bin for terminal execution.

Steps to keep java6 and java8.

  1. Create two files in /usr/bin/ as java6 and java8
  2. Extract JAVA6 and JAVA8 to Linux file system. Suppose directory locations are /usr/java6/ and /usr/java8/
  3. Create Soft links for java6 and java8 using the following commands as root.

ln -s /usr/java8/jdk1.6.0_10/bin/java /usr/bin/java6

ln -s /usr/java8/jdk1.8.0_12/bin/java /usr/bin/java8

Now check versions using following commands in terminal.

java6 -version
java8 -version

Thursday, December 15, 2016

Add number of days to timestamp in MySQL

Following DATE_ADD('field_name', INTERVAL) can be used to increase the number of days in the 'field_name' in MySQL databases. 

SELECT SQL

SELECT DATE_ADD('field_name', INTERVAL 2 DAY)FROM 'table_name';

Update SQL

UPDATE 'table_name'
SET field_name= DATE_ADD('field_name' , INTERVAL 2 DAY)
WHERE 'id' = 1;

Tuesday, November 29, 2016

Change enum values by passing values

Following code can be used to change the enum return value as required by passing parameters.

import java.text.MessageFormat;

public enum Errors {
     USERNAME_NOT_FOUND("User not found"),
     USERNAME_EXISTS("Username {0} already exists."),
     USERNAME_CONTAINS_INVALID_CHARS("Username {0} contains invalid characters {1}.");

     private final String message;

     Errors(String message) {
          this.message = message;
     }

     @Override
     public String toString() {
          return message;
     }

     public String getMessage(Object... args) {
          return MessageFormat.format(message, args);
     }
      
     public static void main(String args[]) {

System.out.println(Errors.USERNAME_NOT_FOUND);          System.out.println(Errors.USERNAME_EXISTS.getMessage("username"));  System.out.println(Errors.USERNAME_CONTAINS_INVALID_CHARS.getMessage("us%ername", "%"));

     }
}


Wednesday, November 2, 2016

Run different main classes from one project in JAVA

You can use following command to run different classes from one project jar file. Suppose Runner1 and Runner2 are main classes. You want to run both in separately, then you can use the following commands.

java -cp App.jar foo.Runner1
java -cp App.jar foo.Runner2

Monday, July 25, 2016

HTTP Request/ Response capture in JAVA

Following properties can be used to enable console output of http requests and responses in JAVA. 

System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump",
"true");
    
System.setProperty("com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump",
"true");
    
System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump",
"true");
    
System.setProperty("com.sun.xml.internal.ws.transport.http.HttpAdapter.dump",

"true");

Tuesday, July 5, 2016

Git ignore HTTPS verification

Following git commands ignore https verification.

git -c http.sslVerify=false clone https://github.com/spring-guides/gs-securing-web.git

In Git shell, type the above command to retrieve "gs-securing-web" web application clone.

Monday, June 13, 2016

Run MongoDB as a service

Following command can be used to run mongo db as service.

mongod.exe --install --dbpath "c:\mongo\data\db" --logpath "c:\mongo\data\log"

You can also set dbpath & logpath in "mongod.cfg" file and run the command as follows.

mongod.exe --install --config "c:\mongo\mongod.cfg"

Sample mongod.cfg

systemLog:
    destination: file
    path: C:\Program Files\MongoDB\Server\3.2\data\log\mongod.log
storage:
    dbPath: C:\Program Files\MongoDB\Server\3.2\data\db

In Windows, you can stop service in services management window. Run/Services

In Linux, ps -ef|grep mongo then kill -9 process_id

Monday, August 31, 2015

Grep files from file list

Following Linux script can be used to grep files from file list. Suppose you have file name list in "test2" file. Then, you can use following script to grep files in current location and copy these files to "/home/sujith/files/.

for k in `cat /home/sujith/test2`; 
do echo $k; 
cp *$k /home/sujith/files/.;
done

String Substring Linux

Suppose file "test" has strings with "-" separator. If you need to get the second part of the string into "test2" file, you can use the following command.

test
=======

90463619-15723905D.pdf
90465573-15728095D.pdf
91028582-16080834D.pdf

test2
=======
15723905D.pdf
16080834D.pdf
15728095D.pdf

cat test |awk -F"-" '{print $2}' > test2

Tuesday, May 26, 2015

Set email priority in JAVA

Following code can be used to set priority in email server. This is tested and worked fine.JAVA mail API is used for the development.

// Setting the priority of an email is simply a matter of setting the X-Priority header field.
// Values of 1 through 5 are acceptable
// 1 = highest priority, 3 = normal, and 5 = lowest priority.

// Set the email's priority to high:
email.AddHeaderField("X-Priority","1");

Tuesday, May 19, 2015

CURL Commands

Here are some valuable curl commands.

GET JSON Request
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://hostname/resource

GET XML Request
curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET http://hostname/resource

POST data
curl --data "param1=value1&param2=value2" http://hostname/resource

For file upload
curl --form "fileupload=@filename.txt" http://hostname/resource

RESTful HTTP Post
curl -X POST -d @filename http://hostname/resource

For logging into a site (auth)
curl -d "username=admin&password=admin&submit=Login" --dump-header headers http://localhost/Login
curl -L -b headers http://localhost/

Reference Site :-

http://stackoverflow.com/questions/14978411/http-post-and-get-using-curl-in-linux
http://www.w3schools.com/json/json_syntax.asp