Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Key language:
command, switch, path, current directory, parent directory
Make a list of all files in your Photos folder and save it in a text document
Copy all files changed in the last week to your flash disk
Delete all files ending in ".doc"
Rename every file ending in .txt to .doc
These tasks are all possible, but with more than a few files they become time consuming and error prone. Command
line interfaces reduce these jobs to just one or two typed commands, even if operating on thousands of files at once.
You will see a blinking white cursor and the current path (the folder you are in) on the left (your path may vary slightly
depending on your version of windows). In the command line, folders and files are separated by slash characters (\).
cd c:\users\gray\desktop
To change to the directory above the current one (the parent directory), use:
cd ..
Getting information dir Use the dir command to list the contents of the current directory. You can
about files and also use it to list the contents of a different directory by specifying the full
directories path:
dir c:\photos\hungary\F1
Deleting files del Del deletes files. You can use it with individual file names or wildcards, but
be extremely careful using wildcards – you may delete more than you
imagined! (Another good reason not to run as an administrator, to limit the
damage you could do)
Creating folders mkdir mkdir name1 makes a folder called name1 in the current directory.
Move files and move To move file1 into directory2, type: move file1 directory2
directories
Redirecting output >filename You can redirect output from commands so that instead of appearing on the
screen it appears elsewhere, such as in a file. This is a very powerful option.
To redirect output, use the greater than sign. For example, to redirect the
output of the dir command to a file called listing.txt:
dir >listing.txt
The screen will stay blank but the listing.txt file will appear containing the
command's output.
Operate on multiple * The asterisk character is used to represent "Any number of characters". The
files at once ? question mark character is used to represent "Any single character". Both are
(wildcards) used to operate on multiple files at once, and can be used with any command.
For example:
Task Answer
1. Download the CLI-exercise.zip file and extract it to N/A
your desktop.
2. Open a new command prompt. Change the current
directory to the CLI-exercise directory on the desktop
3. The folder contains a few PNG images, but these are
duplicates of the JPEG images. List the png images.
4. Delete all the files with the png extension using a
single command.
5. Make a new folder called elsalvador
6. Move all the image files from the exercise folder into
the elsalvador folder
7. Inside the elsalvador folder, make one new folder
called elpital and one new folder called misc
8. Move all files that start with el-pital- to the elpital
folder
9. Move all remaining files to the misc folder
10. Oops, a couple of guatemala images have found their
way into the misc folder. They have guatemala in their
file names. Delete them.
11. Now we want a list of all files in the cli-exercise
folder and all subfolders. You should be able to do this
with a single command. (You may need to use the
help function for the dir command)
12. Test the above command first to make sure it works,
then re-direct its output to a file called filelist.txt