legacy-wiki
Bash
Recovered from the older tannerjc.net wiki snapshot dated January 23, 2016.
- make for loops ignore spaces in input
IFS='\n'
for BLAH in `cat filename`; do
IFS=$(echo -e \n\r)
one liners
for loop
for i in $(seq 1 9); do ssh -f server.example.com logger hi; done;
for i in `ls|xargs`; do bzip2 -d $i; done;
date formatting
$ date +%F-%H-%M-%S.pcap
2011-01-28-11-25-13.pcap
unique use cases
- multiple zip files
- zip files have spaces
- each with files of similar naming scheme
- all unzip to current dir
take care of spaces in zip files
#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en \n\b)
for f in *
do
echo $f
done
IFS=$SAVEIFS
for f in *; do mkdir $f-dir; done
unzip archives inside the newly created dirs of same root name
for f in *.zip; do unzip $f -d $f-dir; done