Showing posts with label Windows CMD. Show all posts
Showing posts with label Windows CMD. Show all posts

Wednesday, October 26, 2022

SSH Setup For Accessing Ubuntu From Windows Using SFTP

Getting Basic Info Like Hostname and IP

(base) C:\Users\ashish>hostname CS3L (base) C:\Users\ashish>ipconfig Windows IP Configuration Ethernet adapter Ethernet 2: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : ad.itli.com Ethernet adapter Ethernet: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : ad.itli.com Wireless LAN adapter Wi-Fi: Connection-specific DNS Suffix . : IPv6 Address. . . . . . . . . . . : 2401:4900:47f2:5147:b1b2:6d59:f669:1b96 Temporary IPv6 Address. . . . . . : 2401:4900:47f2:5147:15e3:46:9f5b:8d78 Link-local IPv6 Address . . . . . : fe80::b1b2:6d59:f669:1b96%13 IPv4 Address. . . . . . . . . . . : 192.168.1.100 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : fe80::d837:1aff:fe40:b173%13 192.168.1.1 Ethernet adapter Bluetooth Network Connection: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . :

Setting up SSH

(base) C:\Users\ashish>mkdir .ssh (base) C:\Users\ashish>dir Volume in drive C is OSDisk Volume Serial Number is ABCD-PQRS Directory of C:\Users\ashish 10/26/2022 03:25 PM <DIR> . 10/26/2022 03:25 PM <DIR> .. 08/16/2022 01:29 PM <DIR> .3T 09/26/2022 08:04 AM 1,288 .bash_history 06/02/2022 10:15 AM <DIR> .cache 05/30/2022 11:39 AM <DIR> .conda 10/26/2022 02:58 PM 89 .dotty_history 08/19/2022 06:42 PM 68 .gitconfig 10/11/2022 02:03 PM <DIR> .ipython 05/30/2022 10:05 AM <DIR> .jupyter 05/30/2022 12:56 PM <DIR> .keras 08/20/2022 11:55 AM 20 .lesshst 07/04/2022 06:09 PM <DIR> .matplotlib 06/30/2022 10:32 AM <DIR> .ms-ad 10/07/2022 09:00 PM 1,457 .python_history 10/26/2022 03:25 PM <DIR> .ssh 09/06/2022 10:13 PM 2,379 .viminfo 05/30/2022 11:34 AM <DIR> .vscode 05/16/2022 03:19 PM <DIR> 3D Objects 10/07/2022 02:50 PM <DIR> Anaconda3 05/16/2022 03:19 PM <DIR> Contacts 10/26/2022 02:57 PM <DIR> Desktop 10/07/2022 06:27 PM <DIR> Documents 10/26/2022 03:18 PM <DIR> Downloads 05/16/2022 03:19 PM <DIR> Favorites 05/16/2022 03:19 PM <DIR> Links 05/16/2022 03:19 PM <DIR> Music 05/16/2022 02:13 PM <DIR> OneDrive 05/16/2022 03:20 PM <DIR> Pictures 05/16/2022 03:19 PM <DIR> Saved Games 05/16/2022 03:20 PM <DIR> Searches 05/30/2022 09:36 AM <DIR> Videos 6 File(s) 5,301 bytes 26 Dir(s) 81,987,842,048 bytes free (base) C:\Users\ashish>cd .ssh (base) C:\Users\ashish\.ssh>dir Volume in drive C is OSDisk Volume Serial Number is ABCD-PQRS Directory of C:\Users\ashish\.ssh 10/26/2022 03:25 PM <DIR> . 10/26/2022 03:25 PM <DIR> .. 0 File(s) 0 bytes 2 Dir(s) 81,987,903,488 bytes free (base) C:\Users\ashish\.ssh>echo "" > id_rsa (base) C:\Users\ashish\.ssh>dir Volume in drive C is OSDisk Volume Serial Number is ABCD-PQRS Directory of C:\Users\ashish\.ssh 10/26/2022 03:26 PM <DIR> . 10/26/2022 03:26 PM <DIR> .. 10/26/2022 03:26 PM 5 id_rsa 1 File(s) 5 bytes 2 Dir(s) 81,987,678,208 bytes free (base) C:\Users\ashish\.ssh>type id_rsa (base) C:\Users\ashish\.ssh> (base) C:\Users\ashish>ssh-keygen -t rsa -f ./.ssh/id_rsa -P "" Generating public/private rsa key pair. ./.ssh/id_rsa already exists. Overwrite (y/n)? y Your identification has been saved in ./.ssh/id_rsa. Your public key has been saved in ./.ssh/id_rsa.pub. The key fingerprint is: SHA256:fGEZHROeTzogrdXwo7haw0g3eXLVZnO9nM0ZtTbIBh8 itlitli\ashish@CS3L The key's randomart image is: +---[RSA 3072]----+ | oo+E .| | . B=+o +| | . B B=*=o| | . B =.Bo+B| | . S = o .=o| | . + B . | | . = | | o . | | . | +----[SHA256]-----+ (base) C:\Users\ashish>

Note This Error While Doing Setup on Windows

CMD> ssh-copy-id -i ./.ssh/id_rsa.pub ashish@192.168.1.100 'ssh-copy-id' is not recognized as an internal or external command, operable program or batch file.

We overcome this issue by manually copying Public RSA Key into the 'authorized_keys' file of the remote machine using SFTP.

(base) C:\Users\ashish>sftp usage: sftp [-46aCfpqrv] [-B buffer_size] [-b batchfile] [-c cipher] [-D sftp_server_path] [-F ssh_config] [-i identity_file] [-J destination] [-l limit] [-o ssh_option] [-P port] [-R num_requests] [-S program] [-s subsystem | sftp_server] destination

Next Steps of Copying Pubic Key Onto Remote Machine And Vice-versa

Address of Ubuntu System: ashish@192.168.1.151

(base) C:\Users\ashish>sftp ashish@192.168.1.151 The authenticity of host '192.168.1.151 (192.168.1.151)' can't be established. ECDSA key fingerprint is SHA256:2hgOVHHgkrT9/6XnK/KDaFQ0DaXLUoW82eeU6oQyTvQ. Are you sure you want to continue connecting (yes/no/[fingerprint])? Warning: Permanently added '192.168.1.151' (ECDSA) to the list of known hosts. ashish@192.168.1.151's password: Connected to 192.168.1.151. sftp> ls Desktop Documents Downloads Music Pictures Public Templates Videos anaconda3 nltk_data snap sftp> bye

PWD: /home/ashish

sftp> put id_rsa.pub win_auth_key.txt Uploading id_rsa.pub to /home/ashish/win_auth_key.txt id_rsa.pub 100% 593 89.9KB/s 00:00 sftp>

PWD: /home/ashish/.ssh

sftp> get id_rsa.pub ./ubuntu_id_rsa.pub.txt Fetching /home/ashish/.ssh/id_rsa.pub to ./ubuntu_id_rsa.pub.txt /home/ashish/.ssh/id_rsa.pub 100% 573 2.7KB/s 00:00 sftp> sftp> bye

Steps on Ubuntu Machine

(base) ashish@ashishlaptop:~$ cat win_auth_key.txt ssh-rsa AAA***vZs= itli\ashish@CS3L (base) ashish@ashishlaptop:~$

Paste this Public RSA Key in 'authorized_keys' File

(base) ashish@ashishlaptop:~/.ssh$ nano authorized_keys (base) ashish@ashishlaptop:~/.ssh$ cat authorized_keys ssh-rsa AAAA***rzFM= ashish@ashishdesktop ssh-rsa AAAA***GOD0= ashish@ashishlaptop ssh-rsa AAAA***3vZs= itli\ashish@CS3L (base) ashish@ashishlaptop:~/.ssh$

Testing The SSH

Back to Windows 10 System

(base) C:\Users\ashish>ssh ashish@ashishlaptop The authenticity of host 'ashishlaptop (192.168.1.151)' can't be established. ECDSA key fingerprint is SHA256:2hgOVHHgkrT9/6XnK/KDaFQ0DaXLUoW82eeU6oQyTvQ. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'ashishlaptop' (ECDSA) to the list of known hosts. Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-52-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage 2 updates can be applied immediately. To see these additional updates run: apt list --upgradable Last login: Wed Oct 26 13:35:44 2022 from 192.168.1.151 (base) ashish@ashishlaptop:~$ (base) ashish@ashishlaptop:~$ ls anaconda3 Desktop Documents Downloads Music nltk_data Pictures Public snap Templates Videos win_auth_key.txt (base) ashish@ashishlaptop:~$ rm win_auth_key.txt (base) ashish@ashishlaptop:~$ ls anaconda3 Desktop Documents Downloads Music nltk_data Pictures Public snap Templates Videos (base) ashish@ashishlaptop:~$ exit logout Connection to ashishlaptop closed. (base) C:\Users\ashish>ssh ashish@ashishlaptop Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-52-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage 2 updates can be applied immediately. To see these additional updates run: apt list --upgradable Last login: Wed Oct 26 15:46:02 2022 from 192.168.1.100 (base) ashish@ashishlaptop:~$ client_loop: send disconnect: Connection reset (base) C:\Users\ashish>
Tags: Technology,SSH,Linux,Windows CMD,

Saturday, October 9, 2021

That what DIR shows, XCOPY copies



$ dir /s *.ppt*

Volume in drive F has no label.
Volume Serial Number is 6137-6435

Directory of ~\Artificial Intelligence\AI and disciplines it borrows ideas from (20210304)

04/27/2021  01:39 PM           178,384 AI and disciplines it borrows from (20210304).pptx
                1 File(s)        178,384 bytes

Directory of ~\Artificial Intelligence\Career Road Map for Artificial Intelligence & Data Science [20210725]

07/24/2021  12:02 PM           521,685 Career Road-Map for Artificial Intelligence & Data Science.pptx
                1 File(s)        521,685 bytes

Directory of ~\Machine Learning\Classification\Naive Bayes Classifier for Spam Filtering

07/27/2021  07:47 PM         9,358,328 Naive Bayes Classifier for Spam Filtering.pptx
                1 File(s)      9,358,328 bytes

Directory of ~\Machine Learning\Regression\Linear Regression (Theory 20210715)

07/15/2021  12:32 PM         4,869,791 Linear Regression.pptx
                1 File(s)      4,869,791 bytes

Directory of ~\Machine Learning\Regression\Improvements over OLS (Forward Stepwise, Ridge, Lasso, LARS)

07/17/2021  05:12 PM           723,056 Improvements over OLS (Forward Stepwise, Ridge, Lasso, LARS).pptx
                1 File(s)        723,056 bytes

Directory of ~\Natural Language Processing\Session 1 on `Understanding, Analyzing and Generating Text'

07/20/2021  05:16 PM         1,503,410 Session 1 on `Understanding, Analyzing and Generating Text'.pptx
                1 File(s)      1,503,410 bytes

Directory of ~\Natural Language Processing\Sentiment Analysis\VADER - Rule Based Approach to Sentiment Analysis

07/22/2021  12:48 PM           340,528 Session 2 on `Understanding, Analyzing and Generating Text'.pptx
                1 File(s)        340,528 bytes

Directory of ~\Natural Language Processing\Word Embeddings\Document Parsing, Document based Embeddings and Word Embeddings

08/15/2021  10:19 PM           849,022 Document Parsing, Document based Embeddings and Word Embeddings.pptx
                1 File(s)        849,022 bytes

Directory of ~\Web Development\JavaScript\JavaScript Intro (Dev Console, Data Types and Operators)

07/26/2021  07:03 PM           231,542 JavaScript.pptx
                1 File(s)        231,542 bytes

    Total Files Listed:
                9 File(s)     18,575,746 bytes
                0 Dir(s)  587,115,003,904 bytes free 

$ dir /s /b *.ppt*

~\Artificial Intelligence\AI and disciplines it borrows ideas from (20210304)\AI and disciplines it borrows from (20210304).pptx
~\Artificial Intelligence\Career Road Map for Artificial Intelligence & Data Science [20210725]\Career Road-Map for Artificial Intelligence & Data Science.pptx
~\Machine Learning\Classification\Naive Bayes Classifier for Spam Filtering\Naive Bayes Classifier for Spam Filtering.pptx
~\Machine Learning\Regression\Linear Regression (Theory 20210715)\Linear Regression.pptx
~\Machine Learning\Regression\Improvements over OLS (Forward Stepwise, Ridge, Lasso, LARS)\Improvements over OLS (Forward Stepwise, Ridge, Lasso, LARS).pptx
~\Natural Language Processing\Session 1 on `Understanding, Analyzing and Generating Text'\Session 1 on `Understanding, Analyzing and Generating Text'.pptx
~\Natural Language Processing\Sentiment Analysis\VADER - Rule Based Approach to Sentiment Analysis\Session 2 on `Understanding, Analyzing and Generating Text'.pptx
~\Natural Language Processing\Word Embeddings\Document Parsing, Document based Embeddings and Word Embeddings\Document Parsing, Document based Embeddings and Word Embeddings.pptx
~\Web Development\JavaScript\JavaScript Intro (Dev Console, Data Types and Operators)\JavaScript.pptx 

~\vscode>xcopy /s *.ppt* F:\xcopy

~\Artificial Intelligence\AI and disciplines it borrows ideas from (20210304)\AI and disciplines it borrows from (20210304).pptx
~\Artificial Intelligence\Career Road Map for Artificial Intelligence & Data Science [20210725]\Career Road-Map for Artificial Intelligence & Data Science.pptx
~\Machine Learning\Classification\Naive Bayes Classifier for Spam Filtering\Naive Bayes Classifier for Spam Filtering.pptx
~\Machine Learning\Regression\Linear Regression (Theory 20210715)\Linear Regression.pptx
~\Machine Learning\Regression\Improvements over OLS (Forward Stepwise, Ridge, Lasso, LARS)\Improvements over OLS (Forward Stepwise, Ridge, Lasso, LARS).pptx
~\Natural Language Processing\Session 1 on `Understanding, Analyzing and Generating Text'\Session 1 on `Understanding, Analyzing and Generating Text'.pptx
~\Natural Language Processing\Sentiment Analysis\VADER - Rule Based Approach to Sentiment Analysis\Session 2 on `Understanding, Analyzing and Generating Text'.pptx
~\Natural Language Processing\Word Embeddings\Document Parsing, Document based Embeddings and Word Embeddings\Document Parsing, Document based Embeddings and Word Embeddings.pptx
~\Web Development\JavaScript\JavaScript Intro (Dev Console, Data Types and Operators)\JavaScript.pptx 
9 File(s) copied 
    

Xcopy Help

~\vscode>xcopy /? Copies files and directory trees. XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W] [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U] [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z] [/B] [/J] [/EXCLUDE:file1[+file2][+file3]...] [/COMPRESS] source Specifies the file(s) to copy. destination Specifies the location and/or name of new files. /A Copies only files with the archive attribute set, doesn't change the attribute. /M Copies only files with the archive attribute set, turns off the archive attribute. /D:m-d-y Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time. /EXCLUDE:file1[+file2][+file3]... Specifies a list of files containing strings. Each string should be in a separate line in the files. When any of the strings match any part of the absolute path of the file to be copied, that file will be excluded from being copied. For example, specifying a string like \obj\ or .obj will exclude all files underneath the directory obj or all files with the .obj extension respectively. /P Prompts you before creating each destination file. /S Copies directories and subdirectories except empty ones. /E Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T. /V Verifies the size of each new file. /W Prompts you to press a key before copying. /C Continues copying even if errors occur. /I If destination does not exist and copying more than one file, assumes that destination must be a directory. /Q Does not display file names while copying. /F Displays full source and destination file names while copying. /L Displays files that would be copied. /G Allows the copying of encrypted files to destination that does not support encryption. /H Copies hidden and system files also. /R Overwrites read-only files. /T Creates directory structure, but does not copy files. Does not include empty directories or subdirectories. /T /E includes empty directories and subdirectories. /U Copies only files that already exist in destination. /K Copies attributes. Normal Xcopy will reset read-only attributes. /N Copies using the generated short names. /O Copies file ownership and ACL information. /X Copies file audit settings (implies /O). /Y Suppresses prompting to confirm you want to overwrite an existing destination file. /-Y Causes prompting to confirm you want to overwrite an existing destination file. /Z Copies networked files in restartable mode. /B Copies the Symbolic Link itself versus the target of the link. /J Copies using unbuffered I/O. Recommended for very large files. /COMPRESS Request network compression during file transfer where applicable. The switch /Y may be preset in the COPYCMD environment variable. This may be overridden with /-Y on the command line.

Application of "for" with "xcopy" to discard folder structure but keep the files

~\vscode>for /r %i in (*.ppt*) do xcopy /Y "%i" f:\someplace ~\vscode>xcopy /Y "~\vscode\Lessons in Technology\Artificial Intelligence\AI and disciplines it borrows ideas from (20210304)\AI and disciplines it borrows from (20210304).pptx" f:\someplace Does F:\someplace specify a file name or directory name on the target (F = file, D = directory)? D ~\vscode\Lessons in Technology\Artificial Intelligence\AI and disciplines it borrows ideas from (20210304)\AI and disciplines it borrows from (20210304).pptx 1 File(s) copied ~\vscode>xcopy /Y "~\vscode\Lessons in Technology\Artificial Intelligence\Career Road Map for Artificial Intelligence & Data Science [20210725]\Career Road-Map for Artificial Intelligence & Data Science.pptx" f:\someplace ~\vscode\Lessons in Technology\Artificial Intelligence\Career Road Map for Artificial Intelligence & Data Science [20210725]\Career Road-Map for Artificial Intelligence & Data Science.pptx 1 File(s) copied ~\vscode>xcopy /Y "~\vscode\Lessons in Technology\Machine Learning\Classification\Naïve Bayes Classifier for Spam Filtering\Naïve Bayes Classifier for Spam Filtering.pptx" f:\someplace ~\vscode\Lessons in Technology\Machine Learning\Classification\Naïve Bayes Classifier for Spam Filtering\Naïve Bayes Classifier for Spam Filtering.pptx 1 File(s) copied ~\vscode>xcopy /Y "~\vscode\Lessons in Technology\Machine Learning\Regression\Linear Regression (Theory 20210715)\Linear Regression.pptx" f:\someplace ~\vscode\Lessons in Technology\Machine Learning\Regression\Linear Regression (Theory 20210715)\Linear Regression.pptx 1 File(s) copied ~\vscode>xcopy /Y "~\vscode\Lessons in Technology\Machine Learning\Regression\Improvements over OLS (Forward Stepwise, Ridge, Lasso, LARS)\Improvements over OLS (Forward Stepwise, Ridge, Lasso, LARS).pptx" f:\someplace ~\vscode\Lessons in Technology\Machine Learning\Regression\Improvements over OLS (Forward Stepwise, Ridge, Lasso, LARS)\Improvements over OLS (Forward Stepwise, Ridge, Lasso, LARS).pptx 1 File(s) copied ~\vscode>xcopy /Y "~\vscode\Lessons in Technology\Natural Language Processing\Session 1 on ‘Understanding, Analyzing and Generating Text'\Session 1 on ‘Understanding, Analyzing and Generating Text'.pptx" f:\someplace ~\vscode\Lessons in Technology\Natural Language Processing\Session 1 on ‘Understanding, Analyzing and Generating Text'\Session 1 on ‘Understanding, Analyzing and Generating Text'.pptx 1 File(s) copied ~\vscode>xcopy /Y "~\vscode\Lessons in Technology\Natural Language Processing\Sentiment Analysis\VADER - Rule Based Approach to Sentiment Analysis\Session 2 on ‘Understanding, Analyzing and Generating Text'.pptx" f:\someplace ~\vscode\Lessons in Technology\Natural Language Processing\Sentiment Analysis\VADER - Rule Based Approach to Sentiment Analysis\Session 2 on ‘Understanding, Analyzing and Generating Text'.pptx 1 File(s) copied ~\vscode>xcopy /Y "~\vscode\Lessons in Technology\Natural Language Processing\Word Embeddings\Document Parsing, Document based Embeddings and Word Embeddings\Document Parsing, Document based Embeddings and Word Embeddings.pptx" f:\someplace ~\vscode\Lessons in Technology\Natural Language Processing\Word Embeddings\Document Parsing, Document based Embeddings and Word Embeddings\Document Parsing, Document based Embeddings and Word Embeddings.pptx 1 File(s) copied ~\vscode>xcopy /Y "~\vscode\Lessons in Technology\Web Development\JavaScript\JavaScript Intro (Dev Console, Data Types and Operators)\JavaScript.pptx" f:\someplace ~\vscode\Lessons in Technology\Web Development\JavaScript\JavaScript Intro (Dev Console, Data Types and Operators)\JavaScript.pptx 1 File(s) copied ~\vscode>

When writing code in .BAT file

If you are using this in a batchfile, you should double the % like this: for /r %%i in (*.txt) do xcopy /Y "%%i" g:\someplace
Tags: Technology,Windows CMD,

Wednesday, September 1, 2021

Managing task on Windows using CMD



Managing task on Windows using CMD using "tasklist", "taskkill" and "findstr".

(base) CMD>tasklist | findstr "WINWORD*"
WINWORD.EXE --  3164 Console --   7    251,092 K
WINWORD.EXE --  9292 Console --   7    245,508 K
WINWORD.EXE -- 13640 Console --   7    246,748 K
WINWORD.EXE -- 10288 Console --   7    242,704 K
WINWORD.EXE -- 19244 Console --   7    246,996 K
WINWORD.EXE -- 18416 Console --   7    246,552 K
WINWORD.EXE -- 12380 Console --   7    163,932 K

(base) CMD>taskkill /F /PID 3164
SUCCESS: The process with PID 3164 has been terminated.

(base) CMD>taskkill /IM "WINWORD.exe" /F
SUCCESS: The process "WINWORD.EXE" with PID 13640 has been terminated.
SUCCESS: The process "WINWORD.EXE" with PID 10288 has been terminated.
SUCCESS: The process "WINWORD.EXE" with PID 19244 has been terminated.
SUCCESS: The process "WINWORD.EXE" with PID 18416 has been terminated.
SUCCESS: The process "WINWORD.EXE" with PID 12380 has been terminated.

Tags: Technology,Windows CMD,

Wednesday, June 2, 2021

Command 'git clone'



Cloning a repository with only the URL

(base) ~\ws>git clone https://github.com/ashishjain1547/repo_for_testing.git Cloning into 'repo_for_testing'... Logon failed, use ctrl+c to cancel basic credential prompt. Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': remote: Enumerating objects: 16, done. remote: Counting objects: 100% (16/16), done. remote: Compressing objects: 100% (9/9), done. remote: Total 16 (delta 5), reused 10 (delta 3), pack-reused 0 Unpacking objects: 100% (16/16), 5.70 KiB | 12.00 KiB/s, done. (base) ~\ws>tree /f Folder PATH listing for volume Windows Volume serial number is 8139-90C0 C:. └───repo_for_testing .gitignore LICENSE newFile.txt README.md test_file_20210528.txt (base) ~\ws>cd repo_for_testing (base) ~\ws\repo_for_testing>git branch * main (base) ~\ws\repo_for_testing>git branch -a * main remotes/origin/HEAD -> origin/main remotes/origin/main remotes/origin/test_branch (base) ~\ws\repo_for_testing>git branch -r origin/HEAD -> origin/main origin/main origin/test_branch (base) ~\ws\repo_for_testing>git branch -D fatal: branch name required

Cloning a repository with URL and branch name.

(base) ~\ws_diff_branch>git clone --branch test_branch https://github.com/ashishjain1547/repo_for_testing.git Cloning into 'repo_for_testing'... remote: Enumerating objects: 16, done. remote: Counting objects: 100% (16/16), done. remote: Compressing objects: 100% (9/9), done. remote: Total 16 (delta 5), reused 10 (delta 3), pack-reused 0 Unpacking objects: 100% (16/16), 5.70 KiB | 8.00 KiB/s, done. (base) ~\ws_diff_branch>cd repo_for_testing (base) ~\ws_diff_branch\repo_for_testing>git branch * test_branch (base) ~\ws_diff_branch\repo_for_testing>git branch -a * test_branch remotes/origin/HEAD -> origin/main remotes/origin/main remotes/origin/test_branch (base) ~\ws_diff_branch\repo_for_testing>git branch -r origin/HEAD -> origin/main origin/main origin/test_branch

Notes From Bitbucket

#1 Cloning to a specific folder git clone <repo> <directory> Clone the repository located at <repo> into the folder called ~<directory>! on the local machine. #2 Cloning a specific tag git clone --branch <tag> <repo> Clone the repository located at <repo> and only clone the ref for <tag>. #3 Shallow clone git clone -depth=1 <repo> Clone the repository located at <repo> and only clone the history of commits specified by the option depth=1. In this example a clone of <repo> is made and only the most recent commit is included in the new cloned Repo. Shallow cloning is most useful when working with repos that have an extensive commit history. An extensive commit history may cause scaling problems such as disk space usage limits and long wait times when cloning. A Shallow clone can help alleviate these scaling issues. Ref: Bitbucket [20210602] Tags: Technology,GitHub,Cloud,Windows CMD,

Sunday, May 16, 2021

Python (1) (virtualenv and condaenv) [20210516]



Hello friends, to begin with the first thing we have to do is installation:

% You can download and install 'Python' from here: Python Downloads
% Or, you can download Anaconda from here: Anaconda Downloads

For those who do not know what Anaconda is, here is a one-liner: It is your data science toolkit. [As written on the Anaconda website]

You should note that knowledge of both Python and Anaconda is important as Anaconda makes things very simple and manageable, but some organization will not allow you to install 'Anaconda' and you would have to work with Python only.

Today as this is the first session that I am taking, we would be discussing about installation of Python on Windows and Linux machines. That is because this is an especially important step as in future you would have to install and work with a lot of Python packages and at times there would conflicts as you would keep on increasing the number of package installations in your system.
For example: if you do a “pip install tensorflow” on your system that will install the latest version of the TensorFlow and now if you try to install a package (let us say) Elephas that would lead to conflict in packages as the dependencies of Elephas require you to have an incredibly old version of TensorFlow.

The dependencies of the Elephas as of 2020-July were:

Flask==1.0.2
hyperas==0.4
pyspark==2.4.0
six==1.11.0
tensorflow==1.15.2
pydl4j>=0.1.3
keras==2.2.5

Now we check the current version of TensorFlow available:

CMD>pip install tensorflow==

ERROR: Could not find a version that satisfies the requirement tensorflow== (from versions: 1.13.0rc1, 1.13.0rc2, 1.13.1, 1.13.2, 1.14.0rc0, 1.14.0rc1, 1.14.0, 1.15.0rc0, 1.15.0rc1, 1.15.0rc2, 1.15.0rc3, 1.15.0, 1.15.2, 1.15.3, 1.15.4, 1.15.5, 2.0.0a0, 2.0.0b0, 2.0.0b1, 2.0.0rc0, 2.0.0rc1, 2.0.0rc2, 2.0.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.1.0rc0, 2.1.0rc1, 2.1.0rc2, 2.1.0, 2.1.1, 2.1.2, 2.1.3, 2.2.0rc0, 2.2.0rc1, 2.2.0rc2, 2.2.0rc3, 2.2.0rc4, 2.2.0, 2.2.1, 2.2.2, 2.3.0rc0, 2.3.0rc1, 2.3.0rc2, 2.3.0, 2.3.1, 2.3.2, 2.4.0rc0, 2.4.0rc1, 2.4.0rc2, 2.4.0rc3, 2.4.0rc4, 2.4.0, 2.4.1, 2.5.0rc0, 2.5.0rc1, 2.5.0rc2, 2.5.0rc3, 2.5.0)
ERROR: No matching distribution found for tensorflow==

Latest version of TensorFlow is 2.5.0.

Ref: Distributed Deep Learning Using Python Packages Elephas, Keras, Tensorflow and PySpark

This problem of dependencies is not only between packages but also between the version of Python you are using and a package such as Rasa.

As of Rasa 2.6.x, you need a Python from one of the following versions only: 3.6, 3.7 or 3.8 
[ Ref: 
% rasa/installation  
% rasa/2.5.x/installation ]

Even though the current version of Python is: 3.9

What is the solution? 
To deal with this we have a solution called:
1. 'virtual environment' in Python
2. 'conda environment' in Anaconda

We have an older version of Python in my system:


C:\Users\Ashish Jain>python
Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> print("Hi")
Hi
>>>
>>> exit()
C:\Users\Ashish Jain>

On a sidenote, if you want to see where your Python.exe is:
1. On Ubuntu, use "which python"
2. On Windows, use "where python"


C:\Users\Ashish Jain>where python
E:\programfiles\Anaconda3\python.exe
C:\Users\Ashish Jain\AppData\Local\Microsoft\WindowsApps\python.exe 

Setting up "virtualenv"

Step 1: Install "virtualenv" C:\Users\Ashish Jain>pip install virtualenv Collecting virtualenv Downloading virtualenv-20.4.6-py2.py3-none-any.whl (7.2 MB) |███| 7.2 MB 1.6 MB/s Collecting appdirs[2,>=1.4.3 Downloading appdirs-1.4.4-py2.py3-none-any.whl (9.6 kB) Requirement already satisfied: importlib-metadata>=0.12; python_version < "3.8" in e:\programfiles\anaconda3\lib\site-packages (from virtualenv) (1.7.0) Requirement already satisfied: six[2,>=1.9.0 in e:\programfiles\anaconda3\lib\site-packages (from virtualenv) (1.15.0) Collecting distlib[1,>=0.3.1 Downloading distlib-0.3.1-py2.py3-none-any.whl (335 kB) |███| 335 kB 3.2 MB/s Requirement already satisfied: filelock[4,>=3.0.0 in e:\programfiles\anaconda3\lib\site-packages (from virtualenv) (3.0.12) Requirement already satisfied: zipp>=0.5 in e:\programfiles\anaconda3\lib\site-packages (from importlib-metadata>=0.12; python_version < "3.8"->virtualenv) (3.1.0) Installing collected packages: appdirs, distlib, virtualenv Successfully installed appdirs-1.4.4 distlib-0.3.1 virtualenv-20.4.6 Step 2: Check where it is installed. C:\Users\Ashish Jain>where virtualenv E:\programfiles\Anaconda3\Scripts\virtualenv.exe Step 3: "virtualenv" creates a directory so you need to (additionally) set up a folder (like "my_workspace") where you would create virtual environments. Related projects, that build abstractions on top of virtualenv: % virtualenvwrapper - a useful set of scripts for creating and deleting virtual environments % pew - provides a set of commands to manage multiple virtual environments % tox - a generic virtualenv management and test automation command line tool, driven by a tox.ini configuration file % nox - a tool that automates testing in multiple Python environments, similar to tox, driven by a noxfile.py configuration file Ref: virtualenv Documentation C:\Users\Ashish Jain>cd OneDrive/Desktop/my_workspace Important difference between "Conda environment" and "Virtualenv": With "virtualenv" you cannot install lower (or previous) versions of Python but a higher (or newer) version. While, this limitation is not there in "conda env". C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace>virtualenv rasa_env --python=python3.8 RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.8' C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace>virtualenv rasa_env_2 --python=python3.8 RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.8' C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace>virtualenv rasa_env_2 --python=python3.6 created virtual environment CPython3.6.6.final.0-64 in 12325ms creator CPython3Windows(dest=C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace\rasa_env_2, clear=False, no_vcs_ignore=False, global=False) seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\Ashish Jain\AppData\Local\pypa\virtualenv) added seed packages: pip==21.1.1, setuptools==56.0.0, wheel==0.36.2 activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace>virtualenv rasa_env_3 --python=python3.8 RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.8' Step 4: We locate our "activate" file if we are on Ubuntu and "activate.bat" file if we are on Windows. C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace>dir /s "activate" Volume in drive C is Windows Volume Serial Number is 8139-90C0 Directory of C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace\rasa_env\Scripts 05/16/2021 12:54 AM 2,179 activate 1 File(s) 2,179 bytes Total Files Listed: 1 File(s) 2,179 bytes 0 Dir(s) 62,928,424,960 bytes free View 1: C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace>dir /s "activate*" Volume in drive C is Windows Volume Serial Number is 8139-90C0 Directory of C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace\rasa_env\Scripts 05/16/2021 12:54 AM 2,179 activate 05/16/2021 12:54 AM 1,052 activate.bat 05/16/2021 12:54 AM 3,102 activate.fish 05/16/2021 12:55 AM 1,755 activate.ps1 05/16/2021 12:55 AM 1,193 activate.xsh 05/16/2021 12:55 AM 1,193 activate_this.py 6 File(s) 10,474 bytes Total Files Listed: 12 File(s) 20,956 bytes 0 Dir(s) 62,889,410,560 bytes free View 2: C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace>dir /s /b "activate*" C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace\rasa_env\Scripts\activate C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace\rasa_env\Scripts\activate.bat C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace\rasa_env\Scripts\activate.fish C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace\rasa_env\Scripts\activate.ps1 C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace\rasa_env\Scripts\activate.xsh C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace\rasa_env\Scripts\activate_this.py C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace\rasa_env\Scripts>activate.bat (rasa_env) C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace\rasa_env\Scripts> Do you see this "(rasa_env)"? This means you are in venv "rasa_env".

Activate 'Python CLI' (Command Line Interface). Python CLI is also known as Python shell.

And Try Some Commands... (rasa_env) C:\Users\Ashish Jain\OneDrive\Desktop\my_workspace>python Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information. >>> Dealing with numeric data Addition >>> >>> 7 + 3 10 >>> Division >>> 7 / 3 2.3333333333333335 >>> >>> 7 // 3 2 >>> Modulo (returns the remainder from division operation) >>> 7 % 3 1 >>> Data Type: Strings >>> username = "Ashish" >>> print(username) Ashish >>> Note: You can do indexing on a String. >>> username[0] 'A' >>> But a Python String is immutable like a 'Tuple'. >>> username[0] = 'I' Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'str' object does not support item assignment >>> Output Formatting in Four Ways: Output Formatting #1 >>> print(F"Logged in as: {username}") Logged in as: Ashish >>> Output Formatting #2 >>> print("Logged in as: {}".format('Ashish')) Logged in as: Ashish >>> >>> print("Logged in as: {}".format(username)) Logged in as: Ashish >>> Output Formatting #3 >>> firstname = 'Ashish' >>> lastname = 'Jain' >>> print("Logged in as: %s %s" % (firstname, lastname)) Logged in as: Ashish Jain >>> Output Formatting #4 >>> print("Logged in as:", firstname, lastname) Logged in as: Ashish Jain >>> >>> print("Logged in as:", username) Logged in as: Ashish >>> Data Type: List List is a collection of elements (may not be of similar type as you would see in programming language C or C++). >>> l = ['a', 1] >>> l[0] 'a' >>> l[1] 1 >>> Data Type: Tuple Tuple is like the List data type with one difference that it is immutable. >>> my_tuple = (1, 2, 3) >>> my_tuple[0] 1 >>> my_tuple[0:3] (1, 2, 3) >>> >>> my_tuple[0] = 4 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'tuple' object does not support item assignment >>> Data Type: Dict (Dictionary) Important Note: What you are seeing as error for an attempt to concatenate two "dict" using "|" pipe character has been added as a feature in Python 3.9.0. >>> {'a': 'b'} | {'c': 'd'} Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for |: 'dict' and 'dict' >>> Multi-line String and Printing it. >>> >>> print("""Hi! ... I am Ashish! ... I love Python!""") Hi! I am Ashish! I love Python! >>> Checking the type of a variable: >>> type(username) <class 'str'> >>> >>> isinstance(username, str) True >>> >>> isinstance(username, int) False >>> isinstance(5, int) True Sometimes, the error logs of Python are not very clear. For example, in the example below we entered second argument as ('str') that is a string, instead of the keyword (str), so Python returns an error log TypeError: isinstance() arg 2 must be a type or tuple of types. Here by "type" it means "Data Type". >>> isinstance(username, 'str') Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: isinstance() arg 2 must be a type or tuple of types Immutability of Strings and Tuples % TypeError: 'tuple' object does not support item assignment % TypeError: 'str' object does not support item assignment

Working with "conda" (with Anaconda)

Launch 'Anaconda Prompt'. (base) C:\Users\Ashish Jain>conda create -n py39 python=3.9 Collecting package metadata (repodata.json): done Solving environment: done ==> WARNING: A newer version of conda exists. <== current version: 4.8.5 latest version: 4.10.1 Please update conda by running $ conda update -n base -c defaults conda ## Package Plan ## environment location: E:\programfiles\Anaconda3\envs\py39 added / updated specs: - python=3.9 The following packages will be downloaded: package | build ---------------------------|----------------- ca-certificates-2021.4.13 | haa95532_1 150 KB certifi-2020.12.5 | py39haa95532_0 144 KB openssl-1.1.1k | h2bbff1b_0 5.7 MB pip-21.0.1 | py39haa95532_0 2.0 MB python-3.9.4 | h6244533_0 19.8 MB setuptools-52.0.0 | py39haa95532_0 930 KB sqlite-3.35.4 | h2bbff1b_0 1.2 MB tzdata-2020f | h52ac0ba_0 123 KB vc-14.2 | h21ff451_1 8 KB vs2015_runtime-14.27.29016 | h5e58377_2 2.2 MB wheel-0.36.2 | pyhd3eb1b0_0 31 KB wincertstore-0.2 | py39h2bbff1b_0 15 KB ------------------------------------------------------------ Total: 32.3 MB The following NEW packages will be INSTALLED: ca-certificates pkgs/main/win-64::ca-certificates-2021.4.13-haa95532_1 ... tzdata pkgs/main/noarch::tzdata-2020f-h52ac0ba_0 ... wheel pkgs/main/noarch::wheel-0.36.2-pyhd3eb1b0_0 wincertstore pkgs/main/win-64::wincertstore-0.2-py39h2bbff1b_0 Proceed ([y]/n)? y Downloading and Extracting Packages... Preparing transaction: done Verifying transaction: done Executing transaction: done # # To activate this environment, use # $ conda activate py39 # To deactivate an active environment, use # $ conda deactivate Note: conda create -n py39 -c conda-forge python=3.9 (base) C:\Users\Ashish Jain>python Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information. >>> exit() Note here: We were in "base" environment with Python 3.7.1 but we were still able to create an environment with higher version (Python 3.9.4). (base) C:\Users\Ashish Jain>conda activate py39 (py39) C:\Users\Ashish Jain>python Python 3.9.4 (default, Apr 9 2021, 11:43:21) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information. >>> exit() (py39) C:\Users\Ashish Jain> The concatenation of two "dict" using "pipe" (|) character: (py39) C:\Users\Ashish Jain>python Python 3.9.4 (default, Apr 9 2021, 11:43:21) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information. >>> >>> {'a': 'b'} | {'c': 'd'} {'a': 'b', 'c': 'd'} >>>

Putting all of the above in a '.py file' or a 'Python script'.

print(7 + 3, end='\n\n') print(7 / 3, end='\n\n') print(7 // 3, end='\n\n') print(7 % 3, end='\n\n') username = "Ashish" print(username, end='\n\n') print(F"Logged in as: {username}") Output: (base) C:\Users\Ashish Jain\OneDrive\Desktop>python script.py 10 2.3333333333333335 2 1 Ashish Logged in as: Ashish (base) C:\Users\Ashish Jain\OneDrive\Desktop>

Putting all of the above in a 'Jupyter Notebook'.

The way to start Jupyter Notebook is through the command: "jupyter notebook" (base) C:\Users\Ashish Jain\OneDrive\Desktop>jupyter notebook [I 2021-05-16 17:00:42.136 LabApp] JupyterLab extension loaded from E:\programfiles\Anaconda3\lib\site-packages\jupyterlab [I 2021-05-16 17:00:42.136 LabApp] JupyterLab application directory is E:\programfiles\Anaconda3\share\jupyter\lab [I 17:00:42.172 NotebookApp] Serving notebooks from local directory: C:\Users\Ashish Jain\OneDrive\Desktop [I 17:00:42.172 NotebookApp] Jupyter Notebook 6.3.0 is running at: [I 17:00:42.173 NotebookApp] http://localhost:8888/?token=b9833146c3b56e7dc6632be0e513c541a436d84ff42b1511 [I 17:00:42.173 NotebookApp] or http://127.0.0.1:8888/?token=b9833146c3b56e7dc6632be0e513c541a436d84ff42b1511 [I 17:00:42.174 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [C 17:00:42.370 NotebookApp] To access the notebook, open this file in a browser: file:///C:/Users/Ashish%20Jain/AppData/Roaming/jupyter/runtime/nbserver-764-open.html Or copy and paste one of these URLs: http://localhost:8888/?token=b9833146c3b56e7dc6632be0e513c541a436d84ff42b1511 or http://127.0.0.1:8888/?token=b9833146c3b56e7dc6632be0e513c541a436d84ff42b1511 This opens up a window in your browser:
In the image above, you can see the dropdown named "New". Click on this dropdown and select something like "Python 3" (the option coming for me). The items in this dropdown are your kernels that is an advanced concept for this post.
Link to the session recording: YouTube Tags: Technology,Python,Anaconda,Windows CMD,

Monday, February 22, 2021

Creating new text file from terminal on Windows and Ubuntu



Creating new text file on Ubuntu from terminal

The Linux tee command is a way to write the standard output to a file. Or, to quote from the man page documentation, tee - read from standard input and write to standard output and files This is a little different from redirecting output to a file. In this case, the output is still send to standard out, but an additional copy is sent to create your text file. There are some good examples of how this can be useful, shown in the info documentation for tee. To view the info page, open a terminal window and enter info coreutils 'tee invocation' To understand the basic usage of the tee command, go to a terminal window and navigate to a directory that contains a small number of files. You can then use the ls and tee commands to create a text file that contains a listing of the files in that directory. ls | tee listing.txt You can also append a file using the -a switch. This will insert the output lines at the bottom of a pre-existing file. ls | tee -a listing.txt An example of when tee comes in handy is when you want to create a simple text file as root from your user account. I used it to create the fully qualified domain name file for my Apache configuration. You would think you could use: sudo echo "ServerName localhost" > /etc/apache2/conf.d/fqdn But that doesn't work because the sudo only affects the echo command and not the output redirection. Instead, you can use tee like this. echo "ServerName localhost" | sudo tee /etc/apache2/conf.d/fqdn That command succeeds in creating the fqdn file with the desired content. Some other commands to create text files on Ubuntu: Following line creates an "HTML" page. $ echo " " >> mypage.html Following command creates a 0 size text file: $ touch mypage.html

Creating new text file on Windows from CMD

1. type NUL > EmptyFile.txt 2. echo. 2>EmptyFile.txt This command creates an empty file as there is no error produced here that would go into the file. The command "echo." outputs an empty line in the CMD. 3. copy nul file.txt > nul 4. REM. > empty.file 5. fsutil file createnew file.cmd 0 # to create a file on a mapped drive 6. aaaa > empty_file This will output something like: 'aaaa' is not recognized as an internal or external command, operable program or batch file. But it does create an empty file. In the same spirit and the shortest one is: 7. .>out.txt It does give an error: '.' is not recognized as an internal or external command But this error is on stderr. And > only redirects stdout, where nothing have been produced. Hence the creation of an empty file. The error message can be disregarded here. Or redirected to NUL: 8. .>out.txt 2>NUL 9. echo.>filename (echo "" would actually put "" in the file! And echo without the '.' would put "Command ECHO activated" in the file...) Note: the resulting file is not empty but includes a return line sequence: 2 bytes. 10. Batch solution for a real empty file: <nul (set/p z=) >filename dir filename 11/09/2009 19:45 0 filename 1 file(s) 0 bytes The "<nul" pipes a nul response to the set/p command, which will cause the variable used to remain unchanged. As usual with set/p, the string to the right of the equal sign is displayed as a prompt with no CRLF. Since here the "string to the right of the equal sign" is empty... the result is an empty file. The difference with cd. > filename (does produce a 0-byte-length file) is that this "bit of redirection" (the <nul... trick) can be used to echo lines without any CR: <nul (set/p z=hello) >out.txt <nul (set/p z= world!) >>out.txt dir out.txt The dir command should indicate the file size as 11 bytes: "helloworld!".
% http://tuxtweaks.com/2010/06/command-line-basics-create-text-files-with-tee/ % https://stackoverflow.com/questions/1702762/how-to-create-an-empty-file-at-the-command-line-in-windows Tags: Linux, Windows CMD, Technology

Thursday, September 3, 2020

Working with base 64 encoding using Windows CMD



We have a zip file "input1.zip" that we will turn into "output1.txt" using base-64 encoding:

C:\Users\Ashish\Desktop\e5>certutil -encode input1.zip output1.txt 

Input Length = 202
Output Length = 338
CertUtil: -encode command completed successfully. 

Notes about "output1.txt":
1. This is the output file from 'certutil'. 
2. This has character encoding base64.
3. The file encoding is utf-8. 
4. Maximum length of a line is 64.
5. Base64 encoding usually has last few characters as "=". "=" represents padding.
6. The first line in encoded file is: -----BEGIN CERTIFICATE-----
7. Last line in encoded file is: -----END CERTIFICATE-----


C:\Users\Ashish\Desktop\e5>certutil -decode output1.txt input2.zip
Input Length = 338
Output Length = 202
CertUtil: -decode command completed successfully.

Contents of "output1.txt" with header and footer:

-----BEGIN CERTIFICATE-----
UEsDBBQAAAAAAEy8IVE3rlRbAgAAAAIAAAAGAAAAdDEudHh0dDFQSwMEFAAAAAAA
TrwhUY3/XcICAAAAAgAAAAYAAAB0Mi50eHR0MlBLAQIUABQAAAAAAEy8IVE3rlRb
AgAAAAIAAAAGAAAAAAAAAAEAIAAAAAAAAAB0MS50eHRQSwECFAAUAAAAAABOvCFR
jf9dwgIAAAACAAAABgAAAAAAAAABACAAAAAmAAAAdDIudHh0UEsFBgAAAAACAAIA
aAAAAEwAAAAAAA==
-----END CERTIFICATE-----

Contents of "output1.txt" without header and footer:

C:\Users\Ashish\Desktop\e5>type output1.txt | find /V "-----BEGIN CERTIFICATE-----" | find /V "-----END CERTIFICATE-----"

UEsDBBQAAAAAAEy8IVE3rlRbAgAAAAIAAAAGAAAAdDEudHh0dDFQSwMEFAAAAAAA
TrwhUY3/XcICAAAAAgAAAAYAAAB0Mi50eHR0MlBLAQIUABQAAAAAAEy8IVE3rlRb
AgAAAAIAAAAGAAAAAAAAAAEAIAAAAAAAAAB0MS50eHRQSwECFAAUAAAAAABOvCFR
jf9dwgIAAAACAAAABgAAAAAAAAABACAAAAAmAAAAdDIudHh0UEsFBgAAAAACAAIA
aAAAAEwAAAAAAA==

Encoding input file without header and footer:

C:\Users\Ashish\Desktop\e5>certutil -encodehex -f input1.zip output2.txt 0x40000001

Input Length = 202
Output Length = 272
CertUtil: -encodehex command completed successfully.

Contents of output2.txt:

UEsDBBQAAAAAAEy8IVE3rlRbAgAAAAIAAAAGAAAAdDEudHh0dDFQSwMEFAAAAAAATrwhUY3/XcICAAAAAgAAAAYAAAB0Mi50eHR0MlBLAQIUABQAAAAAAEy8IVE3rlRbAgAAAAIAAAAGAAAAAAAAAAEAIAAAAAAAAAB0MS50eHRQSwECFAAUAAAAAABOvCFRjf9dwgIAAAACAAAABgAAAAAAAAABACAAAAAmAAAAdDIudHh0UEsFBgAAAAACAAIAaAAAAEwAAAAAAA==

The limitation of size of input file while encoding using certutil:

Interesting stats about encoding found in webpages:

Tuesday, August 25, 2020

Working with 'dir' command on Windows CMD prompt


# Finding a file/folder with a string in its name.

Note: /s Lists every occurrence of the specified file name within the specified directory and all subdirectories. Exploring "dir" documentation C:\Users\Ashish Jain>help dir Displays a list of files and subdirectories in a directory. DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N] [/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4] [drive:][path][filename] Specifies drive, directory, and/or files to list. /A Displays files with specified attributes. attributes D Directories R Read-only files H Hidden files A Files ready for archiving S System files I Not content indexed files L Reparse Points - Prefix meaning not /B Uses bare format (no heading information or summary). /C Display the thousand separator in file sizes. This is the default. Use /-C to disable display of separator. /D Same as wide but files are list sorted by column. /L Uses lowercase. /N New long list format where filenames are on the far right. /O List by files in sorted order. sortorder N By name (alphabetic) S By size (smallest first) E By extension (alphabetic) D By date/time (oldest first) G Group directories first - Prefix to reverse order /P Pauses after each screenful of information. /Q Display the owner of the file. /R Display alternate data streams of the file. /S Displays files in specified directory and all subdirectories. /T Controls which time field displayed or used for sorting timefield C Creation A Last Access W Last Written /W Uses wide list format. /X This displays the short names generated for non-8dot3 file names. The format is that of /N with the short name inserted before the long name. If no short name is present, blanks are displayed in its place. /4 Displays four-digit years Switches may be preset in the DIRCMD environment variable. Override preset switches by prefixing any switch with - (hyphen)--for example, /-W. --- --- --- --- --- # You can include files in the current or named directory plus all of its accessible subdirectories by using the /S option. This example displays all of the .WKS and .WK1 files in the D:\DATA directory and each of its subdirectories: dir /s d:\data\*.wks;*.wk1 --- --- --- --- --- # Look for text files in D: drive containing the letter 'ACC' in the case-insensitive manner. dir /s D:\*ACC*.txt OUTPUT: Directory of D:\Downloads\rw\jakarta-tomcat-8.0.35\logs 30-Dec-16 02:05 PM 61,549 localhost_access_log.2016-10-06.txt ... Directory of D:\Work Space\rw_new\temp\iTAP\licenses 27-Jan-16 07:46 PM 1,536 javacc-license.txt 1 File(s) 1,536 bytes --- --- --- --- --- We have following directory structure in a "test" folder: C:\Users\Ashish Jain\OneDrive\Desktop\test>tree /f Folder PATH listing for volume Windows Volume serial number is 8139-90C0 C:. │ 3.txt │ ├───1 │ └───a │ file.txt │ └───2 file_2.txt 1. List everything in this directory: C:\Users\Ashish Jain\OneDrive\Desktop\test>dir /s/b C:\Users\Ashish Jain\OneDrive\Desktop\test\1 C:\Users\Ashish Jain\OneDrive\Desktop\test\2 C:\Users\Ashish Jain\OneDrive\Desktop\test\3.txt C:\Users\Ashish Jain\OneDrive\Desktop\test\1\a C:\Users\Ashish Jain\OneDrive\Desktop\test\1\a\file.txt C:\Users\Ashish Jain\OneDrive\Desktop\test\2\file_2.txt 2. List subdirectories of this directory: C:\Users\Ashish Jain\OneDrive\Desktop\test>dir /s/b /A:D C:\Users\Ashish Jain\OneDrive\Desktop\test\1 C:\Users\Ashish Jain\OneDrive\Desktop\test\2 C:\Users\Ashish Jain\OneDrive\Desktop\test\1\a 3. List files in this directory and subdirectories: C:\Users\Ashish Jain\OneDrive\Desktop\test>dir /s/b /A:-D C:\Users\Ashish Jain\OneDrive\Desktop\test\3.txt C:\Users\Ashish Jain\OneDrive\Desktop\test\1\a\file.txt C:\Users\Ashish Jain\OneDrive\Desktop\test\2\file_2.txt Explanation for ‘dir /A:D’: D:\>dir /? Displays a list of files and subdirectories in a directory. DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N] [/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4] [drive:][path][filename] Specifies drive, directory, and/or files to list. /A Displays files with specified attributes. attributes D Directories R Read-only files H Hidden files A Files ready for archiving S System files I Not content indexed files L Reparse Points - Prefix meaning not Another way of listing only subdirectories: C:\Users\Ashish Jain\OneDrive\Desktop\test>dir /s | find "\" Directory of C:\Users\Ashish Jain\OneDrive\Desktop\test Directory of C:\Users\Ashish Jain\OneDrive\Desktop\test\1 Directory of C:\Users\Ashish Jain\OneDrive\Desktop\test\1\a Directory of C:\Users\Ashish Jain\OneDrive\Desktop\test\2