LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 07-22-2004, 11:54 PM   #1
imsajjadali
Member
 
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102

Rep: Reputation: 15
Delete Files


1) I want to delete all files which have extention out from specific folder.
Which command I can use?
Following files which I want to delete in one command
456.out
987.out
876.out
----
-----

2) I want to delete the files older then specific date from a folder?



Thanks in Advance
Sajjad
 
Old 07-23-2004, 12:36 AM   #2
legolin
Member
 
Registered: Dec 2003
Location: munich
Distribution: Fedora Core 4
Posts: 141

Rep: Reputation: 15
hi,


to delete use the rm command...

for exmple :

rm -f *.out,


this will delete all the files with .out at the end without asking (-f option = force) if you have folders you whant to delete, use the -r option. ()recursive)

for more information use the manual (man rm)

i hope i could help you

leg
 
Old 07-23-2004, 12:44 AM   #3
imsajjadali
Member
 
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102

Original Poster
Rep: Reputation: 15
what about
2) I want to delete the files older then specific date from a folder?
 
Old 07-23-2004, 12:49 AM   #4
imsajjadali
Member
 
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102

Original Poster
Rep: Reputation: 15
when I use the said command
rm -f *.out,
the following error message dispaly

[oracle@visiondb1 PROD_proddb]$ rm -f *.out
bash: /bin/rm: Argument list too long
 
Old 07-23-2004, 01:05 AM   #5
troutwaxer
Member
 
Registered: Jan 2004
Location: Southern California
Distribution: Slackware
Posts: 32

Rep: Reputation: 15
To delete multiple files you need to use a wildcard, which is the * character. (Yes, it's your asterisk.) * means every possible string of numbers and letters, including spaces.

Examples:

Delete all files in a directory:

rm *

Be very, very careful with this. If I want to delete everything in the /usr/bin/foo directory, I type:

rm /usr/bin/foo/*

Thus specifiying the directory. (It's unnecessary and paranoid, but I do it anyway, because I might one day want to type "rm -RF," which removes all files and all subdirectories, and I want to keep the good, safe habit.)


To delete all files starting with the word "star" type:

rm star*

This will remove starfish, star.doc, star.conf.bak, star.html, etc.


To delete all files that end in out, type

rm *.out.

Keep the period. Make sure you don't type

rm *out

because that will also remove shout, pout, standout, etc.

Also, type

man rm

so you can learn about the "rm" command.

You can also use the * with commands such as cp, ls, etc.

I can't help you with removing things after a certain date. You'll have to write a script and I don't have time to fiddle with that tonight.

To do it manually, you'll need to type

ls -algFs

which will give you a listing of all files with dates. You can probably do something like

ls -algFs | grep 2003

or

ls -algFs | grep "Jan 7"

and get a list of old files.

Alex
 
Old 07-23-2004, 01:06 AM   #6
legolin
Member
 
Registered: Dec 2003
Location: munich
Distribution: Fedora Core 4
Posts: 141

Rep: Reputation: 15
argument too long???

*) uh, this is new for me... maybe in your system there are another options for rm... i'm using FC2. try without the -f option, of loock in the manual for the "force" option.


*) you whant do delete files olther than "Date", for that i don't know a program.
but what you can do is to sort the files by date
ls -lt, or ls -c1t (to have only the files name)

you could use something like this to make a textfile with the output of ls:

ls -c1 -t > sort-list

now do a ls -lt and compare and delete the lines of "sort-list", where newer files are.

run: rm `cat sort-list`

bye

leg
 
Old 07-23-2004, 01:14 AM   #7
imsajjadali
Member
 
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102

Original Poster
Rep: Reputation: 15
Hi Alex
I have used the command rm *.out. but the following error display

[oracle@visiondb1 PROD_proddb]$ rm *.out.
rm: cannot remove `*.out.': No such file or directory

can you please tell me the exact command to remove files with extion out.

thanks
 
Old 07-23-2004, 01:18 AM   #8
troutwaxer
Member
 
Registered: Jan 2004
Location: Southern California
Distribution: Slackware
Posts: 32

Rep: Reputation: 15
Take out the period. You typed:

rm *.out.

Instead, type:

rm *.out


Alex
 
Old 07-23-2004, 01:23 AM   #9
imsajjadali
Member
 
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102

Original Poster
Rep: Reputation: 15
hi Alex
when I type said command
rm *.out
the following error message dispaly

[oracle@visiondb1 PROD_proddb]$ rm *.out
bash: /bin/rm: Argument list too long
[oracle@visiondb1 PROD_proddb]$

thanks
 
Old 07-23-2004, 01:26 AM   #10
legolin
Member
 
Registered: Dec 2003
Location: munich
Distribution: Fedora Core 4
Posts: 141

Rep: Reputation: 15
try this:

for i in *.out ; do rm $i ; done
 
Old 07-23-2004, 01:30 AM   #11
imsajjadali
Member
 
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102

Original Poster
Rep: Reputation: 15
I don't understand, please type the exact command
 
Old 07-23-2004, 01:48 AM   #12
troutwaxer
Member
 
Registered: Jan 2004
Location: Southern California
Distribution: Slackware
Posts: 32

Rep: Reputation: 15
I just made some files with .out extensions and tried to remove them. The command

rm *.out

worked perfectly. This makes me think that someone aliased the rm command to something silly. Try typing

alias

at the command prompt. This will show you a list of aliased commands. You may discover that "rm" has been connected to an incorrect command. Commands such as "rm" or "cp" that can affect files in a dangerous manner are usually aliased with the "-i" extension, so if you see output like this:

alias rm="rm -i"

then you're ok. If "rm" is not on the list you need to look elsewhere for the problem. On the other hand, if you see something that looks like this:

alias rm="rm -i -t -N"

then rm has been aliased improperly. In this case you should type:

alias rm="rm -i"

which will give you a sane "rm" command. Then try:

rm *.out

The other possibility is that you're working on a drive which someone else has mounted and on which you don't have proper permissions. This can cause some commands to behave erratically. In fact, I just got an identical error message (Argument list too long) trying to eject a CDROM drive as "alex" which I had mounted as "root."

You may have to su to root, or contact your sysadmin.

Alex
 
Old 07-23-2004, 02:17 AM   #13
legolin
Member
 
Registered: Dec 2003
Location: munich
Distribution: Fedora Core 4
Posts: 141

Rep: Reputation: 15
the command is:
for i in *.out ; do rm $i ; done

type it on a xterm or konsole (and in the right location, where your files are placed)
 
Old 07-23-2004, 02:28 AM   #14
imsajjadali
Member
 
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102

Original Poster
Rep: Reputation: 15
Hi Alex
Thanks for your quick support
I am log in with user root and try the alias and rm command. alias command shows the right result which u have mentioned but the rm command display same error message. the result of two commands are as

[root@visiondb1 PROD_proddb]# alias
alias cp='cp -i'
alias l.='ls -d .[a-zA-Z]* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-do
lde'
[root@visiondb1 PROD_proddb]# rm *.out
bash: /bin/rm: Argument list too long
[root@visiondb1 PROD_proddb]#

thanks
 
Old 07-23-2004, 02:33 AM   #15
imsajjadali
Member
 
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102

Original Poster
Rep: Reputation: 15
hi
the command is:
for i in *.out ; do rm $i ; done
this command run sccussfully, but it prompt on every file before deletion. I want to delete all files with out extention without prompting.
[root@visiondb1 PROD_proddb]# for i in *.out ; do rm $i ; don
rm: remove `o165278.out'? y
rm: remove `o165291.out'? y
rm: remove `o165296.out'? y
rm: remove `o165301.out'?


thanks
 
  


Reply



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
How to delete files that won't delete? di11rod Linux - Security 7 10-19-2005 09:14 PM
delete files suguname Linux - Newbie 3 07-05-2005 08:49 AM
how do you delete files? otoomet Linux - General 6 11-12-2004 04:06 AM
How to delete the destination files while the source files deleted in cp -u ? myunicom Linux - General 4 09-26-2003 01:13 PM
Delete Files bsengland Linux - Newbie 1 11-04-2002 05:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 11:47 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
Open Source Consulting | Domain Registration