Red HatThis forum is for the discussion of Red Hat Linux.
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.
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?
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)
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
*) 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.
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.
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]#
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'?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.