command

Image of a terminal prompt

Pro Tip: For, While and Until Loops

LEVEL: SYSADMIN / TIME: 1-2 min. Here’s some handy quick reference examples to go back to easily if you are needing to use for, while and until loops in your bash shell scripts. This is perfect for bookmarking and coming back to at a later date. I am always forgetting the subtle syntax differences that bash has, compared to other languages I use, for example C, PHP, Python etc. Before I show you the examples,…



shell prompt image

running a command against every line in a textfile

So, you have a text file like so: file1 file2 .. And you want to run a command on each line of the file (say, chmod 644). Like all things UNIX, there are more than one way to do thing, but here’s the quick and dirty answer: xargs -0 -n 1 chmod 644 < <(tr \\n \\0 <filelist.txt)   So, this will run xargs on the std. input (filelist.txt). -n is max arguments – in…