6 | | THIS PAGE IS UNDER CONSTRUCTION |
| 6 | === man === |
| 7 | Display online manual pages. Most Linux commands have a manual page with detailed instructions on use. Replace '''<command name>''' below with command you would like information on. |
| 8 | |
| 9 | {{{ |
| 10 | [tulaneID@cypress1 ~]$ man <command name> |
| 11 | }}} |
| 12 | === pwd and cd === |
| 13 | The '''pwd''' command lists the present working directory. The '''cd''' command changes directory. |
| 14 | {{{ |
| 15 | [tulaneID@cypress1 ~]$ pwd |
| 16 | /home/tulaneID |
| 17 | [tulaneID@cypress1 ~]$ cd NextDirectoryUp |
| 18 | [tulaneID@cypress1 ~]$ pwd |
| 19 | /home/tulaneID/NextDirectoryUp |
| 20 | }}} |
| 21 | === ls === |
| 22 | List files. |
| 23 | {{{ |
| 24 | [tulaneID@cypress1 ~]$ ls |
| 25 | a.out code.c Makefile |
| 26 | }}} |
| 27 | |
| 28 | Setting the ''-l'' flag will display files along with their permissions and ownership. |
| 29 | {{{ |
| 30 | [tulaneID@cypress1 ~]$ ls -l |
| 31 | total 0 |
| 32 | -rw-r--r-- 1 tulaneID MyGroup 0 Aug 14 10:57 a.out |
| 33 | -rw-r--r-- 1 tulaneID MyGroup 0 Aug 14 10:57 code.c |
| 34 | -rw-r--r-- 1 tulaneID MyGroup 0 Aug 14 10:57 Makefile |
| 35 | }}} |
| 36 | |
| 37 | === mkdir === |
| 38 | Create new directory. |
| 39 | {{{ |
| 40 | [tulaneID@cypress1 ~]$ cd testdir |
| 41 | -bash: cd: testdir: No such file or directory |
| 42 | [tulaneID@cypress1 ~]$ mkdir testdir |
| 43 | [tulaneID@cypress1 ~]$ cd testdir |
| 44 | [tulaneID@cypress1 ~]$ pwd |
| 45 | /u00/user/testdir |
| 46 | }}} |
| 47 | === rm === |
| 48 | Remove files and directories. CAUTION: THERE IS NO UNDOING THIS COMMAND. |
| 49 | {{{ |
| 50 | [tulaneID@cypress1 ~]$ rm testfile |
| 51 | }}} |
| 52 | If you would like to remove a directory and all of its contents use the following command: |
| 53 | {{{ |
| 54 | [tulaneID@cypress1 ~]$ rm -ri testdir |
| 55 | rm: descend into directory `testdir'? y |
| 56 | rm: remove regular empty file `testdir/Makefile'? y |
| 57 | rm: remove regular empty file `testdir/code.c'? y |
| 58 | rm: remove regular empty file `testdir/a.out'? y |
| 59 | rm: remove directory `testdir'? y |
| 60 | [tulaneID@cypress1 ~]$ |
| 61 | }}} |
| 62 | The ''r'' flag specifies to remove files/directories recursively. ''i'' specifies to prompt before deleting each file. |
| 63 | |
| 64 | If you are confident with the command line and your understanding of file locations you can use the ''f'' flag instead of ''i'' to force deletion of all files without prompting: |
| 65 | {{ |
| 66 | [tulaneID@cypress1 ~]$ rm -rf testdir |
| 67 | [tulaneID@cypress1 ~]$ ls testdir |
| 68 | ls: cannot access testdir: No such file or directory |
| 69 | }} |
| 70 | |
| 71 | === cp === |
| 72 | Copy file to new location. |
| 73 | |
| 74 | In the example below file1 already exists, and file2 will become the copy. |
| 75 | |
| 76 | [tulaneID@cypress1 ~]$ cp file1 file2 |
| 77 | To copy a directory and all of its contents: |
| 78 | |
| 79 | [tulaneID@cypress1 ~]$ cp -r dir1 dir2 |
| 80 | mv |
| 81 | Move a file to a new location. |
| 82 | |
| 83 | [tulaneID@cypress1 ~]$ mv file1 file2 |
| 84 | [tulaneID@cypress1 ~]$ ls file1 |
| 85 | ls: cannot access file1: No such file or directory |
| 86 | [tulaneID@cypress1 ~]$ ls file2 |
| 87 | file2 |
| 88 | Unlike cp, the mv command does not create a second instance of the file or directory. |
| 89 | |
| 90 | quota |
| 91 | Display disk quotas. |
| 92 | |
| 93 | The -s flag translates the output into a readable format. If your blocks column is equal to or greater than the quota column, you have exceeded your available disk space. |
| 94 | |
| 95 | user@sphynx>quota -s |
| 96 | Disk quotas for user wcurry (uid 65098): |
| 97 | Filesystem blocks quota limit grace files quota limit grace |
| 98 | /scratch03 86978M 1024G 2048G 180k 0 391m |
| 99 | /u01 2723M 40000M 40050M 19136 0 0 |
| 100 | cat |
| 101 | Print the entire contents of a file. |
| 102 | |
| 103 | [tulaneID@cypress1 ~]$ cat daysofweek.txt |
| 104 | monday |
| 105 | tuesday |
| 106 | wednesday |
| 107 | thursday |
| 108 | friday |
| 109 | saturday |
| 110 | sunday |
| 111 | more |
| 112 | more is like cat, except it prints the file one page at a time. The spacebar is used to continue on to the next page. |
| 113 | |
| 114 | grep |
| 115 | Find text in a file. grep will return every line in the file that matches your search term. |
| 116 | |
| 117 | [tulaneID@cypress1 ~]$ cat animals |
| 118 | dog |
| 119 | Dog |
| 120 | cat |
| 121 | Racoon |
| 122 | DOG |
| 123 | bullfrog |
| 124 | Little Doggie |
| 125 | |
| 126 | [tulaneID@cypress1 ~]$ grep dog animals |
| 127 | dog |
| 128 | Use the -v flag to print out every line excluding those containing the search term. Notice that "dog" (lowercase) is missing from the results. |
| 129 | |
| 130 | [tulaneID@cypress1 ~]$ grep -v dog animals |
| 131 | Dog |
| 132 | cat |
| 133 | Racoon |
| 134 | DOG |
| 135 | bullfrog |
| 136 | Little Doggie |
| 137 | The -i flag will search without case-sensitivity. |
| 138 | |
| 139 | [tulaneID@cypress1 ~]$ grep -i dog animals |
| 140 | dog |
| 141 | Dog |
| 142 | DOG |
| 143 | Little Doggie |
| 144 | The -i and -v flag can be combined to exclude all lines containing the search term regardless of capitalization. |
| 145 | |
| 146 | [tulaneID@cypress1 ~]$ grep -iv dog animals |
| 147 | cat |
| 148 | Racoon |
| 149 | bullfrog |
| 150 | sed |
| 151 | sed is a powerful text stream editor. There are many uses of this program, but the most common is its search and replace function. Combined with regular expressions, this command can be used to seek out complex strings in your code and replace them with modifications. Please visit Sed - An Introduction and Tutorial for more information. |
| 152 | |
| 153 | [tulaneID@cypress1 ~]$ cat animals |
| 154 | dog |
| 155 | Dog |
| 156 | cat |
| 157 | Racoon |
| 158 | DOG |
| 159 | bullfrog |
| 160 | Little Doggie |
| 161 | |
| 162 | [tulaneID@cypress1 ~]$ sed 's/dog/bird/g' animals |
| 163 | bird |
| 164 | Dog |
| 165 | cat |
| 166 | Racoon |
| 167 | DOG |
| 168 | bullfrog |
| 169 | Little Doggie |
| 170 | awk |
| 171 | awk is a programming language used to modify files. One common use of awk is printing specific columns of a text stream or file. |
| 172 | |
| 173 | [tulaneID@cypress1 ~]$ cat sample.data |
| 174 | 0.3 0.22 1.8 |
| 175 | 3.1 2.34 3.0 |
| 176 | 0.2 1.0 3.2 |
| 177 | |
| 178 | [tulaneID@cypress1 ~]$ awk '{print $1 " " $3}' |
| 179 | 0.3 1.8 |
| 180 | 3.1 3.0 |
| 181 | 0.2 3.2 |
| 182 | The above command printed out the 1st and 3rd columns of the sample.data file. |
| 183 | |
| 184 | For more information on awk please visit Awk - A Tutorial and Introduction. |
| 185 | |
| 186 | tail |
| 187 | Displays lines from the end of a file. Useful for viewing recent results in an output file. |
| 188 | |
| 189 | [tulaneID@cypress1 ~]$ cat animals |
| 190 | dog |
| 191 | Dog |
| 192 | cat |
| 193 | Racoon |
| 194 | DOG |
| 195 | bullfrog |
| 196 | Little Doggie |
| 197 | |
| 198 | [tulaneID@cypress1 ~]$ tail -3 animals |
| 199 | DOG |
| 200 | bullfrog |
| 201 | Little Doggie |
| 202 | The -f flag can be used to tail a file interactively. New additions to the end of the file will be printed to your screen. |
| 203 | |
| 204 | head |
| 205 | Head is much like tail, except it prints from the top of a file. |