TransWikia.com

Open a folder based on the date

Ask Ubuntu Asked by mrc88 on November 21, 2021

Using command line is it possible to open a dynamic folder based on today’s date?
Command line example:

cd /folderstatic/20200722/

where 20200722 is the dynamic command.

3 Answers

You quickest method I know of is the fzf search tool. Once installed you simply type: fzf ** <>TAB> and then enter the date (or part of) the file or folder name.

Answered by elmclose on November 21, 2021

In this case you can create a shell script or add an alias on your .bashrc

But I'll go with the simplest.

Approach using bash alias

Simply add these lines on your .bashrc or .bash_profile.

# Create year, month and date format (Y-m-d)
# Ex. 20200722
folder_date=$(date +"%Y%m%d")

# Define a dynamic alias using the variable $folder_date
alias $folder_date="cd folder/static/$folder_date"

Then you can simply execute the command using the date today on your terminal.

Example:

$ 20200722

The command will navigate to the directory folder/static/20200722

Answered by chaelgutierrez on November 21, 2021

You can try a combination of date, sed with cd using command substitution.

cd "/folderstatic/$(date +%F | sed s/-//g)"

date +%F would print date in YYYY-MM-DD format which will be passed to sed and there -(hyphens) would be replaced with empty string. The resultant date +%F | sed s/-//g would like

20200722

Answered by yfluK on November 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP