LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-16-2011, 11:58 AM   #1
Newbie - linux
LQ Newbie
 
Registered: Aug 2011
Posts: 5

Rep: Reputation: Disabled
Shell Command Newbie


I have a problem to solve, and I'm stuck. I must write a Shell Command Script; I have did a little while in college, but I do not remember all to get me over the bumps that I'm facing... Or problems to the few lines that I have did with the script.

Here is the assignment:

Write a shell command that can find all files within the /www/sites/ directory tree that were modified more than 10 days ago, excluding any files with .jpg, .gif, .mov, and .avi extensions. Make the output list the path and size of said file(s).

So far... I have

#! /bin/bash # Not sure if it should be "bash" or "sh" at this point?

find /www/sites/ .-typr f -mtime +10 /xargs tar -cvf 'date' +%d%m%Y' _archive.tar' #I'm thinking that the "_archive.tar'" may not be right for assignment

#stuck here

$ tar --exclude= '.jpg' --exclude= '.gif' --exclude= '.mov' --exclude= '.avi'

#not sure for the rest and how to put it together right now! I do think that I need a echo command to output the information for the sites, path, size. Please help me to understand what I missing by refreshing.

Thank you, Thesnow. I'm still having trouble putting it together. Can you help line by line? I know #! /bin/bash is correct. The second line should be the assignment of a value or variable if that is remember correction. Example FILENAME= "/www/sites/". But, I not sure with search on how to use the for loop with find. I believe a nested construction, but the set up is kill me. Would some give a sample script for the above assignment, I just need to see something that I can follow and read to understand the set up.

Thanks,

- linux

Last edited by Newbie - linux; 08-16-2011 at 04:44 PM. Reason: Need more help because it has been a long time, and I'm not in college to get through.
 
Old 08-16-2011, 12:45 PM   #2
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 170

Rep: Reputation: 56
If I understand what you're asking, you want a list like

/www/sites/file1 1234
/www/sites/file2 5678
/www/sites/file3 9012
...

If that's the case, you can do it in one line using a for loop with find (similar to what you have) and egrep (to filter the file extensions) then echo the result (to output the file name) along with the file size using stat. There are certainly other ways to do it too.

Since you said it's an assignment, I will stop short of providing the solution.
 
1 members found this post helpful.
Old 08-16-2011, 01:15 PM   #3
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,093

Rep: Reputation: 197Reputation: 197
I always use /bin/bash as the shell in shell scripts.

I can't imagine why tar would be a something to use in the solution.

I advise that you play with the find command a bit until you get something that outputs a list of the files in the relevant directory. Then look at removing the files you're not interested in and then as the other poster said, look at a for loop to iterate the list that's left. You'll find looking at pipes useful.

Code:
$ echo "monkey" | grep "monkey"
monkey
$ echo "monkey " | grep -v "monkey"
$
The vertical line is the pipe, it lets you send the output of one command in to another command.

When you post scripts/code it is a good idea to wrap it in CODE tags (look for the # button in the post editor). It makes your post a lot easier to read.

Last edited by arizonagroovejet; 08-16-2011 at 01:16 PM. Reason: s/you're interested in/in the relevant directory/
 
1 members found this post helpful.
Old 08-16-2011, 09:30 PM   #4
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Debian, Mageia, and whatever VMs I happen to be playing with
Posts: 12,023
Blog Entries: 13

Rep: Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028
This is a great manual:

http://www.tldp.org/LDP/Bash-Beginne...ners-Guide.pdf

It's available in other formats too; it's the third one down from the top.

http://www.tldp.org/guides.html
 
2 members found this post helpful.
Old 08-16-2011, 10:57 PM   #5
Newbie - linux
LQ Newbie
 
Registered: Aug 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Very helpful Frankbell, reading through it now. Thanks for the direction.

Newbie - linux
 
Old 08-17-2011, 12:51 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,483

Rep: Reputation: 2864Reputation: 2864Reputation: 2864Reputation: 2864Reputation: 2864Reputation: 2864Reputation: 2864Reputation: 2864Reputation: 2864Reputation: 2864Reputation: 2864
As and addon to all that has been said, I would add that find can actually do all that you require on its own.
 
0 members found this post helpful.
Old 08-17-2011, 07:04 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,347

Rep: Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365
For bash manuals see also
http://rute.2038bug.com/index.html.gz - a good tutorial on Linux at the cli level
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html - html version of pdf in post #4
http://www.tldp.org/LDP/abs/html/

Incidentally, please add new posts; if you edit your orig one its very confusing

This
Code:
#! /bin/bash
should be
Code:
#!/bin/bash
ie no spaces in that cmd ...
This is also true for variable assignments, no spaces around the '=' operator

Last edited by chrism01; 08-17-2011 at 07:06 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How can I run a command on another shell without changing the current shell? quanba Other *NIX 3 04-05-2010 12:19 PM
How to run root privileged Linux command as normal user via shell shell tcegrid Linux - Newbie 1 06-23-2008 03:38 PM


All times are GMT -5. The time now is 12:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration