- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- deleting files
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
02-03-2010 10:40 PM
02-03-2010 10:40 PM
I want to delete the output of this command which is a very big list:
$ls -lrt|grep 'Jan 23'|grep gz
How to delete it ?
Thanks,
Shiv
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2010 11:20 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2010 11:21 PM
02-03-2010 11:21 PM
Re: deleting files
verify the targeted files
$ls -lrt |grep "Jan 23" |grep ".gz" |awk '{print $9}'|xargs -i -l echo {}
once verified
$ls -lrt |grep "Jan 23" |grep ".gz" |awk '{print $9}'|xargs -i -l rm {}
there are many alternate methods ..thought to modify the command you used for listing files
Johnson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2010 11:22 PM
02-03-2010 11:22 PM
Re: deleting files
$ls -lrt | grep 'Jan 23' | grep gz > /tmp/abc
for I in `cat /tmp/abc`
do
rm $I
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2010 11:23 PM
02-03-2010 11:23 PM
Re: deleting files
List before you delete.
=======================
find /folder_name -name "*.gz" -mtime +7 -exec ll {} \;
Remove files after confirmed
============================
find /folder_name -name "*.gz" -mtime +7 -exec rm {} \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2010 11:35 PM
02-03-2010 11:35 PM
Re: deleting files
for I in `cat /tmp/abc`
do
rm $I
done
It will remove all the zipped file of Jan 23 from the current folder.
Tech Mahindra
Data Canter Tubli Bahrain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2010 11:42 PM
02-03-2010 11:42 PM
Re: deleting files
R.K & Tarun>>
$ls -lrt | grep 'Jan 23' | grep gz > /tmp/abc
for I in `cat /tmp/abc`
do
rm $I
done
ls -lrt command output have 9 fields , in order to delete you need to extract the file name from ls -lrt out put
comand should be
ls -lrt | grep 'Jan 23' | grep gz |awk '{print $9}' >/tmp/abc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2010 12:43 AM
02-04-2010 12:43 AM
Re: deleting files
$ls | grep 'Jan 23' | grep gz > /tmp/abc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2010 01:09 AM
02-04-2010 01:09 AM
Re: deleting files
$ls | grep 'Jan 23' | grep gz > /tmp/abc
again ls wont display time stamp and grep with "Jan 23" wont have any effect on the out put
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2010 01:49 AM
02-04-2010 01:49 AM
Re: deleting files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2010 03:11 AM
02-04-2010 03:11 AM
Re: deleting files
If you can to this, it wasn't a big list. You could do:
rm $(ls -lrt | grep 'Jan 23' | grep gz | awk '{print $9}')
>johnsonpk: command should be ...
You forgot to mention that your xargs solution is faster than the for-loop. :-)
If you know you don't have spaces then this is faster:
... | xargs -n40 rm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2010 03:30 AM
02-04-2010 03:30 AM
Re: deleting files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2010 05:08 AM
02-04-2010 05:08 AM
Re: deleting files
Doing pipelines with 'grep' (multiple times) and 'awk' is a waste of process resources.
Variations like:
# ls -lrt|grep 'Jan 23'|grep gz|awk '{print $9}'
...to list file names modified "Jan 23" and (presumably) with the '.gz' extention is wasteful and may yield fuzzy matches.
First, 'awk' and 'grep' both do pattern matching, so why use both?
You could do:
# ls -lrt|awk '/Jan 23/ && /\.gz$/ {print $9}'
This lets 'awk' do all the work you want and insures that you only match files that end in '.gz'.
While probably a bit of overkill, you could insure that the date you are matching really belongs to the timestamp column and isn't part of a filename:
# ls -lt|awk '$6=="Jan" && $7==23 && $9~/\.gz$/ {print $9}'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2010 11:31 AM
02-09-2010 11:31 AM
Re: deleting files
?
$ls -lrt|awk '/Aug 10/ && /\.gz$/ {print $9}'
$ls -lrt|awk '/Aug 10/ && /\.gz$/ {print $9}'|xargs -i -l rm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2010 11:37 AM
02-09-2010 11:37 AM
Re: deleting files
Did you try changing "rm" to "rm -i" in that
command?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2010 11:47 AM
02-09-2010 11:47 AM
Re: deleting files
> In the below command is it possible to specify option so that it ask befor deletion (like we specify with rm -i somefiles)
Yes, one way is like this:
# ls -lrt|awk '/Aug 10/ && /\.gz$/ {print $9}'|xargs pp -l rm
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2010 11:49 AM
02-09-2010 11:49 AM
Re: deleting files
My apologies, there was a typo in my last post. The command should read:
# ls -lrt|awk '/Aug 10/ && /\.gz$/ {print $9}'|xargs -p -l rm
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2010 03:56 PM
02-09-2010 03:56 PM
Re: deleting files
Are you going to want to hit "y" before every removal? (very big list)
Is there some way to automate your decision?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2010 07:50 AM
02-10-2010 07:50 AM
Re: deleting files
To generalize your ability to match the date value in the output from 'ls', you might want to accommodate systems that space-fill and ones that zero-fill the day.
Instead of doing:
ls -l | awk '/Feb 1/ {print $9}'
...with TWO spaces after "Feb" to find files of "Feb 1" but:
# ls -l | awk '/Feb 01/ {print $9}'
...on some systems (like AIX)
...and in the first case, only putting ONE space so that actually "Feb 11" is matched instead, change the regular expression to this:
# ls -l | awk '/Feb[0 ]*1[ ]/ {print $9}'
This matches "Feb" followed by an *optional* zero or space character followed by a "1" and a space. Now change the "1" to "11" and you still differentiate both whether or not the "1" is zero filled or not.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2010 02:14 AM
02-11-2010 02:14 AM
Re: deleting files
Not just systems, various locales.
You can scan all your locales to find these evil ones.
for i in $(locale -a); do echo "Doing $i: =="; LANG=$i locale -k d_fmt; done