Table of contents
  1. Gists
    1. Sync Chrome Bookmarks
  2. Tar File
    1. Options
      1. Create a new archive
      2. Verbose output
      3. Use archive file
      4. Filter the archive through gzipfile.tar.gz
      5. Filter the archive through bzip2
    2. Un Tar
  3. ZIP folder and add a password
  4. Find
    1. find and remove files
    2. Find and Delete Empty Directories
  5. find and kill by pid
  6. kill by port
  7. Add Table of Contents to mark down doc with pandoc
    1. UseCase Examples
  8. CAT
    1. Show Line Endings
    2. Display Line Numbers
    3. Display Tab Characters
    4. Reverse a File using tac
    5. Remove Blank Lines
    6. Create Here Document
  9. Mac
    1. get local ip
    2. convert file/image to base64




Gists

Sync Chrome Bookmarks

used to sync a bookmark file to a repo to update on both Mac and windows using bash and PowerShell when an account cannot sync due to admin
restrictions

Tar File

Recognized Suffixes

- .gz : gzip
- .tgz : gzip
- .taz : gzip
- .z : compress
- .taZ : compress
- .bz2 : bzip2
- .tz2 : bzip2
- .tbz2 : bzip2
- .tbz : bzip2
- .lz : lzip
- .lzma : lzma
- .tlz : lzma
- .lzo : lzop
- .xz : xz
- .zst : zstd
- .tzst : zstd
  • Compress an entire directory /home/vivek/data/

      tar -czvf file.tar.gz /home/vivek/data/
    
  • To compress multiple directories and files, execute:

     tar -czvf file.tar.gz /home/vivek/data/ /home/vivek/pics/ /home/vivek/.accounting.db
    

One can use bzip2 compression instead of gzip by passing the -j option to the tar command:

tar -cjvf file.tar.bz2 /home/vivek/data/

Options

Create a new archive

- c

Verbose output

- v

Use archive file

- f

Filter the archive through gzipfile.tar.gz

- z

Filter the archive through bzip2

- j

Un Tar

  tar xvf  <.tar file>
  tar xzvf <.tar.gz file>
  tar xjvf <.tar.bz2 file>

ZIP folder and add a password

zip -er last_resort.zip attachments;

Find

find and remove files

for st in $(mdfind -name ultdata); do rm -rf "$st"; done

Find and Delete Empty Directories

The -type d option searches for directories, -empty selects empty ones and -exec rmdir {} executes the rmdir command to delete them.
$ find . -type d -empty -exec rmdir -v {} +

find and kill by pid

pkill -f '.*GradleDaemon.*'

kill by port

npx kill-port 18090

Add Table of Contents to mark down doc with pandoc

  1. set file name

    fileMD=CLI_Grailsw.md;
    
  2. run

     pandoc -s --toc $fileMD -o output.md; rm -f $fileMD; mv output.md ./$fileMD;
    

UseCase Examples

CAT

Show Line Endings

cat -e file.txt

Display Line Numbers

 cat -n file.txt

This command is equivalent to the ‘nl file’ command.

 nl file.txt

Display Tab Characters

 cat -T file.txt

Reverse a File using tac

tac file.txt file2.txt

Remove Blank Lines

cat -s file.txt

Create Here Document

A here document (here doc) is a way to interactively input multiple lines of text into a command or program.
In the case of the cat command, you can use a here doc to provide the content that cat
should display.
Here’s an example using a here doc with the cat command:

cat << EOF
> type text
> more text
> and more text
> more more more text
> EOF

In this example, the « EOF notation indicates the start of the here doc, and the lines following it are treated as input until the EOF delimiter is
encountered.
The cat command will display the
content of the here doc, which in this case consists of three lines.

Mac

get local ip

osascript -e "IPv4 address of (system info)"
ifconfig | grep "inet "

convert file/image to base64

base64 -i ./post_u_north_gate.jpg | pbcopy
cat ./post_u_north_gate.jpg | openssl base64 | tr -d '\n' | pbcopy
./post_u_north_gate.jpg | openssl base64 | tr -d '\n' | pbcopy