How to move or rename files in Linux

Written by stephen byron cooper Google
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to move or rename files in Linux
Linux uses the same command as Unix to move and rename files. (Linux)

The Linux operating system is based on Unix and uses most of the same commands that Unix users will be familiar with. The operating system’s commands enable the management of files in directories to create a tree structure. Files and directories can be moved, renamed, copied or deleted with a series of simple commands. Move and copy are closely related. Move creates a new name for a file, but copy creates a new name and leaves the file with its old name in place, thus creating two identical files with different names. You rename a file with the same command needed to move a file.

Skill level:
Easy

Other People Are Reading

Instructions

  1. 1

    Locate the file you want to rename or move. See a listing of the contents of the current directory by typing “dir.” If you see a directory as one of the elements in the list you can move to it by typing “cd <directory>” where <directory> represents the directory name. To move up a level to the directory that contains the current directory, type “cd ..” and press the “Enter” key. To get to the top directory of the file system type “cd /” and press the “Enter” key.

  2. 2

    Rename or move a file by typing “mv <fromfile> <tofile>” where <fromfile> represents the original name of the file and <tofile> represents the new name of the file. If the new file name you want to use for the file is already being used by a file in that directory and you want to overwrite it, use “mv -i <fromfile> <tofile>” and press the “Enter” key.

  3. 3

    Move a file to a different directory, but keep the same name by using “mv.” Type mv <file> <directory> where directory represents a directory. The directory address can be relative to current directory or an absolute address. For example “mv myfile.txt mydir” would only work if mydir is below the current directory. If mydir is in the parent directory of the current directory, you would enter “mv myfile ../mydir. An absolute address leads gthrough the entire directory structure from the top (root) directory. In this case you would type something like “mv myfile.txt /usr/stats/myproj/mydir” to move the file.

  4. 4

    Move the file to a different directory and change its name at the same time by attaching the address of the new location to the new file name. For example, “mv myfile.txt adir/newfile.txt” would move myfile.txt to the directory adir which is beneath the current directory. At the same time as moving the file, the command will rename it to newfile.txt. Again, if a file already exists in the target directory with the same name, you will have to use the “i” switch. So“mv –i myfile.txt /usr/stats/myproj/mydir/newfile.txt” would overwrite an existing newfile.txt in the mydir directory with the contents of myfile.txt and remove myfile.txt from the current directory.

  5. 5

    Move a file from another directory to the current directory by putting the directory on the front of the file name. The command “mv ../adir/myfile.txt” would move myfile.txt from an adjacent directory to the current one. The command “mv –i odir/myfile.txt” would move myfile.txt from a the odir directory which is a subdirectory of the current directory. It would overwrite any existing myfile.txt in the current directory. You can rename the file during the move by putting the new file name as a parameter to the mv command. Thus, “mv adir/myfile.txt newfile.txt” will move myfile.txt from a lower directory and rename it to newfile.txt

  6. 6

    Move files between directories other than the current one by putting the directory path for both the from and to parameter in the move command. For example: “mv ../../myfile.txt /usr/stats/myproj/mydir” would just move the file from one directory to another and “mv /usr/stats/myproj/mydir/myfile.txt ../../newfile.txt” would move it and rename it.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.