- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script ..
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2010 06:17 AM
01-10-2010 06:17 AM
script ..
I am in need of a scripts which is for removing the files that get from the out put of ls -ltr . There are many files and we should not use for loop also. I am requesting this for our dba.
Can any one help me here...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2010 07:20 AM
01-10-2010 07:20 AM
Re: script ..
cd /dir
find . 'test' -exec rm {} \;
Regarding 'test': Need more information. If you read the man page on find you'll see many 'tests', based upon age, ownerships, etc.
Provide and I'll reciprocate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2010 07:40 AM
01-10-2010 07:40 AM
Re: script ..
Your use of the '-t' option with 'ls' suggests that you might want to remove files older than some date/time. Look at the manpages for 'find'. You might want to do something like:
# find /path_to_files -type f -mtime +30 -exec rm {} +
...which will remove files that are older than 30-days since their last modification.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2010 11:27 AM
01-10-2010 11:27 AM
Re: script ..
My necessity is something different,....I will give u a scenario as below..
#ls -ltr
a
b
c
d
e
f
g
.
.
.
.
etc...
and I would like to remove the first few files(say for example as 4 files a,b,c,d). I feel it is enough to get you. In this , no ownership or aging comes in.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2010 11:57 AM
01-10-2010 11:57 AM
Re: script ..
> and I would like to remove the first few files(say for example as 4 files a,b,c,d). I feel it is enough to get you. In this , no ownership or aging comes in.
OK, then you could do:
# cd /somepath && ls -t|head -4|xargs rm
This changes to the directory you want to be in and if successful removes the first four (4) files (most recently modified, first). If you want to remove the oldest files, do:
# cd /somepath && ls -rt|head -4|xargs rm
It is assumed that only files and no subdirectories are present.
Regards!
...JRF...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2010 06:45 PM
01-10-2010 06:45 PM
Re: script ..
You can use this:
--------------------
for I in `ls -lt | tail -4 | awk '{ print $9 }'`
do
rm -i $I
done
--------------------
rm -i <-- for interactive removal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2010 08:54 PM
01-10-2010 08:54 PM
Re: script ..
I am not supposed to use for loop here..
@ James,
I will try the same and come back to u.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2010 10:21 PM
01-10-2010 10:21 PM
Re: script ..
Why not? Too easy?
> #ls -ltr
> [...] In this , no ownership or aging comes
> in.
What do you mean, "no [...] aging comes in"?
What do you think that "ls -ltr" does, if not
list files according to their ages? At least
one of us is confused about what you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2010 10:26 PM
01-10-2010 10:26 PM
Re: script ..
I told about the ages because of the upper thread was saying about it..please go thru that.
Next, why I am not using for loop is because ,my DBA does not allowing me to include the same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2010 12:11 AM
01-11-2010 12:11 AM
Re: script ..
hmmm I can think of a good reason not to use for loops in this manner, but "my DBA told me not to" isn't it! (Although your DBA may be thinking of the same reason that I am)
Do you not have any curiosity? Don't you want to know _why_ you shouldn't use a for loop? Curiosity is the key to learning!
HTH
Duncan
I am an HPE Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2010 03:35 AM
01-11-2010 03:35 AM
Re: script ..
>Duncan: I can think of a good reason not to use for loops in this manner
Because 4 is too small to bother? :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2010 04:51 AM
01-11-2010 04:51 AM
Re: script ..
no actually because what if the filenames are _really_ long (or we have a lot more than 4 files - not valid for this example but a generic reason to avoid for loops) - we can run into the problem of exceeding the max line length or argument count for the shell.
instead of:
for x in
do
...
done
I would always do:
cat
- | while read x
do
...
done
(syntactically incorrect, but you get the gist)
that lesson learnt after debugging a script which deleted archive logs in a directory - it stopped working when there we more than 255 logs present...
Duncan
I am an HPE Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2010 08:50 PM
01-11-2010 08:50 PM
Re: script ..
In both cases, you can't use a for-loop nor my $(). Typically 4 * N will always be less than 2 Mb.
>I would always do: while read x
>(syntactically incorrect
You mean evil cat incorrect. :-)
Yes, while read or xargs.
- Tags:
- evil cat