Swiss File Knife Highlights

SFK is a free Open Source tool for the command line of every computer, with more than 100 functions. These are the most important ones.

Create zip files easy and flexible.

Create a zip file with all files of a folder.
Create a zip file with some selected files of a folder.
Create a zip file of files changed today.
Create a 20 GBytes .zip file of of all movies in a folder.
Extract only some files from a zip file.

Send files to another computer, instantly.

Send all files of a folder to another computer.
Send only selected files of a folder.
Send only files changed today.
Run a web server for file upload.

Copy files from one folder to another.

Copy files of a folder, except ...
Copy files of a folder, but only ...
Copy only files changed in the last 3 days.

Find filenames on your computer, instantly.

Create a quick filename index.
Find filenames immediately by the index.

Find text in office files, fast and flexible.

Find text in office files on the command line.

Automate things with easy batch files.

Create a script for your daily backup.
Create a script for your weekly backup.

Open Source, no installation, instant use.

Create a zip file with all files of a folder.

Create a zip file containing all files of folder mydir by:

   sfk zip mydir

Create a zip file with some selected files of a folder.

List files in folder mydir, but only those ending .png and .jpeg, located in specific sub folders having media in their name:

   sfk list -dir mydir
-subdir media -file .png .jpeg
(Type this all in one single line.)

This will produce a listing of selected files. When satisfied, add +zipto:

   sfk list -dir mydir
-subdir media -file .png .jpeg
+zipto images
This will show a preview what would be put into the zip. Add -yes to really create the .zip file.

Create a zip file of files changed today.

List only files in folder mydir which were changed today:

   sfk today mydir

You get a listing of files. Maybe you don't want some of them to be zipped, like .bak or .tmp, or anything with test in it's name. Then add exclusion of those like:

   sfk today mydir !.bak !.tmp !test
Finally, zip them into a file like:
   sfk today mydir !.bak !.tmp !test
+zipto today.zip
On Mac/Linux the command looks a bit different:
   sfk today mydir :.bak :.tmp :test
+zipto today.zip

Create a 20 GBytes .zip file of of all movies in a folder.

SFK can create 64-bit zip files, meaning contents can be larger than 2 GBytes. So for example

   sfk zip movies.zip media .mov
will pack all .mov files from folder media into a file movies.zip, with no need to worry about the output size.

Be aware, however, that some (older) software may not be able to read 64-bit zip file contents.

Extract only some files from a zip file.

You can list all files of a zip file like

   sfk unzip myfile.zip
As long as you don't add -yes you will only see the list of files that would be extracted, but nothing is written. Now, if you only want all files having the pattern foo in their path or filename, type
   sfk unzip myfile.zip -pat foo
which will select, for example:
   project/media/foo1.png
project/media/barfoo9.png
project/foostufff/test1.png
If you only want to extract filenames and sub folders starting with foo, type:
   sfk unzip myfile.zip -pat /foo
If you only want files from sub folder media, or called exactly media, type:
   sfk unzip myfile.zip -pat /media/

Send all files of a folder to another computer.

You have a target PC, Macintosh, or Linux computer to which you want to send files. Then run on that computer:

   sfk sftserv -rw
instant file server, which gives read and write access to the current folder, and all sub folders. SFK tells:
   SFK Instant FTP 105.
waiting on port 2121,
IP 192.168.1.100
Remember the IP of the target computer, in this case 192.168.1.100.

You have a source PC, Macintosh, or Linux computer from which you want to send files to the target. On that computer, type:

   sfk dir mydir +put 192.168.1.100
This will send all files of folder mydir, including all sub folders, to the target computer. You will only see a preview of files. Add -yes to really send the files.

The +put will only send files which do not exist yet in the target, or which are newer. You can use +putall to enforce sending of all files regardless of file time.

Send selected files of a folder to another computer.

List files in folder mydir, but only those ending .png and .jpeg, located in specific sub folders having media in their name:

   sfk list -dir mydir
-subdir media -file .png .jpeg
(Type this all in one single line.)

This will produce a listing of selected files. When satisfied, add +put:

   sfk list -dir mydir
-subdir media -file .png .jpeg
+put 192.168.1.100

Send files changed today to another computer.

List only files in folder mydir which were changed today:

   sfk today mydir

You get a listing of files. Maybe you don't want some of them to be sent, like .bak or .tmp, or anything with test in it's name. Then add exclusion of those like:

   sfk today mydir !.bak !.tmp !test
Finally, send them to computer 192.168.1.100 by:
   sfk today mydir !.bak !.tmp !test
+put 192.168.1.100
On Mac/Linux the command looks a bit different:
   sfk today mydir :.bak :.tmp :test
+put 192.168.1.100

Run a web server for file upload.

You made a photo on your mobile. Now you want it on the PC, without the need to plug in a cable. On the PC, CD into the target folder, then type:

   sfk webserv -rw
This gives read and write access to the current folder, and all sub folders. It will tell something like:
   SFK Instant HTTP Server.
Waiting on port 80.
Try http://192.168.1.100
Now open a web browser on your mobile, and type the shown address, in this example 192.168.1.100. You will get a simple web page with the possibility to select and upload a file.

Copy files of a folder, excluding sub folders and files.

You want to copy folder project to project2. Let's start by:

   sfk copy project project2
This will not copy anything, it just shows the selected files:
   project\readme.txt
project\logo.png
project\turnover.xlsx
project\turnover.xlsx.bak
project\oldstuff\turnover.xlsx
project\logging\dbdump.dat
All you want is a clean project copy without all kind of junk files. You do not want to copy .bak files, sub folders oldstuff, sub folders logging. Therefore extend the command like:
   sfk copy project project2
-dir . -subdir !old !log
-file !.bak
Type this all into one line. This will exclude
• all sub folders having "old" or "log" in their name
• all files ending with extension .bak
The command is not fully precise, it would also exclude sub folders like "folding" and "logos". In most cases the quick-typed form is sufficient, but if you want it precise, type
   sfk copy project project2
-dir . -subdir !\old\ !\log\
-file !.bak
When satisfied with the file list preview, add -yes.
On Mac/Linux the command looks a bit different:
   sfk copy project project2
-dir . -subdir :/old/ :/log/
-file :.bak

Copy only selected files of a folder.

You want to copy parts of folder work to docs. Let's start by:
   sfk copy work docs
This will not copy anything, it just shows the selected files:
   work\foo.cpp
work\bar.cpp
work\system.hpp
work\docs\intro.docx
work\docs\dataflow.png
You only want to copy files like readme, .docx, dataflow. Then use
   sfk copy work docs
-dir .
-file readme .docx dataflow
Type this all into one line. The output could be:
   [simulating:]
work\docs\dataflow.png
work\docs\intro.docx
would copy 3 files, 2 mbytes.
Finally add -yes to really copy the files.

Copy only files changed in the last 3 days.

Folder work contains 150,000 files, and doing

   sfk copy work work2
may take halve a minute, because SFK has to look at each and every file, just to find out which were changed. If you know work2 is a full copy of work already, and you only want to copy changes made in the last three days, use instead:
   sfk copy work work2 -since 3d

Create a quick filename index.

On the command line, go to C:\, then type:

   sfk index .
Don't forget the dot ".", which means to index the current directory, including all sub directories. This will create an index file zz-index\zz-index.txt with all filenames on drive C:\. It will take a few minutes.

On Mac/Linux, go to the root folder by cd /, then run the command as administrator like

   sudo sfk index .
which will create a file zz-index.txt directly in the root folder.

If you don't want to do this as root, use gindex instead. No matter in which folder you are, just type:

   sfk gindex /
and it will create a so-called global index file like
   /home/yourusername/
.sfkhome/data/zz-index.txt
containing all names of "/" and sub folders. The sfk name command will also search this global index automatically.

Find filenames immediately by the index.

You know there is a file, with something like "island" and ".jpg" in it's name. But you have no idea where. Then type:

   sfk name island .jpg
It will load the index file created above, extract all files having these words in their path and filename, and list the results, sorted by modification time.
using: C:\zz-index\zz-index.txt
C:\doc\screens\03-carib-island.jpg
C:\doc\screens\05-island-pathway.jpg
C:\webdir\desks\1280-green-island.jpg
C:\webdir\desks\1600-green-island.jpg

Searching filenames this way is much faster than with any search function provided by your operating system. And you have control over the indexing time point. If you know you did the last indexing 7 days ago, you can be sure all files of age 8 days and older must be contained in the index.

By the way, the Freeware tool Depeche View can load the whole index file, which is just a long text, allowing super fast repeated searches for whatever names you type.

Find text in office files on the command line.

There is a folder C:\sales with a few thousand .docx files. You want to find all bills containing PC and model number 12345 in the same line. Then type this:
   C:
cd \
sfk ofind sales "/pc*12345/"
example output:
:file sales\2017022291-George Smith.docx
Gamer PC    GC-12345   USD 795.90
:file sales\2018072443-Wilma Doe.docx
Gamer PC    GC-12345   USD 795.90
:file sales\2011061442-James Sample.docx
Gamer PC    GC-12345   USD 795.90

Search is case insensitive. The slashes "/" around the search pattern are required as the pattern can be very flexible, allowing an optional reformatting of the output. Type sfk ofind for the full syntax.

By the way, the Freeware tool Depeche View can load one hundred office files from a folder in one window, allowing super fast repeated searches for whatever you type.

Create a script for your daily backup.

You work in an office, and

• you PC has access to a network drive "O:", which is your personal drive to backup work data to.
• you do all work in a folder D:\work.
• everyday you want to save your changes from D:\work to O:\work.
• copy to the network drive is slow, and there is a size limit, so you do not want to copy large unimportant files, and junk files in general.
Go to D:\, and start by typing:
   sfk batch backup.bat
This will create a short template batch file. Open it in Notepad, and reduce it to the minimum like this:
   @echo off
sfk script "%~f0" -from begin %*
GOTO xend

sfk label begin -var

+sync work o:\work

-dir .

-subdir !\tracing !\dbdump

-file   !\tmp !.bak

%1

+end

:xend

Explanations:
• this is a CMD.EXE batch file, with an embedded SFK script file.
• the sfk script command loads it's own file "backup.bat", again, and jumps to the sfk label begin statement.
• it passes all parameters given via %*, which can be used inside the SFK script like %1 %2 %3 to %9.
• the +sync means to run sfk sync, which is similar to sfk copy, but it also deletes files in O:\work which no longer exist in D:\work.
• the sync will ignore all sub folders starting like tracing or dbdump, and all files starting tmp or ending with file extension .bak.
Now type backup. It will only show a preview of what will be copied, and what will possibly be deleted. Finally type backup -yes to really sync the files.

This batch file is an automation script. The big advantage over typing commands directly in the command line is that you can split long commands over several lines, in a text editor, making everything readable and easy extendable.

On Mac/Linux things are a bit different:

• use sfk batch backup.sh. the resulting template will be bash compatible.
• use the usual syntax adaptions required for linux,
like -subdir :/tracing :/dbdump
and -file :/tmp :.bak.

Create a script for your weekly home backup.

At home, you normally

• have a PC with drive C: and D:
• want to backup to an external USB drive like G:
and of course you do not want to backup the whole drive contents, as copying C:\Windows is completely useless (you can never copy that back without severe damage to your operating system), and it would take ages on each and every backup session.

So there must be a selection of main folders, with a possible exclusion of sub folders and unwanted files.

You cannot go to C:\ and create a batch file there, as Windows blocks this for security reasons. It is recommended to create a folder like C:\tools, CD into there, then start like:

   sfk batch backup.bat -full
The -full is important. It will create a huge backup batch template, which you can read here.

Carefully check the default filters given under -subdir and -file. Remove them in the first step, to make sure all files are backed up. Then define your own filters, step by step.

A full explanation of every script step is available in the SFK E-Book, in Chapter Backup and transfer of folders.

For Mac/Linux a similar script is available by

   sfk batch backup.sh -full
which of course does not use C: and D: drives, but just one main folder example.

You can get them on SourceForge, or directly here:

 SFK for Windows (32/64 bits) SFK for Windows (64 bits OSE) SFK for Mac OS/X (64 bits) SFK for Desktop Linux (64 bits) SFK for Embedded Linux (32 bits) Overall .zip package With source code for self compile.

If you have experience with the command line: save sfk.exe into a folder which is listed in your PATH environment variable, and you have the sfk command.

If you have no command line experience: double click on sfk.exe after download. A window will open with instructions. Press '1'. This will

• create a folder C:\tools, into which sfk.exe is copied.
• create a desktop icon sfk shell.
No administrator rights are required for this. Double click on the created sfk shell icon. This will open a command line in which you have the sfk command.

On Mac/Linux, rename the binary to just sfk after download. Type chmod +x sfk to make it executable. Extend the PATH by the folder containing sfk. Then type sfk or ./sfk for the main help.

Find all one hundred SFK functions on the Swiss File Knife homepage: