Page 195 - DCAP602_NETWORK_OPERATING_SYSTEMS_I
P. 195
Unit 10: File System
Using wildcards, it is possible to construct very sophisticated selection criteria for filenames. notes
Here are some examples of patterns and what they match:
Examples of wildcard matching.
pattern matches
* All filenames
G* All filenames that begin with the character “g”
B*.txt All filenames that begin with the character “b” and end with the characters “.txt”
Data??? Any filename that begins with the characters “Data” followed by exactly 3 more
characters
[abc]* Any filename that begins with “a” or “b” or “c” followed by any other characters
[A-Z]* Any filename that begins with an uppercase letter. This is an example of a range.
BACKUP. Another example of ranges. This pattern matches any filename that begins with the
[0-9][0-9][0-9] characters “BACKUP.” followed by exactly 3 numerals.
[!a-z]* Any filename that does not begin with a lowercase letter.
You can use wildcards with any command that accepts filename arguments.
cp
The cp program copies files and directories. In it’s simplest form, it copies a single file:
$ cp file1 file2
It can also be used to copy multiple files to a different directory:
$ cp file1 file2 file3 directory
Other useful examples of cp and its options include:
Examples of the cp command
command results
cp file1 file2 Copies the contents of file1 into file2. If file2 does not exist, it is created, otherwise, file2
is overwritten with the contents of file1.
cp -i file1 file2 Like above however, since the “-i” (interactive) option is specified, if file2 exists, the
user is prompted before it is overwritten with the contents of file1.
cp file1 dir1 Copy the contents of file1 (into a file named file1) inside of directory dir1.
cp –R dir1 dir2 Copy the contents of the directory dir1. If directory dir2 does not exist, it is created.
Otherwise, it creates a directory named dir1 within directory dir2.
mv
The mv command performs two different functions depending on how it is used. It will either
move one or more files to a different directory, or it will rename a file or directory. To rename a
file, it is used like this:
$ mv filename1 filename2
To move files to a different directory:
$ mv file1 file2 file3 directory
LoveLy professionaL university 189