13. Last but not least: tips and tricks

Last but not least: in the next chapters, I'll give you some useful tips and tricks.

13.1 Make file(s) read-only

To set the file attribute to read-only (as the name suggests: the file can be read from, but not written to), use the command 'ATTRIB':
D:	est>ATTRIB +r "my Doc"\doc2.rtf [ENTER]
Notice the parameter '+r' (plus sign). Of course, with Glob patterns you can easily change more than one file. In the next example all files with the extension '.rtf' in subdirectory 'my Doc' are made read-only::
D:\test>ATTRIB +r "my Doc"\*.rtf [ENTER]

13.2 Remove files read-only attribute

To remove the read-only attribute of files, use the command 'ATTRIB' with parameter '-r' (minus sign) :
D:\test>ATTRIB -r "my Doc"\*.rtf [ENTER]

13.3 Show read-only files

Use the 'DIR' command with the switch '/A:R' to show read-only files:
D:\test>DIR /A:R [ENTER]

13.4 (un)Hiding a file

To hide a file in the subdirectory 'my Doc' with the command 'ATTRIB' and parameter '+h' (plus sign):
D:\test>ATTRIB +h "my Doc"ile1.txt [ENTER]
To unhide a file:
D:\test>ATTRIB -h "my Doc"ile1.txt [ENTER]
So 'ATTRIB' and parameter '-h' (minus sign)

Delete all hidden files (is this really a clever action? Never use this unless you are sure what you do!):
DEL /A:H "my Doc"\*.txt [ENTER]
You can also hide a directory with the ATTRIB command!

13.5 Secure file deletion

In Linux, I use the 'shred' command to delete files permanently. Via the Windows Command Line you can also do some secure file deletion: first you turn an existing file into a zero-byte file, second you delete the file via the 'DEL'-command and third you run 'CIPHER'-command:
D:\test>TYPE nul >file1.txt && DEL file1.txt [ENTER]
(Use the 'FOR' command to delete more than one file).

After deleting your files, you run 'CIPHER' command that will overwrite deleted files, i.e. free disk space, maybe freeing up some extra disk space.
D:\test>CIPHER /w:D:\test [ENTER]
In one command line:
D:\test>TYPE nul >file1.txt && DEL file1.txt && CIPHER /w:D:\test [ENTER]
An alternative is the command line tool SDelete: https://technet.microsoft.com/en-us/sysinternals/bb897443

Tip: run
D:\test>CIPHER /? [ENTER]
for lots of information on the CIPHER command!

13.6 Copy from the Windows Command Prompt to the Clipboard

If you enable QuickEdit Mode, you can copy text from the Windows Command Prompt and paste it in a document (Notepad++). To enable Quickedit Mode,

a. do a right-mouse click on the title bar: a dialog pops up
b. select Properties
c. check the 'QuickEdit Mode' box
d. close the dialog

Select some text by dragging a box around your text and do a right-mouse click (or press Enter): the text is copied to the Clipboard. With e.g. CTRL+V you can paste the text into e.g. NotePad++.

13.7 Copy output command to the Clipboard

To copy the output of a command to the Clipboard, type:
D:\test>DIR | CLIP [ENTER]
(notice that this will not work on XP)

13.8 Save output command to a file

For your convenience, here the command again to save the output of a command into a file using the redirection operator >
D:\test>DIR > result.txt [ENTER]

13.9 TASKLIST and TASKKILL

To end one or more processes by the command 'TASKKILL', you need a process id (PID) or a so called 'imagename'. To get this information, you have to run 'TASKLIST'. Example: start notepad and type:
D:\test>TASKLIST [ENTER]
In my case, the notepad.exe (notice the column name: 'imagename') has process id 4324. You can end this process in two ways. The first way is with the switch /IM and 'imagename' as command parameter:
D:\test>TASKKILL /IM notepad.exe [ENTER]
The second way has the switch '/PID' and the process id as parameter:
D:\test>TASKKILL /PID 4324 [ENTER]
In both cases, multiple processes can be killed. In case of '/IM' you can use Glob patterns.

The command
D:\test>TASKLIST | FIND "cmd" [ENTER]
displays the PID of your CMD-window in the second column.

Notice that home editions of Windows do not have 'TASKKILL'. You should use 'TSKILL' instead.

13.10 Use functions keys

The most popular function keys in the Windows Command Line window for me are:

F3: it pastes the last command (see also the explanation of F8)
F7: it shows a list of previous commands: select a command and press Enter in order to run the selected command.
F8: press F8 one or more times for pasting commands from your command history; this can also be done by up and down arrow keys.