|
||||
mark@platypus:~> mkdir unix_class mark@platypus:~> ls -ld unix_class/ drwxrwxr-x 2 mark users 48 2005-02-02 14:57 unix_class/ mark@platypus:~> |
More than one directory can be created at a time using both
absolute and relative paths:
|
||||
mark@platypus:~> mkdir unix_class ./lab06 /home/mark/lab07 mark@platypus:~> ls -ld unix_class ./lab06 /home/mark/lab07 drwxrwxr-x 2 mark users 48 2005-02-02 15:01 ./lab06 drwxrwxr-x 2 mark users 48 2005-02-02 15:01 /home/mark/lab07 drwxrwxr-x 2 mark users 48 2005-02-02 15:01 unix_class mark@platypus:~> |
cp original_file destination_fileThe source and target files may be referenced with relative or absolute paths. An example of copying a single file in the same directory:
|
||||
mark@platypus:~> ls -l birddog.jpg -rw-r--r-- 1 mark users 36423 2004-11-04 18:26 birddog.jpg mark@platypus:~> cp birddog.jpg new_pic.jpg mark@platypus:~> ls -l new_pic.jpg -rw-r--r-- 1 mark users 36423 2005-02-02 15:11 new_pic.jpg mark@platypus:~> |
Copying a file to another directory. The original name of the
file is retained.
|
||||
tuckerm@platypus:~> ls -l ./web/term3.png -rw-r--r-- 1 tuckerm tuckerm 984 Dec 5 2003 ./web/term3.png tuckerm@platypus:~> cp ./web/term3.png /mnt/homes/CLASSES/MET489/lab06/ tuckerm@platypus:~> ls -l /mnt/homes/CLASSES/MET489/lab06/term3.png -rw-r--r-- 1 tuckerm tuckerm 984 Feb 2 15:14 /mnt/homes/CLASSES/MET489/lab06/term3.png tuckerm@platypus:~> |
To copy a file from another location to the current directory:
|
||||
tuckerm@platypus:~> ls -l /mnt/homes/CLASSES/MET489/lab06/term3.png -rw-r--r-- 1 tuckerm tuckerm 984 Feb 2 15:14 /mnt/homes/CLASSES/MET489/lab06/term3.png tuckerm@platypus:~> cp /mnt/homes/CLASSES/MET489/lab06/term3.png . tuckerm@platypus:~> ls -l ./term3.png -rw-r--r-- 1 tuckerm tuckerm 984 Feb 2 15:18 ./term3.png tuckerm@platypus:~> |
cp can also copy a directory and all of its contents by using the
"-r" option. This will retain the same structure for
files and subdirectories within the copied directory:
|
||||
tuckerm@platypus:~> ls ./web/ gimp_acquire.png term2.png xsane_device_scan.png xsane_view.png gimp_start.png term3.png xsane_preview.png sane.html term_fill.png xsane_save.png term1.png xsane_begin.png xsane_select.png tuckerm@platypus:~> cp -r ./web /mnt/homes/CLASSES/MET489/lab06/new_web tuckerm@platypus:~> ls /mnt/homes/CLASSES/MET489/lab06/new_web/ gimp_acquire.png term2.png xsane_device_scan.png xsane_view.png gimp_start.png term3.png xsane_preview.png sane.html term_fill.png xsane_save.png term1.png xsane_begin.png xsane_select.png tuckerm@platypus:~> |
There are several options for the cp command which will modify its behavior such as preserving the date/time of the newly created files. See the man pages for more information.
mv source_file destination_fileSource file is the current name of the file which is to be moved or renamed and destination_file is the name or path where the source_file is to be moved to.
An example of renaming a file with mv:
|
||||
tuckerm@platypus:~> ls -l newfile -rw-rw-r-- 1 tuckerm tuckerm 775 Feb 2 20:20 newfile tuckerm@platypus:~> mv newfile oldfile tuckerm@platypus:~> ls -l oldfile -rw-rw-r-- 1 tuckerm tuckerm 775 Feb 2 20:20 oldfile tuckerm@platypus:~> |
An example of moving a file to another location with mv:
|
||||
tuckerm@platypus:~> ls -l oldfile -rw-rw-r-- 1 tuckerm tuckerm 775 Feb 2 20:20 oldfile tuckerm@platypus:~> mv oldfile test/movedfile tuckerm@platypus:~> ls -l oldfile /bin/ls: oldfile: No such file or directory tuckerm@platypus:~> ls -l ./test/movedfile -rw-rw-r-- 1 tuckerm tuckerm 775 Feb 2 20:20 ./test/movedfile tuckerm@platypus:~> |
Moving a file to a new directory without renaming:
|
||||
tuckerm@platypus:~> ls -l ./test/movedfile -rw-rw-r-- 1 tuckerm tuckerm 775 Feb 2 20:20 ./test/movedfile tuckerm@platypus:~> mv ./test/movedfile . tuckerm@platypus:~> ls -l movedfile -rw-rw-r-- 1 tuckerm tuckerm 775 Feb 2 20:20 movedfile tuckerm@platypus:~> |
|
||||
tuckerm@platypus:~> rm movedfile rm: remove regular file `movedfile'? y tuckerm@platypus:~> |
The "-r" option will tell rm to remove all files and directories specified, including any and all subdirectories found in the directories listed. An example of rm with the recursive option:
|
||||
tuckerm@platypus:~> rm -r test rm: descend into directory `test'? y rm: descend into directory `test/test2'? y rm: remove regular file `test/test2/start-vnc.sh'? y rm: remove directory `test/test2'? y rm: remove regular file `test/coltbl.xwp'? y rm: remove directory `test'? y tuckerm@platypus:~> ls -ld test /bin/ls: test: No such file or directory tuckerm@platypus:~> |
rm with the "-f" flag will force rm to delete the file(s) specified. This will override the "-i" option. It will also force deletion as the owner of a file, even if the file permissions do not allow write access.
An example of removing a file without read permissions:
|
||||
tuckerm@platypus:~> ls -l somefile -rw-rw-r-- 1 tuckerm tuckerm 775 Feb 2 20:30 somefile tuckerm@platypus:~> rm somefile rm: remove write-protected regular file `somefile'? y tuckerm@platypus:~> |
An example of forcing the removal of a file with the same
permissions:
|
||||
tuckerm@platypus:~> rm -f somefile tuckerm@platypus:~> |
|
||||
tuckerm@platypus:~> ls -ld somedir/ drwxrwxr-x 2 tuckerm tuckerm 48 Feb 2 20:43 somedir// tuckerm@platypus:~> rmdir somedir/ tuckerm@platypus:~> ls -ld somedir/ /bin/ls: somedir/: No such file or directory tuckerm@platypus:~> |
ls
command:
Wildcard matching the beginning of a file name:
|
||||
tuckerm@platypus:/mnt/data/gempak/hds/eta> ls *eta215.gem 2005012918_eta215.gem 2005013106_eta215.gem 2005020118_eta215.gem 2005013000_eta215.gem 2005013112_eta215.gem 2005020200_eta215.gem 2005013006_eta215.gem 2005013118_eta215.gem 2005020206_eta215.gem 2005013012_eta215.gem 2005020100_eta215.gem 2005020212_eta215.gem 2005013018_eta215.gem 2005020106_eta215.gem 2005020218_eta215.gem 2005013100_eta215.gem 2005020112_eta215.gem tuckerm@platypus:/mnt/data/gempak/hds/eta> |
Using the wildcard to match the ending of a file name:
|
||||
tuckerm@platypus:/mnt/data/xcd> ls ZZ04* ZZ04187.IDX ZZ04188.IDX ZZ04322.IDX ZZ04323.IDX ZZ04324.IDX tuckerm@platypus:/mnt/data/xcd> |
The wildcard can be used in the middle of a string as well as at
the beginning or the end:
|
||||
tuckerm@platypus:/mnt/data/gempak/hds/eta> ls 20050202*215.gem 2005020200_eta215.gem 2005020212_eta215.gem 2005020206_eta215.gem 2005020218_eta215.gem tuckerm@platypus:/mnt/data/gempak/hds/eta> |
Please also visit this unix wildcards>unix wildcards website to see the other two types of wildcards, question marks and brackets.