ls with timestamp (BSD ver.)
ls -l below
tk-no-MacBook-Pro:webapps tk$ ls -l
total 51584
drwxr-xr-x@ 10 tk staff 340 1 29 2008 ROOT
drwxr-xr-x@ 5 tk staff 170 1 29 2008 balancer
drwxr-xr-x@ 23 tk staff 782 1 29 2008 jsp-examples
drwxr-xr-x@ 11 tk staff 374 1 29 2008 servlets-examples
drwxr-xr-x@ 44 tk staff 1496 1 29 2008 tomcat-docs
drwxr-xr-x 24 tk staff 816 3 11 22:16 tutorial-thin
-rw-r--r-- 1 tk staff 14953152 3 10 03:22 tutorial-thin.tar.gz
-rw-r--r-- 1 tk staff 11455414 3 10 22:42 tutorial-thin.war
drwxr-xr-x@ 6 tk staff 204 1 29 2008 webdav
this year : with time detail
last year : no time detail
try to ls -full--time
tk-no-MacBook-Pro:webapps tk$ ls --full-time
ls: illegal option -- -
usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]
BSD ver "ls" command cant use option "--full-time"
should use "Tl"
tk-no-MacBook-Pro:webapps tk$ ls -Tl
total 51584
drwxr-xr-x@ 10 tk staff 340 1 29 05:38:54 2008 ROOT
drwxr-xr-x@ 5 tk staff 170 1 29 05:38:54 2008 balancer
drwxr-xr-x@ 23 tk staff 782 1 29 05:38:53 2008 jsp-examples
drwxr-xr-x@ 11 tk staff 374 1 29 05:38:54 2008 servlets-examples
drwxr-xr-x@ 44 tk staff 1496 1 29 05:38:58 2008 tomcat-docs
drwxr-xr-x 24 tk staff 816 3 11 22:16:56 2019 tutorial-thin
-rw-r--r-- 1 tk staff 14953152 3 10 03:22:54 2019 tutorial-thin.tar.gz
-rw-r--r-- 1 tk staff 11455414 3 10 22:42:33 2019 tutorial-thin.war
drwxr-xr-x@ 6 tk staff 204 1 29 05:38:54 2008 webdav
copy files timestamp
-rw-r--r-- 1 tk staff 40988 3 22 21:58 2.log
-rw-r--r-- 1 tk staff 40988 3 25 03:16 3.log
tk$ touch -r 2.log -m 3.log
-rw-r--r-- 1 tk staff 40988 3 22 21:58 3.log
-rw-r--r-- 1 tk staff 40988 3 22 21:58 2.log
file and directory counts
count files
find /Users/tk/ -type f | wc -l
count directory
find /Users/tk/ -type d | wc -l
and.. list full path with subDirectory
ls -ltrh -d $(find `pwd`) > list.log
how to save [jsonb_pretty] format data
1)data is below
prototype=# select jsonb_pretty(memo) from foo
prototype-# where id = 1;
jsonb_pretty
---------------------------
{ +
"name": "japan", +
"currency": "JPY", +
"population": "10000"+
}
(1 row)
2)if you use copy to stdout,
psql -d prototype -c "\COPY (select jsonb_pretty(memo) from foo where id=1) TO STDOUT" >test.json
result are...
cat test2.json
{\n "name": "japan",\n "currency": "JPY",\n "population": "10000"\n}
3)make select script and call psql -c command like this
$ cat sel.sql
select jsonb_pretty(memo) from foo where id=1
and
psql -d prototype -f sel.sql | cat -n > sample.txt
more sample.txt
1 jsonb_pretty
2 ---------------------------
3 { +
4 "name": "japan", +
5 "currency": "JPY", +
6 "population": "10000"+
7 }
8 (1 row)
9
how to get and put pdf in bytea (postgres)
only using sql and sql-command
0)main table to store binary file below
prototype=# \d storedpdf
Table "public.storedpdf"
col name | type | description |
---|---|---|
id | integer | key |
name | character varying | file name |
bytea | to store files |
1)create temporary table
prototype=# create table media(val text);
2)copy hex text stream to table(text)
cat /test/get.pdf | xxd -p | tr -d '\n' | psql -d prototype -c "\COPY media(val) FROM STDIN"
3)convert text to binary by decode function
prototype=# insert into storedpdf(pdf) select decode(val,'hex') from media;
psql -d prototype -c "\COPY (select pdf from storedpdf ) TO STDOUT" | xxd -r -p>get.pdf