Showing posts with label Unix command. Show all posts
Showing posts with label Unix command. Show all posts

Saturday, October 2, 2021

Thursday, July 25, 2019

Compress a file before scp from remote server to local


ssh user@host "tar -zcvf - -C /path/to/dir filename" | tar -zxvf -

Note: only use when it's much faster to transfer a compressed file to your machine than transferring the original one.

Credits:
https://superuser.com/a/1354868
https://stackoverflow.com/a/3035446/1032449

Tuesday, April 26, 2016

Unix, use output of the previous command

Not a direct solution but it suits my need.
Use !! to expand the previous command and evaluate it with $() or ``
For example;

$ which pinata  
/usr/local/bin/pinata 
$ ls -lh `!!`
... 
Credit: http://stackoverflow.com/a/5955674/1032449 

Thursday, September 24, 2015

Find out which process is using a particular port

I was never be able to remember options for netstat command. This option for lsof seems to be easier. Note that it requires a root access.
lsof -i :80
Change 80 to any port number you like.

Creadit: http://unix.stackexchange.com/a/106572

Friday, March 27, 2015

Set bash completion when aliasing docker to d

After you installed docker bash completion, either by sourcing it from your .bash_profile or installing it to bash-completion, add this line to the end of your docker-completion.sh file.
complete -F _docker d
Reload your shell. And that's it!

Note: change the last d to other character you aliased docker to

Wednesday, December 3, 2014

Calculate sum of memory usage data with Awk

I don't know how to use awk, but I have a problem which I know it suits for.

I want to sum up memory usage data that come out from executing the command ps aux. I learned 2 usages of awk from this lesson.

Print value of a column with:
awk '{ print $COLUMN_NUMBER }'

Sum value of a column with:
awk '{ temp = temp + $COLUMN_NUMBER }END{ print temp }'

So I can get sum of memory usage of processes with certain name pattern like this:
$ ps aux | grep NAME_PATTERN | awk '{temp = temp + $6}END{ print temp }'

I still don't know awk, but at least I'm incrementally learning it.

Credits:
simple awk tutorial
Add up a column of numbers at the Unix shell

Tuesday, January 21, 2014

start-stop-daemon: help for start, stop, create pidfile for your command that doesn't have pidfile

You have a command to start a long running process but it doesn't create a pidfile for you to write a script to start/stop it. start-stop-daemon could help that.

This is a document of the command.

Example:

start-stop-daemon -d dir_want_to_run_on -b -m -p pidfile.pid --start --startas command
start-stop-daemon -p pidfile.pid --stop

-b : background
-m : make file (need to use with -p)
-p : pid file name (need to use with -m)

Monday, December 23, 2013

Unix/Linux log script outputs to a file

In any scripts that print something out, the simplest way to capture those printed stuffs is to append with

>> logfilename.log 2>&1 

All the outputs (stdout, stderr) will be redirect to file logfilename.log. To learn this in details, search for something like "unix stdout redirection"

Collectd PostgreSQL Plugin

I couldn't find this link when searching with google https://www.collectd.org/documentation/manpages/collectd.conf.html#plugin-postgresq...