Monday, 19 March 2018

linux - Run a command on every file in a directory, changing the output name


I need to compile all of the C files in a directory into seperate outputs... see example gcc -Wall program1.c -o program1.out


How do I do this?



Answer



Use string manipulation:


for f in *.c; do gcc -Wall "$f" -o "${f%%.c}.out"; done

No need for complicated regular expressions or anything that's not a shell builtin here.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...