InsideDarkWeb.com

Open a folder based on the date

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.

Ask Ubuntu Asked by mrc88 on November 21, 2021

3 Answers

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!

Related Questions

I cant install old nvidia driver after kernel update

1  Asked on August 25, 2020 by mersadakbari

         

How to solve public key error when running Ansible playbook

0  Asked on August 25, 2020 by frank-din

   

I am trying to make a Windows Install USB, but there are issues

1  Asked on August 23, 2020 by infinitejayz

   

Use phone as microphone in Linux

6  Asked on August 22, 2020 by someanon

         

Can Ubuntu TRIM another (NTFS) partition?

4  Asked on August 21, 2020 by user259452

       

Skip Unneeded services in Ubuntu boot

1  Asked on August 20, 2020 by pasmon-79

   

Windows very very slow after system upgrade?

0  Asked on August 17, 2020 by asher

     

Instaling UBUNTU in XPS 11 2-in-1 Ultrabook

0  Asked on August 16, 2020 by adriano-alejandro-bustos-musta

   

Uninstall gcc-5.4.0 to run gcc-4.8 as default

3  Asked on August 9, 2020 by claudio-nahmad

   

Can’t boot from Ubuntu USB stick

4  Asked on August 7, 2020 by poorav

   

How to record the RAM usage during Python and C++ run time?

1  Asked on August 6, 2020 by generalcode

       

Frontend for TTS – Ubuntu 20.04

0  Asked on August 4, 2020 by nikol

 

Ask a Question

Get help from others!

© 2021 InsideDarkWeb.com. All rights reserved.