We collect practical, well-explained Bash one-liners, and promote best practices in Bash shell scripting. To get the latest Bash one-liners, follow @bashoneliners on Twitter. If you find any problems, report a bug on GitHub.

Tags

0

Mirror from one Subversion repository to another Subversion repository

 $ bzr co https://repo1/proj1/trunk proj1 && cd proj1 && bzr push https://repo2/vendor/proj1/trunk

— by Janos on Aug. 5, 2011, 8:57 p.m.

Explanation

  • The commit history in repo1 will be copied to repo2.
  • The temporary Bazaar repository (proj1) will have the full history of changes.
  • The command above initializes the mirror. To update the mirror, run this script, you can schedule it to run periodically to keep the mirror up to date: cd proj1 && bzr up && bzr push

Limitations

  • The author information will get lost in the process.

1

Rename all files in a directory to lowercase names

 $ paste <(ls) <(ls | tr A-Z a-z) | while read OLD NEW; do echo mv -v $OLD $NEW; done

— by Janos on Aug. 5, 2011, 8:57 p.m.

Explanation

  • <(cmd) is the filename of a named pipe (FIFO), where the named pipe is filled by the output of cmd
  • paste puts together the named pipes to form two columns: first column with the original filenames, second column with the lowercased filenames
  • ... | tr abc ABC transforms stdin by replacing any characters that appear in the first set of letters to the second set of letters
  • while read old new; do ...; done for each line it reads the first column into $old and the second column into $new

Limitations

  • Won't work if there are spaces in a filename.

0

Find Flash videos stored by browsers on a Mac

 $ find /private/ 2>/dev/null | grep /Flash

— by Janos on Aug. 5, 2011, 8:57 p.m.

Explanation

When you watch a flash video like youtube in a browser, the video file is saved on your harddisk at a temporary location. And, if you watch a video and then another video in the same window, the first one will be deleted.

Limitations

  • Might not work with all browsers.
  • Does not work with all websites (for example IMDB).
  • Does not work with an anonymous window in Chrome.