How to write a script to delete files?
Hello,
Before uploading a my site I have to search for all backup files (ie:index.html~) and also the .dolphinview files and delete them from the local web server and of course it is a multilevel directory structure. Is it possible to create a simple script that would do this job for me? Thank you... |
This should be enough ("-r" stands for recursive):
Code:
rm -r *~ *.dolphinview |
Quote:
Code:
find . \( -name "*~" -o -name ".dolphinview" \) -exec echo rm {} \; |
If any of the files or directories in your tree have spaces in their names (or worse, end-of-line characters), the find command above can cause problems. Also, if there are a very large number of files, using -exec is inefficient since one instance of the rm program is invoked for each file deleted.
I assume you are only interested in deleting files (as opposed to whole directory trees), so it is good to be explicit about it and use the -type f option. Thus I would recommend using this alternative: Code:
find . -type f \( -name "*~" -o -name ".dolphinview" \) -print0 | xargs -0 rm xargs just reads a list of strings, and executes whatever command you specify for groups of those strings. The size of the group is usually large, but you can limit it using the -n option e.g. Code:
seq 1 10 |xargs -n 3 echo |
Good insight, Matthew! Thank you for the detailed notice :)
|
First I would like thank you all for your help and replies.
I tried matthewg42 command and it worked perfectly now I can clear the folder with just one click but I have one more simple question, How can I learn to do this on my own?:study: |
http://www.tuxfiles.org/linuxhelp/cli.html
http://linuxcommand.org/ And read man pages. ;) Code:
man <command> Now that I think of it, I also usually use find ... | xargs rm , but mainly because I want to list what I'm deleting before deleting it. Thought rm -r would be simpler. |
Asking questions about how to do something, and then trying to understand the answers is a good way to get tips.
The way I learned the core *nix commands was from curiosity. Before I even saw a unix-like OS, I had had an MS-DOS box for a year or two, and learned the DOS command inside out. Finding myself sitting in front of a unix terminal for the first time I was horrified to find that even dir was different (ls), but curious to see if there was a 1-1 mapping of programs, or some new ones (to me) on the *nix side. Once I got started it was like a month of Christmas. :) Pipes worked properly, shell scripts were actually useful as a language to so stuff - as opposed to the digital junk of DOS bat files, and the set of basic programs was so well chosen that it was possible to accomplish a massive variety of tasks elegantly, and have fun at the same time. What I did was to look at the PATH variable, and for each directory, I looked at each binary name and read the manual page for it (not in every detail, but tried to understand what the program did). I did a lot of mucking about with text file processing commands: fmt, cut, paste, sort, col, expand, fold, head, tail join etc. and kept myself amused. This was at university, and the systems we used had thousands of user accounts, hundreds of which would be logged in at any one time. I had a lot of fun with write. A little smiley here, a little cheeky something there. On rare, mischievous and slightly evil occasions a huge binary file... aaah, those were the days. It's a pity more people aren't on multi-user systems. I guess the increase in use of LTSP systems re-open the potential for this sort of fun for a lot of students, yay! :D |
Sorry [KIA]aze but I was convinced with what matthewg42 said I think I will try it when I have some backup files created
BTW .dolphinview is not an extension, it is a hidden file created equivalent to thumb.db on windows to save the thumbnails of photos and stuff (I am using dolphin instead of konqueror because it is much faster and simpler but I still can not give up konqueror) And thank you for the sites, but about the man pages I already tried that, but I think I need to already know the basics, or even a general idea about the file in order to know which command I am going to man :) matthewg42: I was using DOS when I was about 10 years so the computer was just for games but when I got a little older I used batch files to run the games from a centralized location, of course Norton Commander was there so it was not so effective and then win95 came and no more command line until I installed Linux, and I already have the alternatives to command line most of the time (even if I am compiling a software), even in this 'search and destroy' I used to do it with the find program, but it was boring so I looked for the command line as an alternative (lucky for me the dir command is working now but after a while I found that 'ls' is much better and colourful) I do not have the chance you got, so, I would rather stick to a book or an on-line site that would give me the basics and after that I would start tyring new commands and reading man pages. judging from your age that was 12-14 years ago:), I guess KDE was just a thought then, and the Internet was not as rich as today, right? you had a lot of time indeed. what I am trying to say is that the way you learnt is not suitable for me. Although, it could have been if I knew you a long while earlier :D But thank you for the advice and for taking the time to write it. |
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
|
Quote:
I looked for the others and here is what I found: archie:(ARCHIvE) An earlier Unix utility used to search for file names on Internet FTP sites. Considered by some as the first search engine, in its heyday before the Web, there were approximately 30 Archie servers throughout the Internet that maintained catalogs of files available for downloading from various FTP sites. Periodically, Archie servers searched the FTP sites and recorded information about the files they found. gopher:A protocol for the storage and retrieval of text on a computer network using a TCP/IP protocol. Mosiac: No software related results yet. Muds mushes: I think it is a game but I am not sure though moos: is a text-based online virtual reality system to which multiple users (players) are connected at the same time. Well, This those are history of computers' software :), I think they should make a museum for such old software. |
Mosaic was a web browser. It was extremely primitive by modern standards, but it was the seed which turned into modern browsers. I don't know if it was the first graphical browser, but it was certainly the first to really achieve some degree of popularity. I think you could also use it as a gopher client too, although I seem to remember the curses-based one which we had on the sparcs was better.
MUDs are an ancestor of the modern MMORPGs like WoW. Text based of course, but non the worse for it IMO. The brain has better visual effects generators even than NVIDIA and ATI put together and then squared. MUSHES and MOOS were a little like MUDs. I think it was MUSHES which were more a sort of interactive fiction system - less hitpoints and more making stuff up. *edit* there are still MUDs around today. Check out Nanvaent |
All times are GMT -5. The time now is 06:34 AM. |