Twitter http://twitter.com/ebalaskas/
Blog http://ebalaskas.gr/blog
Website http://ebalaskas.gr/

0

Rename all files in a directory to upper case

 $ for i in *; do mv "$i" "${i^^}"; done

— by EvaggelosBalaskas on April 20, 2013, 9:53 p.m.

Explanation

Loop over the items in the current directory, and use Bash built-in case modification expansion to convert to upper case.

Limitations

The case modification extension is available since Bash 4.

5

Rename all items in a directory to lower case

 $ for i in *; do mv "$i" "${i,,}"; done

— by EvaggelosBalaskas on April 20, 2013, 9:41 p.m.

Explanation

Loop over the items in the current directory, and use Bash built-in case modification expansion to convert to lower case.

Limitations

The case modification extension is available since Bash 4.

1

Sort and remove duplicate lines from two (or more files). Display only uniq lines from files.

 $ sort file1 file2 | uniq -u

— by EvaggelosBalaskas on March 6, 2013, 8:58 a.m.

Explanation

The -u flag of uniq removes duplicate lines from the input.

Example file1:

123456
234567
345678

Example file2:

234567
345678
456789

Result:

123456
456789

3

Remove offending key from known_hosts file with one swift move

 $ sed -i 18d .ssh/known_hosts

— by EvaggelosBalaskas on Jan. 16, 2013, 2:29 p.m.

Explanation

Using sed to remove a specific line.

The -i parameter is to edit the file in-place.

Limitations

This works as posted in GNU sed. In BSD sed, the -i flag requires a parameter to use as the suffix of a backup file. You can set it to empty to not use a backup file:

sed -i'' 18d .ssh/known_hosts

0

How to expand a CIDR notation to its IPs

 $ for j in $(seq 0 255); do for i in $(seq 0 255) ; do seq -f "10.$j.$i.%g" 0 255; done; done

— by EvaggelosBalaskas on Jan. 16, 2013, 11:53 a.m.

Explanation

Using two for loops to create second & third block of IP and finally through a formatted seq to printf the output.

More efficient/using less memory than using {..} (range).

Limitations

seq is not available by default in some systems.