Showing posts with label Linux/Unix. Show all posts
Showing posts with label Linux/Unix. Show all posts

Julia language UNIX date time

Unix time date format is used in many applications, including Yahoo finance.



using Dates, Printf

unix_date = @sprintf("%.0f", Dates.datetime2unix(Dates.now()))

println( unix_date ) # String



Output:

1603013077


As an Amazon Associate I earn from qualifying purchases.

Resizing Mac APFS disk to create a case-sensitive HFS (hfsx) for Linux sharing and Android builds

Resizing Mac APFS 500Gb to 350Gb and creating HFSx (case-sensitive) for AOSP building.



$ sudo diskutil apfs resizeContainer disk0s2 250g hfsx REPO 0b

..
Shrinking APFS Physical Store disk0s2 from 499,963,170,816 to 249,999,998,976 bytes
Shrinking APFS data structures

[ \ 0%..10%..20%..30%..40%............................... ] 47% 0:00:02 

..

Initialized /dev/rdisk0s3 as a 233 GB case-sensitive HFS Plus volume
Mounting disk
1 new disk created or changed due to APFS operation
Disk from APFS operation: disk0s3
Finished APFS operation
uki 192.168.1.7 13:16 ~ $ diskutil list
/dev/disk0 (internal):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                         500.3 GB   disk0
   1:                        EFI EFI                     314.6 MB   disk0s1
   2:                 Apple_APFS Container disk1         250.0 GB   disk0s2
   3:                  Apple_HFS REPO                    249.8 GB   disk0s3

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +250.0 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume SYSTEM                  220.6 GB   disk1s1
   2:                APFS Volume Preboot                 22.3 MB    disk1s2
   3:                APFS Volume Recovery                509.8 MB   disk1s3

   4:                APFS Volume VM                      1.1 GB     disk1s4



REFERENCE:

http://www.peachpit.com/articles/article.aspx?p=1403238

https://www.macobserver.com/tips/deep-dive/resize-your-apfs-container/


As an Amazon Associate I earn from qualifying purchases.

Resizing Mac APFS disk to create a case-sensitive HFS (hfsx) for Linux sharing and Android builds

Resizing Mac APFS 500Gb to 350Gb and creating HFSx (case-sensitive) for AOSP building.



$ sudo diskutil apfs resizeContainer disk0s2 250g hfsx REPO 0b

..
Shrinking APFS Physical Store disk0s2 from 499,963,170,816 to 249,999,998,976 bytes
Shrinking APFS data structures

[ \ 0%..10%..20%..30%..40%............................... ] 47% 0:00:02 

..

Initialized /dev/rdisk0s3 as a 233 GB case-sensitive HFS Plus volume
Mounting disk
1 new disk created or changed due to APFS operation
Disk from APFS operation: disk0s3
Finished APFS operation
uki 192.168.1.7 13:16 ~ $ diskutil list
/dev/disk0 (internal):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                         500.3 GB   disk0
   1:                        EFI EFI                     314.6 MB   disk0s1
   2:                 Apple_APFS Container disk1         250.0 GB   disk0s2
   3:                  Apple_HFS REPO                    249.8 GB   disk0s3

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +250.0 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume SYSTEM                  220.6 GB   disk1s1
   2:                APFS Volume Preboot                 22.3 MB    disk1s2
   3:                APFS Volume Recovery                509.8 MB   disk1s3

   4:                APFS Volume VM                      1.1 GB     disk1s4



REFERENCE:

http://www.peachpit.com/articles/article.aspx?p=1403238

https://www.macobserver.com/tips/deep-dive/resize-your-apfs-container/


As an Amazon Associate I earn from qualifying purchases.

The "ls" command with sorting

The Mac/Unix "ls" command does not include sorting by file name. 

To get it done I added a new function in Bash to my ~/.bash_profile


# ls with sort - updated: February 13, 2018
function list()
{
    if [ "$1" != "" ]; then
        ls -a $1 | sort
    fi
   
    ls -a | sort
}



As an Amazon Associate I earn from qualifying purchases.

The "ls" command with sorting

The Mac/Unix "ls" command does not include sorting by file name. 

To get it done I added a new function in Bash to my ~/.bash_profile


# ls with sort - updated: February 13, 2018
function list()
{
    if [ "$1" != "" ]; then
        ls -a $1 | sort
    fi
   
    ls -a | sort
}



As an Amazon Associate I earn from qualifying purchases.

sed command line tool

The sed command line tool allows you to pipe a string of text and substitute part of it.

Note that it does for the first occurrence only:



$ echo "my, this is my sentence" | sed 's/my/My/'
My, this is my sentence


Escaping forward slashes with the backslashes:


$ echo "convert /usr/local/bin to /common/bin" | sed "s/\/usr\/local\/bin/\/common\/bin/"
convert /common/bin to /common/bin



$ echo "Repeat me 5 times." | sed 's/[0-9]/& & & & &/'

Repeat me 5 5 5 5 5 times.



As an Amazon Associate I earn from qualifying purchases.

sed command line tool

The sed command line tool allows you to pipe a string of text and substitute part of it.

Note that it does for the first occurrence only:



$ echo "my, this is my sentence" | sed 's/my/My/'
My, this is my sentence


Escaping forward slashes with the backslashes:


$ echo "convert /usr/local/bin to /common/bin" | sed "s/\/usr\/local\/bin/\/common\/bin/"
convert /common/bin to /common/bin



$ echo "Repeat me 5 times." | sed 's/[0-9]/& & & & &/'

Repeat me 5 5 5 5 5 times.



As an Amazon Associate I earn from qualifying purchases.

AWS

Notes on how I use Amazon AWS EC2 instances for Convolutional Deep Neural Networks Machine Learning, using powerful GPU CUDA configurations.

I have moved this post to:

https://ukidlucas.github.io/posts/AWS.html


As an Amazon Associate I earn from qualifying purchases.

AWS

Notes on how I use Amazon AWS EC2 instances for Convolutional Deep Neural Networks Machine Learning, using powerful GPU CUDA configurations.

I have moved this post to:

https://ukidlucas.github.io/posts/AWS.html


As an Amazon Associate I earn from qualifying purchases.

Installing Ubuntu 18.04 LTS on AMD box using USB stick created on Mac

Overview


I am installing Ubuntu 18.04.1 LTS desktop (as of November 9, 2018) on an old AMD box I had sitting around, the computer has NVidia 1050 I use for TensorFlow Machine Learning.

Download Ubuntu Desktop (amd64)


https://www.ubuntu.com/download/desktop

Prepare USB Drive

Note: At first, I tried 32GB drive, but the target computer did not recognize it, then I switched to a smaller USB stick. I used Disk Utility to format it in DOS FAT 32.
$ diskutil list
/dev/disk2 (external, physical): #:
DOS_FAT_32 UBUNTU18_04 7.9 GB disk2s1

Install UNetBooting

https://unetbootin.github.io/ 




Install disk image (ISO) on the USB drive


  • Check your USB drive name with "diskutil list" (disk2s1 for me)
  • Open "UNetBooting" and select:
  • Diskimage (radio button)
  • ISO file location
  • disk2s1 as the USB Drive
  • click OK, it will take a long while


Insert the USB into the target AMD computer


Enter BIOS Setup

Attach a keyboard to your computer.
Start the computer while pressing F10 key to enter BIOS setup. This might be different for your computer model. 
In the BIOS you may want to TRY to set up USB (or external mass storage device) as first in the BOOT priority. but my computer did not have that option.

Entering the USB boot with ESC, ESC, ESC

I was able to enter USB boot by starting the computer and pressing ESC key repeatedly.

From here I was shown "UNetBooting" utility and had the option to "Try Ubuntu without installing" which I chose.

Ubuntu Starts

My first impression of Ubuntu 18.04 LTS is that it is much cleaner and modern, it is not Mac OS just yet, but it fills nice.
  • I checked the browser and the Internet was on, via Ethernet cable.
  • The resolution is very good, 1920x1080
  • On the desktop, I had the option to "Install Ubuntu", I followed their easy steps.
  • I chose "Erase disk and Install Ubuntu" as I had old windows and Ubuntu 16.04 on it that I did not want to keep. I needed max space for machine learning datasets.
  • The installation process was very pleasant and modern.
  • Once the installation finished, remove the USB and restart the computer.
Happy Ubuntu computing!












As an Amazon Associate I earn from qualifying purchases.

Installing Ubuntu 18.04 LTS on AMD box using USB stick created on Mac

Overview


I am installing Ubuntu 18.04.1 LTS desktop (as of November 9, 2018) on an old AMD box I had sitting around, the computer has NVidia 1050 I use for TensorFlow Machine Learning.

Download Ubuntu Desktop (amd64)


https://www.ubuntu.com/download/desktop

Prepare USB Drive

Note: At first, I tried 32GB drive, but the target computer did not recognize it, then I switched to a smaller USB stick. I used Disk Utility to format it in DOS FAT 32.
$ diskutil list
/dev/disk2 (external, physical): #:
DOS_FAT_32 UBUNTU18_04 7.9 GB disk2s1

Install UNetBooting

https://unetbootin.github.io/ 




Install disk image (ISO) on the USB drive


  • Check your USB drive name with "diskutil list" (disk2s1 for me)
  • Open "UNetBooting" and select:
  • Diskimage (radio button)
  • ISO file location
  • disk2s1 as the USB Drive
  • click OK, it will take a long while


Insert the USB into the target AMD computer


Enter BIOS Setup

Attach a keyboard to your computer.
Start the computer while pressing F10 key to enter BIOS setup. This might be different for your computer model. 
In the BIOS you may want to TRY to set up USB (or external mass storage device) as first in the BOOT priority. but my computer did not have that option.

Entering the USB boot with ESC, ESC, ESC

I was able to enter USB boot by starting the computer and pressing ESC key repeatedly.

From here I was shown "UNetBooting" utility and had the option to "Try Ubuntu without installing" which I chose.

Ubuntu Starts

My first impression of Ubuntu 18.04 LTS is that it is much cleaner and modern, it is not Mac OS just yet, but it fills nice.
  • I checked the browser and the Internet was on, via Ethernet cable.
  • The resolution is very good, 1920x1080
  • On the desktop, I had the option to "Install Ubuntu", I followed their easy steps.
  • I chose "Erase disk and Install Ubuntu" as I had old windows and Ubuntu 16.04 on it that I did not want to keep. I needed max space for machine learning datasets.
  • The installation process was very pleasant and modern.
  • Once the installation finished, remove the USB and restart the computer.
Happy Ubuntu computing!












As an Amazon Associate I earn from qualifying purchases.

Running Groovy with multiple command line parameters


Source for ArgumentsTest.groovy


#!/bin/bash
//usr/bin/env groovy  -cp extra.jar:spring.jar:etc.jar -d -Dlog4j.configuration=file:/etc/myapp/log4j.xml "$0" $@; exit $?


def params = ""
args.each() {
    if (it) {
        params +=   it + "! "
    }
}

println "Hello World " + params

Execute permission

$ sudo chmod +x ArgumentsTest.groovy
Password:

Output


$ ./ArgumentsTest.groovy Uki Natalia Zoe
Hello World Uki! Natalia! Zoe!


As an Amazon Associate I earn from qualifying purchases.

Running Groovy with multiple command line parameters


Source for ArgumentsTest.groovy


#!/bin/bash
//usr/bin/env groovy  -cp extra.jar:spring.jar:etc.jar -d -Dlog4j.configuration=file:/etc/myapp/log4j.xml "$0" $@; exit $?


def params = ""
args.each() {
    if (it) {
        params +=   it + "! "
    }
}

println "Hello World " + params

Execute permission

$ sudo chmod +x ArgumentsTest.groovy
Password:

Output


$ ./ArgumentsTest.groovy Uki Natalia Zoe
Hello World Uki! Natalia! Zoe!


As an Amazon Associate I earn from qualifying purchases.

git: updating all repos using Bash

I have a lot (hundreds) of repositories I want to keep updated on daily basis, here is a handy script I use:


# saving current working directory
cwd=$(pwd)

echo "reading each repo directory in $cwd"
for repo in *
do
echo '#################################################'
# change to give repo directory
cd $repo
# print repo url
    git config --get remote.origin.url
    git fetch
    git status
    # go back to directory you started with
    cd $cwd
done
}

If you like this post, please give me your 2 cents ($0.02 litterally) to show token of appreciation and encourage me to write more:

Donate Bitcoins



As an Amazon Associate I earn from qualifying purchases.

git: updating all repos using Bash

I have a lot (hundreds) of repositories I want to keep updated on daily basis, here is a handy script I use:


# saving current working directory
cwd=$(pwd)

echo "reading each repo directory in $cwd"
for repo in *
do
echo '#################################################'
# change to give repo directory
cd $repo
# print repo url
    git config --get remote.origin.url
    git fetch
    git status
    # go back to directory you started with
    cd $cwd
done
}

If you like this post, please give me your 2 cents ($0.02 litterally) to show token of appreciation and encourage me to write more:

Donate Bitcoins



As an Amazon Associate I earn from qualifying purchases.

UNIX: create symbolic link ln -s

Symbolic link is a directory that points to another directory:

$ sudo ln -s TARGET_DIR SYMBOLIC_LINK_DIR



Example 1:

$ cd /System/Library/Frameworks/JavaVM.framework/Versions

$ sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/ "1.8.0_20-ea"
$ ls -alt
lrwxr-xr-x  1 root  wheel   59 May 14 16:24 1.8.0_20-ea -> /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/


Example 2:

Debian linux Apache location: /var/www
Mac Apache default location: /Library/WebServer/Document

On Mac to mimic the Debian linux's Apache server in /var/www you can create a symbolic link that points to Mac's default server location:


$ sudo ln -s /Library/WebServer/Documents www



originally posted on 7/24/2009

If you like this post, please give me your 2 cents ($0.02 litterally) to show token of appreciation and encourage me to write more:

Donate Bitcoins



As an Amazon Associate I earn from qualifying purchases.

UNIX: create symbolic link ln -s

Symbolic link is a directory that points to another directory:

$ sudo ln -s TARGET_DIR SYMBOLIC_LINK_DIR



Example 1:

$ cd /System/Library/Frameworks/JavaVM.framework/Versions

$ sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/ "1.8.0_20-ea"
$ ls -alt
lrwxr-xr-x  1 root  wheel   59 May 14 16:24 1.8.0_20-ea -> /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/


Example 2:

Debian linux Apache location: /var/www
Mac Apache default location: /Library/WebServer/Document

On Mac to mimic the Debian linux's Apache server in /var/www you can create a symbolic link that points to Mac's default server location:


$ sudo ln -s /Library/WebServer/Documents www



originally posted on 7/24/2009

If you like this post, please give me your 2 cents ($0.02 litterally) to show token of appreciation and encourage me to write more:

Donate Bitcoins



As an Amazon Associate I earn from qualifying purchases.

Linux: RPM

Here is couple of functions I use when working with RPM packages:


Show containing "postg"

rpm -qa | grep postg


Show top 20:

rpm -qa | tail -20



Install package:

rpm -ivh somed-1.0.0.armv7l


Uninstall:

rpm -e somed-1.0.0.armv7l







As an Amazon Associate I earn from qualifying purchases.

Linux: RPM

Here is couple of functions I use when working with RPM packages:


Show containing "postg"

rpm -qa | grep postg


Show top 20:

rpm -qa | tail -20



Install package:

rpm -ivh somed-1.0.0.armv7l


Uninstall:

rpm -e somed-1.0.0.armv7l







As an Amazon Associate I earn from qualifying purchases.

Cleaning space on Linux board (SD memory)

Check available space - none left

# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       3.5G  3.3G     0 100% /



List files in a suspicious directory by SIZE:

# ls -alS

Remove biggest offenders


# rm -rf /var/cores/*

# rm -rf /var/log/*


Check space available - 89% utilization

# df -hFilesystem     

Size  Used Avail Use% Mounted

on
/dev/root       3.5G  3.0G  370M  89% /



As an Amazon Associate I earn from qualifying purchases.

apt quotation..