Article 4V743 List folder name and time in one line to create a variable in bash

List folder name and time in one line to create a variable in bash

by
bmxakias
from LinuxQuestions.org on (#4V743)
Hello

I have this code:

Code:Please select something to restore [1, 2, 3 e.t.c]:"
# get the folders count
count=$(ls -ltd $INCDIR/*/ | wc -l)

select incvalue in $(ls -ltd $INCDIR/*/ | awk -F/ '{print $(NF-1)}'); do
# if input is a number and is less than or equal to count
if (( $REPLY && $REPLY <= $count )) 2> /dev/null; then
break
else
echo "Your input ${REPLY} is not available. Please select a number from the list:"
fiThe result is:

Code:1) inc12 3) inc10 5) inc8 7) inc6 9) inc4 11) inc2
2) inc11 4) inc9 6) inc7 8) inc5 10) inc3 12) inc1That is fine as i am having the newest folder by time first but i can't add time on them like:

Code:1) 14:45 inc12 3) 14:45 inc10 5) 14:45 inc8 7) 14:45 inc6 9) 14:45 inc4 11) inc2
2) 14:45 inc11 4) 14:45 inc9 6) 14:45 inc7 8) 14:45 inc5 10) 14:45 inc3 12) 14:45 inc1I tried to use something like (notice that i remove the "d" from the parameters as it was the only way to get it work in ssh):

Code:ls -lt path/to/folders/ | awk '{print $8, $9}'and from ssh it works:

Code:00:35 inc12
00:35 inc11
00:35 inc10
00:35 inc9
00:34 inc8
00:34 inc7
00:34 inc6
00:34 inc5
00:34 inc4
00:34 inc3
00:33 inc2
00:31 inc1again the newest folder by time first but when i use it on script:

Code:select incvalue in $(ls -ltd $INCDIR/*/ | awk '{print $8, $9}'); doi am getting this:

Code: 1) 00:35
2) /backup/folder1/16-11-2019/folder2/inc/inc12/
3) 00:35
4) /backup/folder1/16-11-2019/folder2/inc/inc11/
5) 00:35
6) /backup/folder1/16-11-2019/folder2/inc/inc10/
7) 00:35
8) /backup/folder1/16-11-2019/folder2/inc/inc9/
9) 00:34
10) /backup/folder1/16-11-2019/folder2/inc/inc8/
11) 00:34
12) /backup/folder1/16-11-2019/folder2/inc/inc7/
13) 00:34
14) /backup/folder1/16-11-2019/folder2/inc/inc6/
15) 00:34
16) /backup/folder1/16-11-2019/folder2/inc/inc5/
17) 00:34
18) /backup/folder1/16-11-2019/folder2/inc/inc4/
19) 00:34
20) /backup/folder1/16-11-2019/folder2/inc/inc3/
21) 00:33
22) /backup/folder1/16-11-2019/folder2/inc/inc2/
23) 00:31
24) /backup/folder1/16-11-2019/folder2/inc/inc1/How should i adjust my code it to get it as:

Code:1) 00:35 inc12
2) 00:35 inc11
3) 00:35 inc10
4) 00:35 inc9
5) 00:34 inc8
6) 00:34 inc7
7) 00:34 inc6
8) 00:34 inc5
9) 00:34 inc4
10) 00:34 inc3
11) 00:33 inc2
12) 00:31 inc1and then to use $incvalue and get only the name like inc8 and not the date in the variable...

Thank you !latest?d=yIl2AUoC8zA latest?i=A_qGqY_VfK0:a03QzcYYgCQ:F7zBnMy latest?i=A_qGqY_VfK0:a03QzcYYgCQ:V_sGLiP latest?d=qj6IDK7rITs latest?i=A_qGqY_VfK0:a03QzcYYgCQ:gIN9vFwA_qGqY_VfK0
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments