command line notes

linux command

  • ps aux | grep ...
  • netstat --listen
  • sudo chown -R $USER:admin

Find binary/executable location:

type -a [command]
whereis [command]

Print enviorment variables:

SET | more

Replace Strings and add a backup original file:

sed -i.bu 's/OriginalString/ReplacingString/g' whatever.txt

Disk File system storage:

 df -kh . 

Concate file column by colum:

pr -mts, 1.txt 2.txt 3.txt 4.txt 5.txt > result.csv

Git

Get diff of the previous comit

git diff commit_id HEAD
git diff HEAD^ HEAD 

Undo Last Commit:

git reset --soft HEAD~1

Pull A Git Branch from Remote:

git remote update
git fetch origin < new_branch >
git checkout -b < new_branch > origin/< new_branch >

Stash

git stash 
git stash apply/git stash pop
git stash list
git stash clear

trace files

git log -- [filename]

delete remote branch

git push origin --delete <branchName>

Psql

  • \l list databases
  • \dt list tables
  • pg_dump -U [username] [dbname] -f [dumpfilename]
  • psql -U [user_name] -d [des_dbname] -f [dumpfilename]
  • ALTER SEQUENCE [colum_name] RESTART WITH [id]

MySql

  • ALTER IGNORE TABLE table ADD UNIQUE KEY idx1(title)
  • ALTER TABLE user_customer_permission MODIFY id INT NOT NULL; ALTER TABLE user_customer_permission DROP PRIMARY KEY;
  • SHOW COLUMNS FROM entries;
  • mysql -u[root] -p -h [localhost] [dbname] < [dumpfilename]

Create new user:

    CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
    FLUSH PRIVILEGES;

MsSQL

Show Tables:

SELECT Distinct TABLE_NAME FROM information_schema.TABLES

Node

update node:

npm cache clean -f  
npm install -g n  
n stable 

nginx

sudo vim /etc/nginx/sites-available/site.com
sudo ln -s /etc/nginx/sites-available/site.com /etc/nginx/sites-enabled/site.com
sudo service nginx restart

basic config for site.com:

server {
 listen 80;
 server_name site.com site.com;

 root /var/www/site.com;
 access_log /var/www/site_access.log;
 error_log /var/www/site_error.log;
 location / {
   proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $http_host;
  proxy_redirect off;
  if (!-f $request_filename) {
    proxy_pass http://localhost:"local_port_number";
    break;
  }
}}

Java

Iterate through the JSONObject keys:

jObject = new JSONObject(contents.trim());
    Iterator<?> keys = jObject.keys();
    while( keys.hasNext() ){
        String key = (String)keys.next();
        if( jObject.get(key) instanceof JSONObject ){

        }
    }

String is not empty:

public static boolean isNotEmptyString(String string)
{
    return string != null && !string.isEmpty() && !string.trim().isEmpty();
}

String is numeric:

public static boolean isNumeric(String s) {
    return s.matches("[-+]?\\d*\\.?\\d+");
}
comments powered by Disqus