In: Computer Science
Research Managing Files via the Command Line Interface
(CLI)
commands, flags, and options that allow you to:
copy, delete, rename, and move files on Windows and Linux.
For Window ->
Copy file->
step-1 press window + r
step-2 type cmd and press enter
step-3 cmd will be open
step-4 At the prompt, type copy c:\workfile.txt d: and press Enter to copy the file named “workfile.txt” on the root of C drive to D drive root.
Delete file ->
step-1 press window + r
step-2 type cmd and press enter
step-3 cmd will be open
step-4 write "del" before you file name which you want to delete and press enter
example (
del myfile.txt
)
Rename file ->
step-1 press window + r
step-2 type cmd and press enter
step-3 cmd will be open
step-4 syntax (
rename file_path new_name
)
example(
rename d:\data\file1.doc file2.doc
)
Move file->
step-1 press window + r
step-2 type cmd and press enter
step-3 cmd will be open
step-4 you can move files using the move command. For example, if you want to move a file named "stats.doc" to the "c:\statistics" folder, you would type the following command, then press the Enter key.
move stats.doc c:\statistics
For LInux->
copy file->
The command used is cp. The cp command requires two attributes. One, the location of the file that you want to copy, and next, the location where you want to copy. Now here, I will copy a file named test3 to the directory testdir.
cp test3 testdir (simple file copying)
As seen in the output, the file has been copied, and the ls command proves that it’s in the testdir directory. Now again an important option:
cp -r
Yes, the function of the -r is the same here. It copies the files
in a directory recursively. If you use plain cp to copy a directory
that has files, the cp command will simply omit the directory and
move on. So, a -r option is necessary to copy a folder.
cp -r testdir2 testdir (copynig directory)
Delete file->
simple delete a file by using rm "file name"
rm file_1.txt
If the file is not in the current working directory, provide a path to the file’s location
rm ./path/to/the/file/file_1.txt
You can pass more than one filename to rm
. Doing so
deletes all of the specified files
rm file_2.txt file_3.txt
Rename file->
To use mv
to rename a file type mv
, a
space, the name of the file, a space, and the new name you wish the
file to have. Then press Enter.
You can use ls
to check the file has been
renamed.
mv oldfile.txt newfile.txt
ls *.txt
Move file->
In Linux, using the command shell, you can move files or directories with the mv command. For example, if you wanted to move a file named "myfile.txt" to the folder named "backup," you would type the following command.
mv myfile.txt backup