2.2 File Manipulation Commands
The Copy (cp), Move (mv) and Remove (rm) commands are used to duplicate
the physical storage of a file(s), rename and/or relocate a file(s), and
to delete a file(s).
cp(1) - copy files and directory subtrees
mv(1) - move or rename files and directories
rm(1) - remove files or directories
mkdir (1) - make a directory
rm, rmdir (1) - remove (unlink) files or directories
There are two forms for the cp and mv commands:
cp "source file" "target file" cp "source files" "target directory"
mv "source file" "target file" mv "source files" "target directory"
Note: Note:
exactly 2 arguments, target file at least 2 arguments, target directory
should not exist. must exist. Same names in target directory
The rm command deletes a pointer to the physical storage of an existing file
rm file # delete file
rm -i file # babysit [This is the default flavor on Linux-RK]
rm -f file # force silently
rm -r directory # delete directory and its contents
The mkdir command creates an empty directory. Create one and look at its
attributes. What is the byte size? What happens when you create a file
in it? Does the Byte size change? What if you remove the newly created
file - Does the Byte size decrease?
The rmdir command deletes an empty directory. It will complain if it isn't.
Not so for rm -r
$ # Try these commands by modifying them appropriately on your own systems
$ cp /usr/davis/time.sheet davis.time or $ cd /usr/davis
$ cp time.sheet /usr/ashley
$ cp my.time /usr/davis/ashley.time $ cd /usr/davis
$ cp /usr/ashley/my.time ashley.time
$ mv my.time /usr/davis/ashley.timeout $ cd /usr/davis
$ mv /usr/ashley/my.time ashley.timeout
$ rm /usr/davis/ashley.timeout $ cd /usr/davis
$ rm ashley.timeout
$ cp filea fileb filec filed subdir # Copying many files to subdir (same name)
$ mv filea fileb filec subdir # relocating many files to subdir (same name)
$ pwd
/usr/carson
$ mkdir research/newyork
$ cd projects/potential
$ cp ny.articles archive.1900 ../../research/newyork
$ rm ny.articles archive.1900
$ cd ..
$ pwd
/usr/carson/projects
$ rmdir potential
Questions? Robert Katz: rkatz@ned.highline.edu
Last Update June 17, 2003