Changes between Version 2 and Version 3 of cypress/BasicLinuxComands


Ignore:
Timestamp:
05/14/15 11:56:28 (9 years ago)
Author:
cmaggio
Comment:

migrated content from ccs wiki

Legend:

Unmodified
Added
Removed
Modified
  • cypress/BasicLinuxComands

    v2 v3  
    44Here are a few of the common Linux commands you will use to navigate the clusters and manipulate files and directories.
    55
    6 THIS PAGE IS UNDER CONSTRUCTION
     6=== man ===
     7Display 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 ===
     13The '''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 ===
     22List files.
     23{{{
     24[tulaneID@cypress1 ~]$ ls
     25a.out  code.c  Makefile
     26}}}
     27
     28Setting the ''-l'' flag will display files along with their permissions and ownership.
     29{{{
     30[tulaneID@cypress1 ~]$ ls -l
     31total 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 ===
     38Create 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 ===
     48Remove files and directories. CAUTION: THERE IS NO UNDOING THIS COMMAND.
     49{{{
     50[tulaneID@cypress1 ~]$ rm testfile
     51}}}
     52If you would like to remove a directory and all of its contents use the following command:
     53{{{
     54[tulaneID@cypress1 ~]$ rm -ri testdir
     55rm: descend into directory `testdir'? y
     56rm: remove regular empty file `testdir/Makefile'? y
     57rm: remove regular empty file `testdir/code.c'? y
     58rm: remove regular empty file `testdir/a.out'? y
     59rm: remove directory `testdir'? y
     60[tulaneID@cypress1 ~]$
     61}}}
     62The ''r'' flag specifies to remove files/directories recursively. ''i'' specifies to prompt before deleting each file.
     63
     64If 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
     68ls: cannot access testdir: No such file or directory
     69}}
     70
     71=== cp ===
     72Copy file to new location.
     73
     74In the example below file1 already exists, and file2 will become the copy.
     75
     76[tulaneID@cypress1 ~]$ cp file1 file2
     77To copy a directory and all of its contents:
     78
     79[tulaneID@cypress1 ~]$ cp -r dir1 dir2
     80mv
     81Move a file to a new location.
     82
     83[tulaneID@cypress1 ~]$ mv file1 file2
     84[tulaneID@cypress1 ~]$ ls file1
     85ls: cannot access file1: No such file or directory
     86[tulaneID@cypress1 ~]$ ls file2
     87file2
     88Unlike cp, the mv command does not create a second instance of the file or directory.
     89
     90quota
     91Display disk quotas.
     92
     93The -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
     95user@sphynx>quota -s
     96Disk quotas for user wcurry (uid 65098):
     97Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
     98/scratch03  86978M   1024G   2048G            180k       0    391m       
     99/u01        2723M  40000M  40050M           19136       0       0
     100cat
     101Print the entire contents of a file.
     102
     103[tulaneID@cypress1 ~]$ cat daysofweek.txt
     104monday
     105tuesday
     106wednesday
     107thursday
     108friday
     109saturday
     110sunday
     111more
     112more 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
     114grep
     115Find text in a file. grep will return every line in the file that matches your search term.
     116
     117[tulaneID@cypress1 ~]$ cat animals
     118dog
     119Dog
     120cat
     121Racoon
     122DOG
     123bullfrog
     124Little Doggie
     125
     126[tulaneID@cypress1 ~]$ grep dog animals
     127dog
     128Use 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
     131Dog
     132cat
     133Racoon
     134DOG
     135bullfrog
     136Little Doggie
     137The -i flag will search without case-sensitivity.
     138
     139[tulaneID@cypress1 ~]$ grep -i dog animals
     140dog
     141Dog
     142DOG
     143Little Doggie
     144The -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
     147cat
     148Racoon
     149bullfrog
     150sed
     151sed 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
     154dog
     155Dog
     156cat
     157Racoon
     158DOG
     159bullfrog
     160Little Doggie
     161
     162[tulaneID@cypress1 ~]$ sed 's/dog/bird/g' animals
     163bird
     164Dog
     165cat
     166Racoon
     167DOG
     168bullfrog
     169Little Doggie
     170awk
     171awk 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
     1740.3 0.22 1.8
     1753.1 2.34 3.0
     1760.2 1.0 3.2
     177
     178[tulaneID@cypress1 ~]$ awk '{print $1 " " $3}'
     1790.3 1.8
     1803.1 3.0
     1810.2 3.2
     182The above command printed out the 1st and 3rd columns of the sample.data file.
     183
     184For more information on awk please visit Awk - A Tutorial and Introduction.
     185
     186tail
     187Displays lines from the end of a file. Useful for viewing recent results in an output file.
     188
     189[tulaneID@cypress1 ~]$ cat animals
     190dog
     191Dog
     192cat
     193Racoon
     194DOG
     195bullfrog
     196Little Doggie
     197
     198[tulaneID@cypress1 ~]$ tail -3 animals
     199DOG
     200bullfrog
     201Little Doggie
     202The -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
     204head
     205Head is much like tail, except it prints from the top of a file.