Command line (BASH) quick reference - perrigoh/learner_journal GitHub Wiki
Here a collection of command line scripts for quick reference.
Steps:
-
Change directory to the directory where the new folder is to be created:
$ cd Google\ Drive/Colab\ Notebooks/ NO OUTPUT
The prompt will change to from
[wmxpg] ~
to[wmxpg]~/Google Drive/Colab Notebooks
-
Create directory (folder):
$ mkdir -p -v project_template mkdir: created directory 'project_template'
Note: do not leave a space between the name, as it will create two folders instead of one.
info source
-v
or–verbose
: It displays a message for every directory created.
-p
: A flag which enables the command to create parent directories as necessary. If the directories exist, no error is specified. Meaning, if folder name is new, it will create the folder. If folder name exist in the directory, it will not create the folder and will not prompt any error message. -
Change directory to the newly created directory (folder):
$ cd !$ # or $ cd project_template NO OUTPUT
The prompt will change to from
[wmxpg] ~/Google Drive/Colab Notebooks
to[wmxpg] ~/Google Drive/Colab Notebooks/project_template
To create directory (folder) plus subdirectory (subfolder) and change directory to the subdirectory (subfolder) at the same time:
mkdir -p -v project_template/doc && cd $_
info source
$_
: exclude the last command, in this case is change directory to the doc folder
rm
stand for remove, -r
stand for recursively delete a directory (folder)and all it's contents, project_template
is the folder name:
$ rm -r project_template
NO OUTPUT
There are options for removing the directory (folder):
rm -i
will ask before deleting each file. Some people will have rm aliased to do this automatically (type "alias" to check). Consider usingrm -I
instead, which will only ask once and only if you are trying to delete three or more files.rm -r
will recursively delete a directory and all its contents (normally rm will not delete directories, while rmdir will only delete empty directories).rm -f
will forcibly delete files without asking; this is mostly useful if you have rm aliased to ``rm -i'' but want to delete lots of files without confirming each one.
Create an empty file filename.ext
:
$ echo > README.md
NO OUTPUT
Create an empty file filename.ext
and add multiple lines text separated by \n
for each line.
In this use case, .gitignore
does not have an extension.
info source
-e
evalute \n
as new line, text can be anytext
and foldername/
which is a file path:
$ echo -e 'reference/\nsite/' >> .gitignore
NO OUTPUT
$ cat requirements.txt
numpy==1.23.5
cat
command can be used to copy content of one file to another file cat from_file_name > to_file_name
. For more usage examples of cat
command, refer the info source
info source - In Linux or Unix:
$ time python decimal_cpf_tbill_cal.py --sum 400000 --t_bill_yield 3.9
T-Bill yield: 7800.00
CPF loss: 5833.32
Huat ah!!! You have made: $1966.68 based on T-bill yield 3.9% per annum.
The break even yield for T-Bill need to be: 2.91666% per annum.
real 0m1.231s
user 0m0.000s
sys 0m0.015s
info source
Real Time is the actual, real world, time that the step takes to run and will be the same as if you timed it with a stopwatch (not possible as you won't know the precise moment the step starts and stops).CPU Time is the amount of time the step utilises CPU resources. If the machine on which the step is running has only a single CPU then the total CPU time would always be less than the real time.
However, with multiple processor machines, the load is spread across multiple CPU's and the total CPU time (as reported on the log) may be longer than the real time, e.g. a data step may take 2.6 seconds of real time to execute but the load is spread across 4 CPUs, utilising 1 second of resource on each, so the CPU time will be 4 seconds, i.e. 1.4 seconds longer than the real time.
info source
The difference is whether the time is spent in user space or kernel space. User CPU time is time spent on the processor running your program's code (or code in libraries); system CPU time is the time spent running code in the operating system kernel on behalf of your program.
$ echo $PATH
/c/Users/wmxpg/bin.../c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/c/Program Files (x86)/HP/Common/HPDestPlgIn:/c/Program Files (x86)/HP/IdrsOCR_15.3.1129.0:/c/Program Files/dotnet:/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/DAL:/c/Program Files/Intel/Intel(R) Management Engine Components/DAL:/cmd:/c/Users/wmxpg.../WindowsApps:/c/Program Files (x86)/HP/Common/HPDestPlgIn:/c/Users/wmxpg.../Microsoft VS Code/bin:/c/Users/wmxpg...atom/bin:/c/Users/wmxpg.../WindowsApps:/c/Users/wmxpg...Pandoc:/usr/bin/vendor_perl:/usr/bin/core_perl:/c/Users/wmxpg/anaconda3:/c/Users/wmxpg/anaconda3/Scripts