Linux
Processing files using ‘find’
by Mostafa on Mar.26, 2008, under How To ..., Linux, Software
In its most basic form, find is often used to locate files that are subsequently piped through a complex set of commands for processing. However, this particular method is easily broken by files that contain spaces in their names.
This is where the ‘exec’ option provided by find comes in handy. From the man-page:
-exec command ;
Execute command; true if 0 status is returned. All following
arguments to find are taken to be arguments to the command until
an argument consisting of ‘;’ is encountered. The string ‘{}’
is replaced by the current file name being processed everywhere
it occurs in the arguments to the command, not just in arguments
where it is alone, as in some versions of find. Both of these
constructions might need to be escaped (with a ‘\’) or quoted to
protect them from expansion by the shell. See the EXAMPLES sec-
tion for examples of the use of the ‘-exec’ option. The speci-
fied command is run once for each matched file. The command is
executed in the starting directory. There are unavoidable
security problems surrounding use of the -exec option; you
should use the -execdir option instead.
An example that recursively touches all *.log files from the current directory would be:
$ find . -name \*.log -exec touch {} \;
Saving power with Linux
by Mostafa on Dec.03, 2007, under Linux
An interesting site with numerous tips and tricks on power efficient computing using Linux:
It is also home to the rather useful “PowerTOP” tool. If the testimonials are anything to go by, everyone running a recent release of Linux should give this a try.
Extracting Audio/Video
by Mostafa on Dec.01, 2007, under How To ..., Linux, Software
It’s really easy to extract either audio or video from a multimedia file using ‘ffmpeg‘. To extract audio only:
$ ffmpeg -i inputfile -vn -acodec copy outputfile
And for video only, replace ‘-vn‘ with ‘-an‘ and ‘-acodec‘ with ‘-vcodec‘.
ffmpeg is also commonly used as a transcoding tool.
SSH Blacklisting
by Mostafa on Nov.29, 2007, under How To ..., Linux, Software
After getting around 1500 failed ssh login attempts a day for a while on a server I manage, I decided to look into tools that automatically blacklist offending IPs.
Sshblack fits the bill perfectly. A HOWTO (including an init-script) for REDHAT-like systems is available from the OSS Watch Wiki.
User installation of additional TeX/LaTeX classes and styles
by Mostafa on Aug.09, 2007, under How To ..., LaTeX, Linux
When you are the sysadmin, you can simply drop the new class/style files under the system TeX path (e.g. /usr/share/texmf/tex/) and run ‘texhash’ to have them automatically picked up. But what do you do when you are just a regular user?
TeX/LaTeX looks at the TEXINPUTS environment variable to look for additional locations to search for included/referenced files. Therefore, new classes/styles can be easily added as follows:
- Create a directory for the files:
$ mkdir -p $HOME/tex/latex
- Place the new class files into that folder (each class can be in its own directory and contain subdirectories):
$ cp -a fancy-class $HOME/tex/latex/
- Export the TEXINPUTS variable and also add it to your $HOME/.bash_profile:
$ export TEXINPUTS=.:$HOME/tex/latex//:$TEXINPUTS
The ‘.’ ensures that the working directory is included in the search path. The double-‘//’ tells bash to also include files in subdirectories of ‘$HOME/tex’ recursively.
New BibTeX files can also be added locally in a similar fashion. The variables to set are then BSTINPUTS and BIBINPUTS.
The environment variable to set for MakeIndex styles is: INDEXSTYLE.
Source: AstroNat – Installation at The Smithsonian/NASA Astrophysics Data System
UPDATE [16 July 2009] The Kpathsea manual provides a wealth of information about usable environment variables.
Network Security
by Mostafa on Aug.09, 2007, under How To ..., Linux, Software
A list of very interesting articles:
http://backtrack.offensive-security.com/index.php?title=ExternalHowto
Joining PDF Documents
by Mostafa on Aug.03, 2007, under How To ..., Linux, Software
A quick search on the web reveals that the simplest (and most available) command to do so is:
$ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf file1.pdf file2.pdf
Source: Putting together PDF files by Scott Nesbitt on NewsForge
[Update: Feb 1, 2011] jpdftweak is probably a better option with many useful features.
Named Pipes (FIFOs)
by Mostafa on May.22, 2007, under How To ..., Linux
A named pipe is a special kind of file on *nix systems that can be used for inter-process communication. They behave like FIFOs and are created using the command “mkfifo“:
$ mkfifo mypipe$ ls -l mypipe prw-rw-r-- 1 xxx xxx 0 May 22 10:18 mypipe
The “p” in the attributes list indicates that this is indeed a pipe.
A trivial example of its use may be to redirect the output of a command on a remote server to a pipe and then reading from that pipe from another host via ssh.
Software Keyboard and Mouse (KM) Switcher
by Mostafa on May.15, 2007, under How To ..., Linux, Software
Stumbled across this great tool a few days ago:
Description from the project homepage:
Synergy lets you easily share a single mouse and keyboard between multiple computers with different operating systems, each with its own display, without special hardware. It’s intended for users with multiple computers on their desk since each system uses its own monitor(s).Redirecting the mouse and keyboard is as simple as moving the mouse off the edge of your screen. Synergy also merges the clipboards of all the systems into one, allowing cut-and-paste between systems. Furthermore, it synchronizes screen savers so they all start and stop together and, if screen locking is enabled, only one screen requires a password to unlock them all.
Mass conversion of images
by Mostafa on May.07, 2007, under How To ..., LaTeX, Linux, Software
The following “one-liner” can be used to mass convert a given image format into another using the convert (part of ImageMagick) and basename tools:
$ for A in $(ls *.$SRC_TYPE); do convert $A $(basename $A .$SRC_TYPE).$DST_TYPE; done
where $SRC_TYPE is the file suffix of the original images (e.g. png) and $DST_TYPE is the file suffix of the type desired (e.g. eps).


