Tag Archives: File

Copying a File with cp

To copy a file named testfile from ~/Documents to ~/Downloads, use this command:

To copy a file that is in your current directory, you could use the following, and it will work exactly the same as mv, except that both files will exist afterward:

To rename a file as you copy it form ~/Documents to ~/Downloads, you could use this:

Or from anywhere using an absolute path, you could use the following command:

Or from anywhere using a path shortcut, you could use this:

Moving or Renaming a File with mv

Moving and renaming a file are the same thing. It doesn’t matter whether you are moving the directory to another or from one filename to another filename in the same directory; there is only one command to remember. To move a file named testfile from ~/Documents to~/Downloads, use this command:

If the destination is not exist, the testfile will be rename to destination name.

Assuming that you are the user hadi, to rename a file that is in your current directory, you could use the following:

To rename a file as you move it fomr ~/Documents to ~/Downloads, you could use this:

Or from anywhere using an absolute path, you could use the following command:

Or from anywhere using a path shortcut, you could use this:

Creating a Linux File with Touch

To create an empty file called testfile within your current directory, use the following command:

To edit this file, you must use a text editor.

You can create a file in a different location by changing what is after touch. To create a new file in /home/hadi/testdirectory, if you are already in your home directory, you can use the following:

Of from anywhere using an absolute path, you can use this:

Or from anywhere using a path shortcut, you can use the following command: