Posts

Showing posts from December 10, 2018

The most recent files in directory with a specific format in each one

Image
up vote -1 down vote favorite I would like to have in a variable the most recent file with a specific format. exemple : in /home/test, 5 files : file_test_hadoop_20181130.csv (This is the last modified one for hadoop file) file_test_hadoop_20181130.txt file_test_hadoop_20181130.ini file_test_hub_20181130.txt (This is the last modified one for txt file) file_test_hub_20181130.csv file_test_hub_20181130.ini So the result that i want is the last modified one in each type : HADOOP_NAME= file_test_hadoop_20181130.csv HUB_NAME= file_test_hub_20181130.txt So i started to do something like this : HADOOP_NAM E=$(ls -tr /home/test | tail -n 1 | find /home/test -maxdepth 1 -name "file_test_hadoop*" -printf '%fn') HUB_NAME =$(ls -tr /home/test | tail -n 1 | find /home/test -maxdepth 1 -name "file_