| Both sides previous revision
Previous revision
Next revision
|
Previous revision
|
unix_101 [2016/05/25 15:21] peek |
unix_101 [2016/05/25 15:24] (current) peek |
| |
| **CAUTION: There is NO undelete command for unix. Once a file or directory has been deleted THERE IS NO WAY to bring that file or directory back. The only way to recover a lost file or directory is to restore it from backup.** | **CAUTION: There is NO undelete command for unix. Once a file or directory has been deleted THERE IS NO WAY to bring that file or directory back. The only way to recover a lost file or directory is to restore it from backup.** |
| | |
| | ====== File Names, Directory Names, and Wildcards ====== |
| | |
| | Most of the file you will provide a list of files and/or directories for a command on the command line, one at a time and separated by a space. But what if there are too many pathnames to list one at a time? Or, conversely, what if you're just too lazy to list them? Computers were invented to be labor-saving devices, so of course there's a way to make the machine do your work for you. That's where wildcards come in. A wildcard is a special character or tag that the shell recognizes as a filter for selection criteria from a directory listing. |
| | |
| | ^ Pattern ^ Matches ^ |
| | ^ <code>*</code> | Used by itself, this will match any file or directory name. <code> |
| | $ ls -1 * |
| | Aware_-_Kontinuum.flac |
| | Glaciers-SD.mp4 |
| | log-messages.txt |
| | MendelMax_3_Full_Kit_Packing_Slip_-_Sheet1.csv |
| | README |
| | </code> | |
| | ^ <code>G*</code> | Matches any file or directory name that starts with a ''G''. <code> |
| | $ ls -1 G* |
| | Glaciers-SD.mp4 |
| | </code> | |
| | ^ <code>*.txt</code> | Matches any file or directory name that ends with ''.txt''. <code> |
| | $ ls -1 *.txt |
| | log-messages.txt |
| | </code> | |
| | ^ <code>file*.txt</code> | Matches any file or directory name that begins with ''file'' and ends with ''.txt'' | |
| | ^ <code>READ???</code> | Matches any file or directory name that starts with ''READ'', followed by exactly three more characters. | |
| | ^ <code>[abc]*</code> | Matches any name beginning with either an ''a'', a ''b'', or a ''c'', followed by any number of characters. | |
| | ^ <code>file-[0-9][0-9]</code> | Matches any name beginning with ''file-'' and followed by exactly two characters. | |
| | ^ <code>[[:upper:]]*</code> | Matches any name beginning with an upper case character, and followed by any number of characters. <code> |
| | $ ls -1 [[:upper:]]* |
| | Aware_-_Kontinuum.flac |
| | Glaciers-SD.mp4 |
| | MendelMax_3_Full_Kit_Packing_Slip_-_Sheet1.csv |
| | README |
| | </code> | |
| | ^ <code>[![:digit:]]*</code> | Matches any name not beginning with a number. | |
| | ^ <code>*[[:lower:]123]</code> | Matches any name ending with ''a''-''z'', or the numbers ''1'', ''2'', or ''3''. | |
| |
| ====== Leaving Things Running In The Background ====== | ====== Leaving Things Running In The Background ====== |
| ^ Type: | <code>$ mkdir /tmp/playground</code> | | ^ Type: | <code>$ mkdir /tmp/playground</code> | |
| ^ Type: | <code>$ find /tmp/playground | ^ Type: | <code>$ find /tmp/playground |
| /tmp/playground</code | | /tmp/playground</code> | |
| ^ Type: | <code>$ cd /tmp/playground</code> | | ^ Type: | <code>$ cd /tmp/playground</code> | |
| ^ Type: | <code>pwd | ^ Type: | <code>pwd |
| ./dir2 | ./dir2 |
| </code> | | </code> | |
| ^ Type: | <code>mv passwd fun</code> | | ^ Type: | <code>$ mv passwd fun</code> | |
| ^ Type: | <code>$ find | ^ Type: | <code>$ find |
| . | . |
| ./fun | ./fun |
| </code> | | </code> | |
| ^ Type: | <code>mv fun dir1</code> | | ^ Type: | <code>$ mv fun dir1</code> | |
| ^ Type: | <code>$ find | ^ Type: | <code>$ find |
| . | . |
| ./dir2 | ./dir2 |
| </code> | | </code> | |
| ^ Type: | <code>mv dir1 dir2</code> | | ^ Type: | <code>$ mv dir1 dir2</code> | |
| ^ Type: | <code>$ find | ^ Type: | <code>$ find |
| . | . |
| ./dir2/dir1/fun | ./dir2/dir1/fun |
| </code> | | </code> | |
| ^ Type: | <code>cd</code> | | ^ Type: | <code>$ cd</code> | |
| ^ Type: | <code>rmdir /tmp/playground | ^ Type: | <code>$ rmdir /tmp/playground |
| rmdir: failed to remove '/tmp/playground': Directory not empty | rmdir: failed to remove '/tmp/playground': Directory not empty |
| </code> | | </code> | |
| ^ Type: | <code>rm /tmp/playground/dir2/dir1/fun</code> | | ^ Type: | <code>$ rm /tmp/playground/dir2/dir1/fun</code> | |
| ^ Type: | <code>find /tmp/playground | ^ Type: | <code>$ find /tmp/playground |
| /tmp/playground | /tmp/playground |
| /tmp/playground/dir2 | /tmp/playground/dir2 |
| /tmp/playground/dir2/dir1 | /tmp/playground/dir2/dir1 |
| </code> | | </code> | |
| ^ Type: | <code>rmdir /tmp/playground/dir2/dir1</code> | | ^ Type: | <code>$ rmdir /tmp/playground/dir2/dir1</code> | |
| ^ Type: | <code>rmdir /tmp/playground/dir2</code> | | ^ Type: | <code>$ rmdir /tmp/playground/dir2</code> | |
| ^ Type: | <code>rmdir /tmp/playground</code> | | ^ Type: | <code>$ rmdir /tmp/playground</code> | |
| |