I have some folders and files inside a directory. I need to order only the folders by creation time.
How order all folders by creation time using shellscript?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You don’t need a shell script.
lswill order your files by creation time if you include the-ltcoptions.From
man ls:If you are only interested in directories and not regular files, you can filter the results by piping to
grepNote:
^dmeans show only lines that start with the letterdwhich in the case of the output ofls -lmeans a directories.update
From your answer, it looks like you’re only interested in the filename of the newest file. Try this:
Notes:
/^d/: filter lines starting with ‘d’print $NF: print the last column; exit: exit immediately after the first match