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.
Ok I now am learning shell scripting. I feel a little held back with how the text is teaching me, and my instructor is basically going from the same book. does anyone have any useful links I can use to get more comfy with shell scripting? if it matters it is/will be in bash.
oh geesh all of those links are terribly overwhelming to me. right now i'm looking for simple stuff. for example i'm working on taking user input ,and the input is filenames. i use a command (find or grep) to find the file and if it exists then show the last mod time of the file. when i use grep nothing happens, if i use find i get a hit, so i'm sort of stuck there. i think i'm not using the right options or something? i accept the input fine because right now i echo the input so i know i'm doing that right.
this seems to list the path and file, but i'm confused at getting all the info (the last modified time is what i'm after). reading the chapters seem so easy but getting the script to work is entirely different
i tried the if then fi statement but that didnt seem to work. at first i had this:
#accept filename as argument, and show last modification time of file
#if it exists, or show message if it doesnt exist.
echo "enter filename: "
read file1
if grep "$1"; then
echo "file found" #here will list mod time
else
echo "that file does not exist"
fi
echo "Last modification time is " #just filler, will get here
ok i find reference to find a file that was done x days ago, can i just show when the last time when it was modified or accessed instead of x days? Skyline, that loop didnt work for me
I did however just figure out what was wrong with my loop. apparently the book is a misprint as it wasnt listing the syntax correctly
# Ask for name, test if var is empty, exit if, else search. The "iname" is case insensitive, the printf prints out the M-time local to you with the full filename behind it. I made it print quotes so it's easy to spot misplaced spaces and if you feed it to something else it won't break on spaces. Null termination (-fprint0 or -print0) do the same:
echo "Enter filename: (will search in "$HOME")"; read file
test -z file && exit 1 || find "$HOME" -type f -iname "${file}" -printf "%t \"%p\"\n"
ok now i'm going crazy, i entered the test line in a file and did it and it worked, i insert in in my script and it DOEST wrk and i entered it exact. WHY?!!?!?!?!?!?!?!?
NM. guess it required verbal foul language to make it work
Distribution: Fedors Core 3, Red Hat 9, Mandrake 8.1
Posts: 52
Rep:
Are you trying to allow the user to enter the file name at the prompt?
If so I think you need to remove the newline from the end of echo with the -n option.
echo -n "Enter filename: (will search in "$HOME")"
read file
test -z file && exit 1 || find "$HOME" -type f -iname "${file}" -printf "%t \"%p\"\n"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.