Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need a script that will tell me the day of the week for a file's modified date.
I have 2 lines of code, one that will tell me the day of the week for a specified date. The other will give me the file's last date modified.
See below:
date +%A --date='Jul 9'
and
ls -lart file.txt | cut -d" " -f6,7,8
What I need is the 2nd statements output to go into the --date= param of the first statement.
I found that you are supposed to use the `` marks to encapsulate a command to use its results as a parameter but when I do so I get errors. The errors seem to be coming from the " " (the deliminator for CUT).
−−time−style=STYLE
with −l, show times using style STYLE: full−iso, long−iso, iso, locale, +FORMAT. FORMAT is
interpreted like ‘date’; if FORMAT is FORMAT1<newline>FORMAT2, FORMAT1 applies to
non−recent files and FORMAT2 to recent files; if STYLE is prefixed with ‘posix−’, STYLE takes
effect only outside the POSIX locale
[EDIT:]
Have you an alias for ls that is giving you this behaviour?
Code:
tred@vaio:~$ alias
alias ls='ls --color=auto'
tred@vaio:~$
When I run those commands (the last two any way), I get:
date: invalid date `Jul'
When I modify the -f param of cut to be -f6,7,8 I get:
date: extra operand `8'
My ls -lart return the date as:
Jul 8 23:56
not like yours (2009-07-09 18:10)
Thanks.
The format in which ls displays dates is largely tied to
the locale you're using. You can get "sensible" date formats
by forcing them:
ls -l --time-style=long-iso
will yield the date display in Tredegars example (and basically
will on all machines I ever had my hands on - the concept of having
Month and Day for dates less than six months away and a different format
including the year for older ones is just mentally crippled and sick).
Awesome! I got it sorted out using both of your tips. Sure enough I did have an alias for "LS". For anyone else with this issue, the command I ended up with is:
There's probably a way to get the "-r" option of "date" to do expansion but I couldn't get it to work.
How about something like this:
Code:
#!/bin/bash
FILES=$(\ls ingram*)
for filename in $FILES
do
if [ "$(date +%A -r $filename)" = "Wednesday" ]; then
echo "HURAH"
else
echo "NO GOOD"
fi
done
Last edited by norobro; 07-09-2009 at 06:43 PM.
Reason: Got rid of back ticks
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.