Background:
I have been making small notes about my learnings daily, typically any new thing I learnt. I make a small note about it.
I want to name this note with dates and time(This is for easy find, recollection etc) but I need to also get the date in this format 20210510002211
-- Now, the terminal will readily spew out this date formate with this command
date +%Y%m%d%H%M%S * - try it.*
-- Now I can't keep that in the terminal, hence why i need to make it into a script. give it a fancy name and run quick
What do you need:
-A text editor(I use nano here)
- Create a file
#!/bin/bash
# A script that spews out current long date and time
date +%Y%m%d%H%M%S
- save the file giving it a fancy name (datum)
- Setting Permission
chmod 755 datum //datum is the fancy name I'm calling the script
--- The script can run now, try./datum
`
- Putting it in my own path
Run
echo PATH
-- It should reveal a the current excutable path on the system
-- It is good practice to have a special folder for your scripts /bin, create that folder on your home directory.
Now you will have a this pathe ./bin/datumWe need to add the new path to PATH definition on the .zshsrc file
do
nano ~/.zshsrc
- You will be able to edit that file now, add the path to the script to the PATH line
save and exit
Now, we need to refresh the zsh files
do
source .zshsrc
Now, just typing datum in the terminal should spit out that long date and time
Top comments (0)