how to write a script file
hi all,
objective: i want to write a shell script file for the below subject subject / situation : i have many users say user1, user2, user3, user4 and so on... within my /home dir within a user dir say.. /home/user1 i have many unwanted files. these unwanted files start with the name core for eg. core2324, core9789, core 9079 etc.. i need to delete them. i want to write an automated script for this, which can do the same. can someone help me to write a script which can delte these unwanted core files which exist in all user dirs. thanks in advance. regards shravee PS: i am new to scripting .. u can say no idea. but i will follow watever u guide. interms of learning any material or so on. |
Quote:
We can HELP you to write a script...so provide what you've done so far, and tell us where you're getting stuck. Otherwise, go to http://www.google.com and look at any one of the thousands of bash scripting tutorials that are out there. You may also want to be aware of how to 'chain' commands together in Linux. In this case, the find command into the rm command, like so: Code:
rm `find -name <path> <expression` Also, be aware that since you want to delete files from other users home directories, you need to be root to run this. |
Show us what you've already tried to do
|
I created a file named "myscript.sh" within /home/user1
my script file contains. -------------------------------------------- rm -rf `find core*` ------------------------------------------- i came to cmd prompt and typed sh myscript.sh this solved my purpose. but this was only for a single user. i need to perform this for several userrs like... /home/user2 /home/user2 and so on... so how to continue this script comd to perform the same for all users.. regards shravee. |
Note: You must be root to delete other users files.
Be careful when using the wildcard * with the rm command. Always do a test run and check the results. Do a test run first. If some file(s) are listed that you do not want to delete, you will need to tweak the command. Code:
find /home/ -type f -name "core[0-9]*") Code:
rm -rf $(find /home/ -type f -name "core[0-9]*") |
Quote:
|
Quote:
|
Hi,
Just a few useful links; Linux Documentation Project Rute Tutorial & Exposition Linux Command Guide Bash Reference Manual <<<< Look here Advanced Bash-Scripting Guide <<<< And here Linux Newbie Admin Guide LinuxSelfHelp Getting Started with Linux The above links and others can be found at 'Slackware-Links' . More than just SlackwareŽ links! |
hi
--------------------------------------------------------------------------------------- dv502, thanks for your code. I will try it out and let you know. --------------------------------------------------------------------------------------- catkin, I created files named cat, c, core2332 and core423 . then i used rm -rf `find core*` which really worked in deleting those core files. --------------------------------------------------------------------------------------- I have a new problem , the script file solved my problem for a single user . so cant i still generalise it for the entire users listed out. regards shravee |
Quote:
|
Quote:
Nowhere in the man page does it say that path has to be a directory; given the behaviour established by shravee it seems that path can be a file. A seldom (ever, until now?!) used feature. Here's experimenting Code:
c@CW8:/tmp/tmp$ ls -l Code:
c@CW8:/tmp/tmp$ find -type f |
Quote:
Code:
find [file...] [expression] Indeed you can avoid to specify the dot as path because it is actually implicit, but I think it is a good habit for clarity and to remind how find actually works. Maybe, it would be interesting to see what happen if you specify both dot and the list of files starting with c: Code:
find . c* |
Quote:
|
All times are GMT -5. The time now is 01:14 AM. |