obda.net

Zsh Glob Qualifiers

111 comments

cheat-sheet articles are about code snippets that I need every once in a while, and which I constantly forget about.

Examples

# three newest (by mtime) files
print *(.om[1,3])
# files larger than 50 kiB
print *(.Lk+50)
# files modified within the last hour
print *(.mh-1)
# files not accessed for six months or longer
print *(.aM+6)
# change ownership of anything that is owned by `alice` to `bob`
chown bob **/*(u:alice:)

Full List

Qualifier Description
/ directory
F non-empty directory (empty: (/^F))
. plain file
@ symbolic link
* executable plain file
r/A/R readable by owner/group/world
w/I/W writable by owner/group/world
x/E/X executable by owner/group/world
s/S/t setuid/setgid/sticky bit
fspec has chmod style permissions spec
u:name: owned by user name
g:name: owned by group name
a[Mwhms][-+]n access time in given units (see below)
m[Mwhms][-+]n modification time in given units
L[kmp][-+]n size in given units (see below)
^ negate following qualifiers
- toggle following links (first one turns on)
N whole pattern expands to empty if no match
D leading dots may be matched
n sort numbers numerically
o[nLamd] order by given code (see below; may repeat)
O[nLamd] order by reverse of given code
[num] select num-th file in current order
[num1,num2] select num1-th to num2-th file

PostgreSQL: Create User and Database

Add a comment

cheat-sheet articles are about code snippets that I need every once in a while, and which I constantly forget about.

(Taken from PostgreSQL add or create a user account and grant permission for database.)

user@host:~$ psql -U postgres
postgres=# CREATE USER tom WITH PASSWORD 'myPassword';
postgres=# CREATE DATABASE jerry;
postgres=# GRANT ALL PRIVILEGES ON DATABASE jerry to tom;

Or, with multi-line input directly from the command line:

user@host:~$ cat <<EOF | psql -U postgres
CREATE USER tom WITH PASSWORD 'myPassword';
CREATE DATABASE jerry;
GRANT ALL PRIVILEGES ON DATABASE jerry to tom;
EOF

You can specify a different collation than the default collation by using template0 as template database:

user@host:~$ cat <<EOF | psql -U postgres
CREATE DATABASE jerry TEMPLATE = template0 LC_COLLATE = 'de_AT.UTF-8';
EOF