Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
Hello all, I'm just getting into scripting and I'm tring to write a script that will operate on each file in a directory, but I'm a little lost on the programming scructure necessary to do so. Basically I want to take each file, check the extension using an if/then statement, then run a command on the file conditionally based on the results of the if/then. Can someone point me in the right direction? I'm clear on how to do an if/then, it's just the part about operating on each file where I'm fuzzy. I tried accepting it as an argument, and then doing a for file in $1, but then I realized that filenames with spaces in them would be affected, so I obviously need a better way of doing this. Any help would be much appreciated.
I tried accepting it as an argument, and then doing a for file in $1, but then I realized that filenames with spaces in them would be affected.
The problem with spaces in filenames can be avoided simply by putting double quotes around the variable "$1".
It sounds to me like you need to investigate the command find. These commands checks whether my website validates by running a perl script called validate on every .html file under a particular folder
Code:
for page in $(find /home/andy/save/src/htdocs -name "*.html")
do validate "$page" &>/dev/null || echo "$page is not valid html"
done
This find command changes the permissions on only the files (not the folders) under a particular folder
Code:
find /usr/share/AbiSuite-2.4 -type f -exec chmod 644 {} \;
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.