DOS command line tips.

Started by Tarn, February 26, 2013, 12:51:05 AM

Previous topic - Next topic

Tarn

Many of the older hackers already know this stuff. This is for those who are learning about DOS commands for the first time. And for those who have forgotten them.

Here are a couple of simple tricks you may find useful at the DOS prompt (in the CMD window. They involve the use of the <F3> key; the <U> up arrow key; and the <D> down arrow key.

Using the up arrow key will echo your last command as if you had re-typed it. Pressing <U> again will echo the command previous to that. You can scroll backwards through the last 20 or so commands that you have typed. Useful when you want to re-enter a long command that has lots of Perl notation in it.

Using the down arrow key will take you forward through the list; from oldest to most recently typed.

Next is the <F3> key. It echoes your last command only, but with a twist. It echos it from your cursor position. Here is an example.

dir *.*_original /s <Enter>

This will list any filename, with any extension plus "_original" added to the extension, in your working directory and all sub-directories. Now type:

del <F3> (don't hit enter yet)

You will see that pressing the <F3> key has added "*.*_original" after your "del". Pressing <Enter> will issue the delete command as if you had typed it; and will delete all the files listed with the "dir..." command.

If you were to type in:

copy (space) <F3>

You would end up with:

copy .*_original

That is because <F3> echoes the last command from your cursor position. Typing "copy " puts you two places past "dir" or "del" and into the command argument. You can avoid this problem by adding extra spaces after a short command like "dir" or "del".

Saving "dir *.*_original /s" to something like "orig.bat" is an easy way to see, or find any of the backup files created by ExifTool. And saving "del *.*_original /s" as something like "origd.bat" is a quick easy way to remove those backup files, when you want to do more work on the same files. (I always work on copies anyway.)

One last trick. Ever spend a lot of time trying to, correctly, type in a command? Try after try... frustration building... then... finally you get it right. Now the trick is trying to re-type that, correctly, into a batch file for later use. Here's the trick. First you get the following command to work:

"-filename<${datetimeoriginal}-${filenumber}.%e" -d %y%m%d *.* -P –progress

Now, hit <F3>, or your up arrow key <U>. You will see the same command echoed at the DOS prompt. At the tail end, add a space and type:

> datename.bat (include the ">" right arrow)

Use your left arrow key <L> to scroll to the very beginning of that line, where you can go no further. Now type:

echo (space)

Your command line should look like this:

echo ExifTool "-filename<${datetimeoriginal}-${filenumber}.%e" -d %y%m%d *.* -P -progress > datename.bat

Look for "datename.bat" in the directory (folder) you were working in. Edit it to add one more "%" to your variables. Change .%e to read .%%e; and change %y%m%d to read %%y%%m%%d. (you need the second "%" because of the batch file. Save that change, and, in the future, just type

datename <Enter>

And you have saved yourself some typing.  I would recommend that you move the file into your C:\windows directory. That is in your path and keeps the file from getting deleted by an errant "del *.*" command.

Hope this helps the newer people.

Dislcaimer: This is for Windows. I know bupkiss about MAC.


Phil Harvey

Here is an exiftool-specific command line tip that really needs to be mentioned somewhere, so here is as good a place as any...

It is often preferable to specify a directory name (ie ".") instead of using wildcards (ie "*.*") for a number of reasons:


  • "*.*" will process any file with a "." in the name.  This includes files that ExifTool should not normally process (like the "_original" backup files for example).  By specifying a directory name instead, ExifTool will process only supported file types.  Or the -ext option may be used to process specific file types.

  • "*.*" will process any sub-directories which contain "." in the name. This may be unexpected.

  • The -r option (to recursively process sub-directories) is only effective when a directory name is specified, so it doesn't work when "*.*" is specified (unless the first-level directories have a "." in the name, as mentioned in point 2 above).

  • Arguments like "*.jpg" are a problem on systems with case-sensitive file names (like OS X and Linux) because JPG images with uppercase extensions will be missed.  It is better to avoid this problem and use "-ext jpg ." to process all JPG images in the current directory because this technique is case-insensitive.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).