Move using.system to the top of file net năm 2024

Now, you might want to move around or copy content that you've created. There are a series of commands that will allow you to do this.

Move content

Let's say you've accidentally created a file in the wrong place, like putting your biology research spreadsheet in your art history folder. 😖

If you use a visual interface like Finder (or another visual interface), you would have to click and drag this file into its correct location. In Terminal, you don't have a visual interface, so you'll have to know the

mv research-findings.csv ../Biology

5 command to do this!

mv research-findings.csv ../Biology

5 , of course stands for move. The

mv research-findings.csv ../Biology

5 command requires several pieces of information.

  • the original file we want to move.
  • the new destination for the original file.

My first piece of information is therefore

mv research-findings.csv ../Biology

8 , and my second piece of information is therefore the file path to the Biology folder.

Absolute and relative file paths

I could type this in two different ways. Let's explore the difference between absolute and relative file paths.

Option 1 (absolute path):

mv research-findings.csv ~/Desktop/Second\ Semester/Biology

Option 2 (relative path):

mv research-findings.csv ../Biology

Option 1 contains the absolute path towards the Biology folder. Each folder is listed in the path from top to bottom.

Option 2 is a relative path . It is the path relative to where we are now.

mv research-findings.csv ../Biology

9 indicates "move up one level" (to "Second semester"), and from there, move into the Biology folder.

Rename content using mv

You can also rename files and folders using the mv command. To rename

mv research-findings.csv ../Biology

8 to

mv research-findings.csv biology-final-report.csv

1 , you could run:

mv research-findings.csv biology-final-report.csv

Technically, you're "moving" the one file to another and renaming it in the process. 👍

Move using.system to the top of file net năm 2024
Move command

Copying files

Copying content works similarly to moving content. Let's start with copying a file because it's simpler.

The same arguments are true for

mv research-findings.csv biology-final-report.csv

2 (copy) as for

mv research-findings.csv ../Biology

5 (move):

  • The first argument is the original file we want to move.
  • The second argument is the new destination for the copy of the original file.

Let's run through an exercise to put together a few different things we've worked on.

Scenario: you want to copy the final coursework from your second semester folder to a new folder called "Final papers". You don't want to move the files; just copy them to a different folder so you can have copies of your final papers in one centralized place.

From within "Second semester" folder, make a directory to contain the end of semester work.

mkdir Final\ papers

Now, you can either change directories (

mv research-findings.csv ../Biology

  1. into the Art history folder and copy the final paper from there, or just copy it without changing directories.

cd Art\ history

cp term-paper.text ../Final\ papers

or

cp Art\ history/term-paper.txt Final\ papers

Now change directories (

mv research-findings.csv ../Biology

  1. into the Final papers folder and list its contents (

mv research-findings.csv ../Biology

  1. to confirm the file is now copied here:

cd Final\ papers

ls

Brilliant!

Move using.system to the top of file net năm 2024
Copy command

Optional study: copying folders

Copying folders is more tricky. You will need to use something called an option. Options exist for many terminal commands. They are a way for you to tell the computer that a command should run in a specific, non-default way.

To copy folders, you'll use the recursive option. Recursive is similar to iteration, in that the command will run in small increments in order to achieve its final goal. This is not worth worrying about right now, though you can read more about recursiveness here.

For this example, we'll hop back to our code project. I want to duplicate my code folder in order to use the code I've written as a base for another project. The original directory is called code-project, so I'll name my copy

mv research-findings.csv biology-final-report.csv

7.

To copy this folder from one place to another, you'll run:

cp -R /Desktop/code-project /Desktop/code-project-2

This copied my code-project folder (including its contents) into a new folder called

mv research-findings.csv biology-final-report.csv

7. The

mv research-findings.csv biology-final-report.csv

9 is an option that specifies you want the command to run with recursion.

Now you can move and copy files and folders. Nice! In the next chapter, you'll see how to search for content among all the folders and files you've created in this course so far.

What is the shortcut key to move a file?

Select the file you want to move by clicking on it once. Right-click and pick Cut, or press Ctrl + X . Navigate to another folder, where you want to move the file. Click the menu button in the toolbar and pick Paste to finish moving the file, or press Ctrl + V .

What is a problem that can be solved using the move method of the file class?

Move(String, String, Boolean) Moves a specified file to a new location, providing the options to specify a new file name and to replace the destination file if it already exists.

How do I move a folder up and down?

Use Click and Drag to Move Folders and Files If both the folder or file you want to move, and the folder you want to move it to are visible, use the click and drag method to move it. Click and drag a folder or file to another folder in File Explorer.

How do you move files properly?

Select the item you want to move by holding down the right-mouse button (or the alternate mouse button if you're using the mouse with your left hand). Drag to the destination folder and release the mouse button.