Featured

Use latexdiff to compare different versions of LaTeX tex files to visually mark differences

This post introduces how to use latexdiff to compare two versions of latex *.tex files, in order to visually mark changes to tex files.

(One colleague asked me about the usage of latexdiff, so I think it is a good time to write it up into a blog post to share with those who need some help with this.)

latexdiff is a Perl script and requires an installation of Perl 5.8 or higher.

Use latexdiff to mark differences and create a new LaTeX document with markup differences between two latex files.

  • Linux (Ubuntu) users

latexdiff can be found in Ubuntu repository and detailed description of usage can be found here.

In your terminal, issue the commands below to install latexdiff.

sudo apt-get update
sudo apt-get install latexdiff
# open your terminal, and cd to the tex files you need to compare
# issue the following command
latexdiff original_version.tex revised_version.tex > diff.tex

Run the diff.tex file like you run a normal tex file, you will see beautifully marked differences in the pdf file.

  • Mac OS X users
latexdiff is a Perl script and requires an installation of Perl 5.8 or higher.
Mac OS X includes an installation of Perl and no additional setup is required. latexdiff can be found in any CTAN repository
(If you are using MacTex on your mac,  latexdiff is already installed in MacTex under /usr/texbin/latexdiff. No need to install it separately. To use latexdiff in commend line, see below)
After you setting perl and latexdiff, just open your terminal, and cd to the path where you put you two versions of latex tex files, and then issue the command. (If the two tex files are located in different location, you can just give the relative path to that location for each version of tex file.)

 

$ latexdiff original_version.tex revised_version.tex > diff.tex
will compare original_version.tex to revised_version.tex and create a new file diff.tex showing the differences.
Run the diff.tex file like you run a normal tex file, you will see beautifully marked differences in the pdf file.
  • Online latexdiff 
when you get the diff.tex on the online latexdiff, you can paste into a new tex file and then you can run it and you will see the pdf which shows the differences.
  • Multiple tex files for each version

If each version of your text files contains multiple (sub) tex files or if you want to use latexdiff with Git, check the reference lists for potential solutions.

References:

LATEXDIFF: SUPERB DIFF TOOL FOR LATEX (pdf) — talks about solutions to multiple files, but this can only deal with sub-files on the same level, not nested cases.

Two LaTeX gems: ShareLaTeX and latexdiff (pdf)

Using Latexdiff For Marking Changes To Tex Documents (pdf)

Multiple-file LaTeX diff (pdf— this one is very good. – use python code to merge multiple tex files to one big tex file for each version and then use latexdiff to make comparision.

Latexdiff with subfiles (pdf) — this one talks about solutions to multiple tex files.

Using latexdiff with git (pdf) – Git Latexdiff  — this is about using git together with latexdiff

Git and latexdiff: compare versions of LaTeX documents (pdf) — this is also about using git together with latexdiff

 

 

 

Monitor CPU temperature from terminal on Ubuntu

This post provides instructions on how to monitor CPU emperatures from command line on Ubuntu.

Step 1: Install lm-sensors using the following command in your terminal

$ sudo apt-get install lm-sensors

Step 2: type the following command in terminal

$ sudo sensors-detect

 You will be asked a few questions. Answer Yes for all of them.

Step 3:  type sensors in your terminal to get your CPU temperature.

$ sensors

Step 4: You can run the following command to see temperature values updating each second

$ watch sensors
$ watch -n 10 sensors  

# this will update the temperature values every 10 seconds. You got the idea -- you can change the number 10 to any seconds you would like to see the updated temperature values.

Step 5: use Ctrl + C to terminate.

 

For more commonly used Linux commands, check my other posts at here  and here .

 

lftp usage on Linux

This post introduces lftp usage on Linux.

(Thanks Scott for sharing this nice tool.)

lftp is a command-line program client for several file transfer protocols. lftp is designed for Unix and Unix-like operating systems.

1: Installation on Ubuntu:

$ sudo apt-get update
$ sudo apt-get install lftp

2: Some commonly used commands with lftp:

ls  — list direcotries and files on remote ftp server

cd — change directory on remote ftp server

lpwd — list local machine current directory

lcd — change local directory

mput *.csv  — mput for multiple files, put for a single specific file.

This will take from the current local directory  and put into the current remote directory on  remote ftp server.

copy directory and its contents to and from ftp server (from and to local machine):

mirror -c -R  path/to/localdirectory/   

This will copy local directory to (the current directory) on the  remove ftp server  , c means continue)

       mirror -c  path/to/remote/directory

This will copy the remote directory  to (the current local directory  , c means continue)

(for more commands, check the lftp man page provided in the references below.)

3: Using Box under Linux (using lftp)

The lftp command is a powerful file transfer client that can be used with Box.

Box supports the secure FTPS protocol and you can use this with lftp for secure file transfer and mirroring.

The lftp command is smart enough to auto-negotiate to use FTPS but this example forces the issue to make absolutely sure unencrypted FTP is never attempted.

Here is an example of how to connect using FTPS.

$ lftp
lftp :~> set ftps:initial-prot ""
lftp :~> set ftp:ssl-force true
lftp :~> set ftp:ssl-protect-data true
lftp :~> open ftps://ftp.box.com:990
lftp ftp.box.com:~> user yourusername@psu.edu
Password:
lftp yourusername@psu.edu@ftp.box.com:~> ls
...

 

when finish use exit to exit from lftp.

4: Copy a remote folder via FTP on the Linux command line using lftp (PDF)

 

References:

lftp Man page (PDF)

Using Box under Linux (PDF)

For more commonly used Linux commands, check my other posts at here  and here .

 

Find all files containing specific text on Linux and Mac

This post introduces how to find all files containing some text on Linux and Mac.

Step 1: cd to the folder where you would like to start with the search.

Step 2: use the following command:

$ grep -Ril "text-to-find-here" ./

Then the file names containing the text you would like to search will be listed.

  • R — stands for recursive.
  • i —  ignore case (optional in your case).
  • l — stands for “show the file name, not the result itself”.

For more commonly used Linux commands, check my other posts at here  and here .

Find files NOT ending in specific extensions

This post provides instructions on how to find files NOT ending in specific file extension(s) when a folder contains many many files on Linux (tested on Ubuntu and CentOS)  and Mac OS.

Open a terminal, and

cd into the folder you would like to list the file extensions.

In your terminal, issue the following command :

$ find . ! \( -name "*.py" -o -name "*.exe" \)

This will list all files that are not a .py file and not a .exe file (change the file extension(s) name according to your name:)).

 

$ find . ! \( -name "*.exe" \)

This will list all files that are not a .exe file.

 

$ find . ! \( -iname "*.exe" \)

This will list all files that are not a .exe or .EXE file.

Note:  -name is case sensitive while -iname is case insensitive.

 

For more commonly used Linux commands, check my other posts at here  and here .

Find the distinct file extensions in a folder

This post provides instructions on how to list all the distinct file extensions when a folder contains many many files on Linux (tested on Ubuntu and CentOS)  and Mac OS.

Open a terminal, and

cd into the folder you would like to list the file extensions

Method 1: issue the following command:

$ find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u

This will help us:

  • Find all files from current folder (including files contained in its sub-folders)
  • Prints extension of files if any
  • Make a unique sorted list (e.g., sort -u is for ordering by Alphabet, -u means unique)

See the  pic below for an example.

Method 2: A variation of the method 1.  Issue the following command

$ find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort | uniq -c | sort -n

This will list with counts for each extension (sort -n is for ordering by file number).

See the pic below for an example.

More flags about sort command can be found here (PDF) and here (PDF).

 

For more commonly used Linux commands, check my other posts at here  and here .

Dynamic GPU usage monitoring (CUDA)

To dynamically  monitor NVIDIA GPU usage, here I introduce two methods:

method 1: use nvidia-smi

in your terminal, issue the following command:

$ watch -n 1 nvidia-smi

It will continually update the gpu usage info (every second, you can change the 1 to 2 or the time interval you want the usage info to be updated).

use Ctrl + C to terminate.

method 2: use the open source monitoring program glances with its GPU monitoring plugin

in your terminal, issue the following command to install glances with its GPU monitoring plugin

$ sudo pip install glances[gpu]

to launch it, in your terminal, issue the following command:

 $ sudo glances

Then you should see your GPU usage etc. It also monitors the CPU, disk IO, disk space, network, and a few other things

use Ctrl + C to terminate.

For more commonly used Linux commands, check my other posts at here  and here .

Unzip file from Terminal on Linux

This post provides the instructions about how to unzip a file from terminal on Linux.

Step 1: install unzip using the following command

$ sudo apt-get install unzip

Step2: cd to the directory where you zip file located

Step3:  use  the following command to unzip your file

$ unzip yourfile.zip 

#this will unzip the file to the current folder
#if you'd like to extract to a particular destination folder, use the following instead:
$ unzip yourfile.zip -d destination_folder

For more commonly used Linux commands, check my other posts at here  and here .

Counting files in a Linux directory

This post will show you how to count files under a Linux directory.

Step 1: cd  to the folder you would like to count the files.

Step 2: issue the following command, then you should see a number, which is the number count of the files under the current directory.

find . -type f | wc -l
  • -type f indicates  counting files only.   You can remove the -type f to include directories (and symlinks) while counting.
  • | (note: not ¦) redirects find command’s standard output to wc command’s standard input.
  • wc (stands for word count) counts newlines, words, and bytes on its input (see here for more details.).
  • -l to count just newlines.

Notes:

  • This command may overcount if filenames can contain newline characters.

For more commonly used Linux commands, check my other posts at here  and here .

List files by time (in reverse order) and in human readable file size

This post tells you how to list files under a directory by time in reverser order and in human readable file size (works on Linux OS and Mac).

  • ls -ltrh 

list all the csv files under the current directory in long format by time and in reverse order, the file size in human readable format (e.g., in mb, or gb, instead of byte size)

  • -l List in long format. If the output is to a terminal, a total sum for all the file sizes is output on a line before the long listing.
  • -r Reverse the order of the sort to get reverse lexicographical order or the oldest entries first (or largest files last, if combined with sort by size.
  • -t Sort by time modified (most recently modified first) before sorting the operands by lexicographical order.
  • ls -ltrh *.csv

list all the csv files under the current directory in long format by time and in reverse order, the file size in human readable format (e.g., in mb, or gb, instead of byte size)

 

For more commonly used Linux commands, check my other posts at here  and here .