Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts

Monday, March 20, 2023

Make a bootable Linux/Ubuntu live USB drive on OS X


We'll see how to create a bootable Linux/Ubuntu USB drive, from an ISO image, on OS X using command line commands.

Step 1: Download the Ubuntu Image

The first step is to download the Ubuntu image from the official website. Live CD images allow to run Ubuntu without installing it. Here, we'll use an old Ubuntu 16 image from https://releases.ubuntu.com/xenial/: ubuntu-16.04.6-desktop-i386.iso

Step 2: Identify the USB Drive

Next you'll need to identify the USB drive that you want to use for the installation. You can do this by opening up a Terminal window and typing:

$ diskutil list

This command will list all of the disks currently connected to your computer. Identify the USB drive that you want to use for the installation and take note of its device identifier (e.g., /dev/disk2).

Step 3: Unmount the USB Drive

Before you can write the Ubuntu image to the USB drive, you need to make sure that it's unmounted. To do this, type the following command into the Terminal:

$ diskutil unmountDisk /dev/disk2

Note: Make sure to replace /dev/disk2 with the device identifier of your USB drive.

Step 4: Write the Ubuntu Image to the USB Drive

Now that your USB drive is unmounted, you can write the Ubuntu image to it using the dd command. Type the following command into the Terminal:

$ sudo dd if=~/Downloads/ubuntu-16.04.6-desktop-i386.iso of=/dev/rdisk2 bs=1048576

Note: Make sure to replace ~/Downloads/ubuntu-16.04.6-desktop-i386.iso with the path to the Ubuntu image on your computer, and /dev/rdisk2 with the device identifier of your USB drive.

The dd command will take some time to complete, so be patient. Once it's finished, you should see a message indicating how many bytes were transferred.

Step 5: Eject the USB Drive

Finally, you need to eject the USB drive to ensure that all of the data has been written correctly. Type the following command into the Terminal:

$ diskutil eject /dev/disk2

Note: Make sure to replace /dev/disk2 with the device identifier of your USB drive.

That's it! You've successfully created a bootable Ubuntu USB drive using command line commands on OS X. You can now use this USB drive to install or run Ubuntu on any computer that supports booting from USB.


Source: https://thornelabs.net/posts/create-a-bootable-ubuntu-usb-drive-in-os-x/

Friday, October 8, 2021

pandoc: quite good conversion from Latex to docx with references and preserving tikz figures

This works surprisingly well, with all the figures and even rendering the BibTex references: 

> pandoc -C -s main.tex --natbib -o main.docx 

this will produce a document with citations using the  (Author, year) format, to produce citations with a numeric format download the ieee.csl file and call:  

> pandoc -C -s main.tex --natbib --csl=ieee.csl  -o main.docx  


To preserve tikz figures a specialized tikz-to-png filter is needed.  It should be downloaded in the current directory and use the call: 

> pandoc -C -s main.tex --natbib --csl=ieee.csl  --from latex+raw_tex --lua-filter=tikz-to-png.lua -o main.docx  


Figure numbers and captions are not preserved (for obscure reasons), however  table numbering can be  preserved using the document type  -t odt+native_numbering  or  -t docx+native_numbering. 

> pandoc -C -s main.tex --natbib --csl=ieee.csl  --from latex+raw_tex --lua-filter=tikz-to-png.lua -t docx+native_numbering -o main.docx  


Cross-references to sections and figures tables can be recovered with the resolve-references filter but the final format won't be great

> pandoc -C -s main.tex --natbib --csl=ieee.csl  --from latex+raw_tex --lua-filter=tikz-to-png.lua --lua-filter=resolve-references.lua -t docx+native_numbering -o main.docx  


Sources: 
https://waterprogramming.wordpress.com/2018/08/26/converting-latex-to-ms-word-docx-almost-perfectly/
https://tex.stackexchange.com/questions/268196/how-to-convert-latex-to-word-using-pandoc-and-keep-citations-as-numeral

Friday, February 12, 2021

reduce the size of a pdf file compressing its figures


To reduce the size of a PDF file in linux of mac you'll need ghostscript (which in mac can be installed  with: brew install ghostscript). The following command line will generate a smaller file:  

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


    Different levels of compression can be obtained changing the option -dPDFSETTINGS:
  • -dPDFSETTINGS=/screen lower quality, smaller size. (72 dpi)
  • -dPDFSETTINGS=/ebook for better quality, but slightly larger pdfs. (150 dpi)
  • -dPDFSETTINGS=/prepress output similar to Acrobat Distiller "Prepress Optimized" setting (300 dpi)
  • -dPDFSETTINGS=/printer selects output similar to the Acrobat Distiller "Print Optimized" setting (300 dpi)
  • -dPDFSETTINGS=/default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file

source: https://askubuntu.com/questions/113544/how-can-i-reduce-the-file-size-of-a-scanned-pdf-file

Saturday, January 26, 2013

Single TAB bash completion

Bash completion (when enabled) allows you to complete paths, commands, and filenames by hitting the TAB key. On the first press of the TAB key it completes the command as long as there is no ambiguity about the completion. If there are several possible completions a second key press reveals all the options.

It is possible to setup bash/readline to reveal the options after the first key press. Just add the following line to your ~/.inputrc :
 set show-all-if-ambiguous on

Source: http://blog.sanctum.geek.nz/lazier-tab-completion/

Saturday, August 25, 2012

Change text inside multiple files (command line)

I always forget these commands, and they are so useful.
The sed command to replace some text in a set of files:
     sed -e 's/old text/new text/g'  -i .trash  *.c 

The regular expression 's/some text/new text/g' is applied to each line of each file *.c.
And the -i flag saves a backup of each file.

The regular expression language is powerful, for instance allows to remember parts of the pattern in the substitution. An example: the following command puts quotation marks around everything that follows the first = sign in each line of script.sh.
  sed -e 's/=\(.*\)/="\1"/' script.sh

The pattern enclosed between \(   and   \) is stored in \1, and then used in the replaced text.

Source: http://www.labnol.org/internet/design/wordpress-unix-replace-text-multiple-files/1128/

Wednesday, August 8, 2012

Find broken symbolic links

To list the symbolic links along with where they point to:

     find -L /PATH/TO/SEARCH -type l -exec ls -l {} \;  

Omitting  -exec ls -l {} \;  will just list the link name.

Other references: http://how-to.wikia.com/wiki/How_to_find_broken_symbolic_links