# Command Line Snippets

Bits and pieces to copy/paste

# psql

I always end up looking up the same few things every time I need to interact with psql:

==== Quit ====  
 \\q

==== Databases ====

== List ==

 \\l

== Switch ==  
 \\c dbname

== Rename ==  
 ALTER DATABASE old RENAME TO new;

==== Tables ====

== List ==

 \\dt

== Show details ==  
 \\d tablename  
   
   
==== Create db with user ====

 create database mydb;  
 create user myuser with encrypted password 'mypass';  
 grant all privileges on database mydb to myuser;

==== Change user pw ====  
 ALTER USER user\_name WITH encrypted password 'new\_password';

(remove ~/.psql\_history after)

==== Drop a user after reassigning privs ===  
 REASSIGN OWNED BY &lt;olduser&gt; TO &lt;newuser&gt;  
or  
 DROP OWNED BY &lt;olduser&gt;

also to be more thorough:

 REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM username;  
 REVOKE ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public FROM username;  
 REVOKE ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public FROM username;  
 REVOKE ALL PRIVILEGES ON DATABASE database FROM username;  
 DROP USER username;

https://stackoverflow.com/questions/3023583/how-to-quickly-drop-a-user-with-existing-privileges

==== Dump a database ====  
 pg\_dump -C -h (ip) -p (port) -U username dbname &gt; dump.sql

(omit -C if you want to create the db yourself)  
==== Restore a dump ====  
 psql dbname &lt; dump.sql

# robocopy

  
copy sourcepath to destpath recursively (/e), log to x:\\logs.log.txt (/log), allow resuming large files (/z), and use 16 threads (/mt)

 robocopy \[sourcepath\] \[destpath\] /tee /log:x:\\logs\\log.txt /z /e /mt:16

# excel

split by delimeter and take just one part  
 =TAKE(DROP(TEXTSPLIT(\[@FullName\],"\\"), 0, 6), 1, 1)

- Split the target into a table where each column is a path segment  
- Drop the first 6 columns  
- Take a single (top leftmost) cell from that table

# azure pipelines

{{tag&gt;Azure\_DevOps}}

Snippets for quickly getting a tree of some path:

Look at artifact staging

```  
\- powershell: |  
 Get-ChildItem -Path $(Build.ArtifactStagingDirectory) -Recurse | Select-Object -ExpandProperty FullName  
displayName: "Diagnostic: Tree of artifact staging dir."  
condition: succeededOrFailed()  
```

Or everything  
```  
\- powershell: |  
 Get-ChildItem -Path $(Pipeline.Workspace) -Recurse | Select-Object -ExpandProperty FullName  
displayName: "Diagnostic: Tree of pipeline workspace"  
condition: succeededOrFailed()  
```

  
Remember to add `condition: succeededOrFailed()` to the step that publishes the artifact, too.

# git

### find all commits touching a file

today I had some changes to a file sitting on an old branch from a couple months ago, and I wasn’t sure *which* branch. [stackoverflow user BigMiner shared this](https://stackoverflow.com/a/34666649), which worked great:

> I have been looking at this closely and all these answers don‘t seem to really show me all the commits across all the branches.
> 
> Here is what I have come up with by messing around with the [gitk](https://git-scm.com/docs/gitk) edit view options. This shows me **all the commits for a file** regardless of branch, local, reflog, and remote.
> 
> ```
> ```php
> gitk --all --first-parent --remotes --reflog --author-date-order -- filename
> 
> ```<small class="shcb-language" id="bkmrk-code-language%3A-php-%28">Code language: PHP (php)</small>
> ```
> 
> It also works with `git log`:
> 
> ```php
> git log --all --first-parent --remotes --reflog --author-date-order -- filename
> ```