How do I copy/move a file or directory?

Handling files in DOS is very similar to Linux/UNIX.  They
are only different syntactically.  In DOS you have the ‘dir’
(directory) command where in Linux you have ‘ls’ (list).  DOS used
‘copy’ where *NIX’s have always used ‘cp’.  In DOS you can use
‘rename’ to change the name of a file where in Linux/UNIX it’s been
‘mv’ (move).  We’ll use these to move files and directories
around.



Let’s assume we have a directory with several files and several
directories.   We can list their attributes with the ‘ls -l’
command:


[tschuh@lvs ~/flern]$ ls -l
total 4336
drwxrwxr-x 2 tschuh tschuh 4096 Nov 8 14:51 directory1
drwxrwxr-x 2 tschuh tschuh 4096 Nov 8 14:51 directory2
drwxrwxr-x 2 tschuh tschuh 4096 Nov 8 14:51 directory3
-rw-rw-r-- 1 tschuh tschuh 62976 Nov 8 14:50 file1
-rw-rw-r-- 1 tschuh tschuh 406528 Nov 8 14:50 file2
-rw-rw-r-- 1 tschuh tschuh 3938304 Nov 8 14:50 file3

Now let’s move file1 into directory1:




[tschuh@lvs ~/flern]$ mv file1 directory1
[tschuh@lvs ~/flern]$ ls -l directory1
total 68
-rw-rw-r-- 1 tschuh tschuh 62976 Nov 8 14:50 file1




Now let’s assume we goofed and need to rename file2 to
newfile_1.  This is where it can get confusing.  As far as
UNIX is concerned, moving a file into a directory is no different the
changing the name of the file to something else.



[tschuh@lvs ~/flern]$ mv file2 newfile_2

[tschuh@lvs ~/flern]$ ls -l
total 4268
drwxrwxr-x 2 tschuh tschuh 4096 Nov 8 14:56 directory1
drwxrwxr-x 2 tschuh tschuh 4096 Nov 8 14:51 directory2
drwxrwxr-x 2 tschuh tschuh 4096 Nov 8 14:51 directory3
-rw-rw-r-- 1 tschuh tschuh 3938304 Nov 8 14:50 file3
-rw-rw-r-- 1 tschuh tschuh 406528 Nov 8 14:50 newfile_2

[tschuh@lvs ~/flern]$ mv newfile_2 directory2

[tschuh@lvs ~/flern]$ ls -l directory2/
total 404
-rw-rw-r-- 1 tschuh tschuh 406528 Nov 8 14:50 newfile_2

And the same works for directories.



[tschuh@lvs ~/flern]$ mv directory2 directory1

[tschuh@lvs ~/flern]$ ls -l directory1
total 72
drwxrwxr-x 2 tschuh tschuh 4096 Nov 8 15:04 directory2
-rw-rw-r-- 1 tschuh tschuh 62976 Nov 8 14:50 file1

And lastly, copying a file from one location to the next:


[tschuh@lvs ~/flern]$ ls -l
total 3860
drwxrwxr-x 3 tschuh tschuh 4096 Nov 8 15:05 directory1
drwxrwxr-x 2 tschuh tschuh 4096 Nov 8 14:51 directory3
-rw-rw-r-- 1 tschuh tschuh 3938304 Nov 8 14:50 file3
[tschuh@lvs ~/flern]$ cp file3 directory3
[tschuh@lvs ~/flern]$ ls -l
total 3860
drwxrwxr-x 3 tschuh tschuh 4096 Nov 8 15:05 directory1
drwxrwxr-x 2 tschuh tschuh 4096 Nov 8 15:06 directory3
-rw-rw-r-- 1 tschuh tschuh 3938304 Nov 8 14:50 file3
[tschuh@lvs ~/flern]$ ls -l directory3
total 3852
-rw-rw-r-- 1 tschuh tschuh 3938304 Nov 8 15:06 file3
Your rating: None