Problems & Solutions

BASH

  • Loop on files with space characters (Feb 2013)
    • SAVEIFS=$IFS; IFS=$(echo -en "\n\b"); for i in `ls -1 -d *`; do echo $i; done; IFS=$SAVEIFS
    • ls -1 -d | while read i; do echo $i; done
  • Bulk rename files (Feb 2013)
    • ls SomeFilePattern* | while read i; do mv $i ${i/TextToReplace/Replacement}; done
  • Use awk to sum up various output formats (Feb 2013)
    • dq2-size() {dq2-ls -f $1 | grep "total size: " | awk '{sum+=$3} END {printf "%.3f GByte\n", sum/1024/1024/1024}';}
  • Convert m3u playlist from v1 to v2 (Sep 2020)
    • echo "#EXTM3U" > /Volumes/Music/playlist-Electronic-v2.m3u
      cat /Volumes/Music/playlist-Electronic.m3u | while read i; do
        time=`afinfo "$i" | grep "estimated duration" | awk '{print ($3-int($3)>0)?int($3)+1:int($3)}'`
        artist=`mid3v2 "$i" | grep "TPE1" | awk -F"=" '{print $2}'`
        title=`mid3v2 "$i" | grep "TIT2" | awk -F"=" '{print $2}'`
        echo "#EXTINF: $time, $artist - $title"
        echo "$i"
      done >> /Volumes/Music/playlist-Electronic-v2.m3u

LaTeX

  • Write a formal letter (Feb 2013)
    • You might wanna use the g-brief document style. Here’s an example.
  • Write a less formal letter (Feb 2013)
    • You can use a modified article document style. Here’s an example.
  • Write a curriculum vitae (Feb 2013)
    • Try using the moderncv document style. Here’s an example.

Linux

  • Assign a fixed IP address to your PC even though it uses DHCP (Feb 2013)
    • Edit /etc/init.d/dhcp and change the line /usr/local/sbin/dnsmasq -i eth0 -D -b -f -o $options to /usr/local/sbin/dnsmasq -i eth0 -D -b -f -o $options -Z and create a file /etc/ethers filled the mac addresses and the IP addresses you want to assign:
      00:aa:bb:cc:dd:ee 192.168.2.2
      99:aa:bb:cc:dd:ee 192.168.2.3
  • Change your MAC address (Feb 2013)
    • You might have to have root access, depending on the system setup.
      ifconfig eth0 down
      ifconfig eth0 hw ether 00:11:22:33:44:55:66
      ifconfig eth0 up
      ifconfig eth0 | grep HWaddr
  • Use rsync (Feb 2013)
    • I know it’s simple, but I keep asking myself:
      rsync -av --progress --inplace --rsh='ssh -p12345' user@sourcehost:~/dir/* user@targethost:~/.

MacOS

  • Add a separator to the dock (Feb 2013)
    • Issue the following commands as often as you want separators in your dock:
      defaults write com.apple.dock persistent-apps -array-add '{ "tile-type" = "spacer-tile"; }'; killall Dock
  • Change the icon of the file/folder/application (Feb 2013)
    • Simply open the context menu and choose “Get Info”. Select the little icon in the top left corner and paste any previously selected image/icon there. Of course you can also copy the selected image from there to another place.
  • Encrypt your TimeMachine backup (Feb 2013)
    • Follow these steps :)
      1) mount a writeable Apple File Sharing (AFP) volume;
      2) choose this volume as backup disk in the TimeMachine preferences;
      3) start a backup process;
      4) cancel the backup process once it has actually started to back up files and a file called HOSTNAME.sparsebundle has been created on the backup volume;
      5) rename the file to something like old.HOSTNAME.sparsebundle;
      6) convert the image to an encrypted image hdiutil convert -format UDSB -o HOSTNAME.sparsebundle -encryption AES-256 old.HOSTNAME.sparsebundle (enter a sensible password when prompted);
      7) open both images in Finder using the ‘Show Package Content’ function (right click);
      8) move the file com.apple.TimeMachine.MachineID.plist from old.HOSTNAME.sparsebundle to HOSTNAME.sparsebundle;
      9) open the new image HOSTNAME.sparsebundle by double clicking in Finder, enter the previously given password and choose to store the password in your keychain;
      10) open the Keychain Access application and copy the key related from your login keychain to the system keychain (you’ll need admin right s for that);
      11) select the volume in your TimeMachine settings once again;
      12) start a backup;
      13) check if the created encrypted image is used;
      14) enjoy
  • Find good tools for your Mac (Feb 2013)
    • Look here :)
      BetterTouchTool allows to (re)define all sorts of touch command for your touch pad. DejaMeni allows to access you menu from anywhere on the screen.
  • Mount a remote folder via sshfs (Feb 2013)
    • I am assuming that you successfully installed MacFUSE and sshfs.
      Now you can mount a remote folder by issuing e.g.:
      sshfs -o no_readahead,noappledouble,nolocalcaches user@domain.tld:/some/remote/folder ~/some/local/folder
      In principle the same should work on linux, only the noappledouble option (which speeds up the connection enormously) can be dropped.
  • Set up a wrapper application for Linux tools on your Mac (Feb 2013)
    • Start the “Automator” application and choose the “application” template. From the “Utilities” library choose “Run Shell Script”. It will appear on the right side and take the final applications input as parameters, when you choose “Pass input: as arguments” on the right side. In the command box you wanna put source ~/.bashrc; /Applications/MacPorts/KDE4/kate.app/Contents/MacOS/kate "$@" &. Now you save as “File Format: Application” in the “Application” folder and off you go.
  • Show mails in Mail as plain text by default (Feb 2013)
    • Issue the following command in a terminal and if needed restart Mail:
      defaults write com.apple.mail PreferPlainText -bool TRUE
  • Show the current path in Finder’s title (Feb 2013)
    • Issue the following command in a terminal and if needed restart Finder:
      defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES
  • Sync your Google contacts with Mac address book (Feb 2013)
    • Open the address book and in the preferences choose the ‘Synchronize with Google’ option. Enter your account details and … well, in case you haven’t got an iPod or iPhone (connected to your Mac) nothing will happen!? But you can issue the following command in the terminal: /System/Library/PrivateFrameworks/GoogleContactSync.framework/Versions/A/Resources/gconsync --sync com.google.ContactSync or set up a crontab job doing it for you, say every three hours: crontab -e and then paste the following: 0 */3 * * * /System/Library/PrivateFrameworks/GoogleContactSync.framework/Versions/A/Resources/gconsync --sync com.google.ContactSync
  • Tell MacOS to use a temporary IPv6 address (Feb 2013)
    • Issue the following command in a terminal and reconnect to your network: sysctl -w net.inet6.ip6.use_tempaddr=1

Money

  • Split a bill between friends (Feb 2013)

PDF

  • Extract pages from one PDF file into another (Feb 2013)
    • Use pdftk or try this one: pdftops input.pdf - | psselect -p1-8 -p17-31 | ps2pdf14 - output.pdf
  • Reduce file size of PDF files (Oct 2018)
    • Here’s a few options for the command line …
      gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

      gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

      gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

      gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

      gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

      ps2pdf input.pdf output.pdf

      convert -density 200x200 -quality 60 -compress jpeg input.pdf output.pdf

      gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dDownsampleColorImages=true -dColorImageResolution=150 -dNOPAUSE -dBATCH -sOutputFile=output.pdf input.pdf

Windows

  • Share folder in Win XP Home (Feb 2013)
    • Use c:\Windows\system32\shrpubw