Wildcards
Wildcard | Meaning |
* |
Matches any characters |
? |
Matches any single character |
[characters] |
Matches any character that is a member of the set characters |
[!characters] |
Matches any character that is not a member of the set characters |
[[:class:]] |
Matches any character that is a member of the specified class |
Commonly Used Character Classes
Character Class | Meaning |
[:alnum:] |
Matches any alphanumeric character |
[:alpha:] |
Matches any alphabetic character |
[:digit:] |
Matches any numeral |
[:lower:] |
Matches any lowercase letter |
[:upper:] |
Matches any uppercase letter |
Wildcard Examples
Pattern | Matches |
* |
All files |
g* |
All file beginning with "g" |
b*.txt |
Any file beginning with "b" followed by any characters and ending with ".txt" |
Data??? |
Any file beginning with "Data" followed by exactly three characters |
[abc]* |
Any file beginning with either an "a", a "b", or a "c" |
BACKUP.[0-9][0-9][0-9] |
Any file beginning with "BACKUP." followed by exactly three numerals |
[[:upper:]]* |
Any file beginning with an uppercase letter |
[![:digit:]]* |
Any file not beginning with a numeral |
*[[:lower:]123] |
Any file ending with a lowercase letter or the numerals "1", "2", or "3" |
cp-Copy files and directories
cp Options
Option | Meaning |
-a, --archive |
Copy the files and directories and all of their attributes, including ownerships and permissions. Normally, copies take on the default attributes of the user performing the copy |
-i, --interactive |
Before overwriting an existing file, prompt the user for confirmation. If this option is not specified, cp will silently overwrite files. |
-r, --recursive |
Recursively copy directories and their contents. This option (or the -a option) is required when copying directories. |
-u, --update |
When copying files from one directory to another, only copy files that either don't exist, or are newer than the existing corresponding files, in the destination directory. |
-v, --verbose |
Display informative messages as the copy is performed. |
cp Examples
Command | Results |
cp file1 file2 |
Copy file1 to file2. If file2 exists, it is overwritten with the contents of file1. If file2 does not exist, it is created. |
cp -i file1 file2 |
Same as above, except that if file2 exists, the user is prompted before it is overwritten. |
cp file1 file2 dir1 |
Copy file1 and file2 into directory dir1. dir1 must already exist. |
cp dir1/* dir2 |
Using a wildcard, all the files in dir1 are copied into dir2. dir2 must already exist. |
cp -r dir1 dir2 |
Copy the contents of directory dir1 to directory dir2. If directory dir2 does not exist, it is created and, after the copy, will contain the same contents as directory dir1. If directory dir2 does exist, then directory dir1 (and its contents) will be copied into dir2. |
mv-Move/rename files and directories
mv options
Option | Meaning |
-i --interactive |
Before overwriting an existing file, prompt the user for confirmation. If this option is not specified, mv command will silently overwrite files |
-u --update |
When moving files from one directory to another, only move files that either don't exist, or are newer than the existing corresponding files in the destination directory. |
-v --verbose |
Display informative messages as the move is performed. |
mv Examples
mv file1 file2 |
Move file1 to file2. If file2 exists, it is overwritten with the contents of files. If file2 does not exist, it is created. In either case, file1 ceases to exist. |
mv -i file1 file2 |
Same as above, except that if file2 exists, the user is prompted before it is overwritten. |
mv file1 file2 dir1 |
Move file1 and file2 into dirctory dir1. dir1 must already exist. |
mv dir1 dir2 |
if directory dir2 does not exist, create directory dir2 and move the contents of directory dir1 into dir2 and delete directory dir1. if directory dir2 does exist, move directory dir1 (and its contents) into directory dir2. |
mkdir-Create directories
rm Options
Option | Meaning |
-i, --interactive |
Before deleting an existing file, prompt the user for confirmation. If this option is not specified, rm will silently delete files. |
-r, --recursive |
Recursively delete directories. This means that if a directory being deleted has subdirectories, delete them too. To delete a directory, this option must be specified. |
-f, --force |
Ignore nonexistent files and do not prompt. This overrides the --interactive option. |
-v, --verbose |
Display informative messages as the deletion is performed. |
rm Examples
Command | Results |
rm file1 |
Delete file1 silently |
rm -i file1 |
Same as above, except that the user is prompted for confirmation before the deletion is performed. |
rm -r file1 dir1 |
Delete file1 and dir1 and its contents. |
rm -rf file1 dir1 |
Same as above, except that if either file1 or dir1 do not exist, rm will continue silently. |
rm-Remove files and directories
ln-Create hard and symbolic links