Changes between Version 2 and Version 3 of cypress/BasicLinuxComands

May 14, 2015 11:56:28 AM (7 years ago)

migrated content from ccs wiki


  • 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.
     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.
     10[tulaneID@cypress1 ~]$ man <command name>
     12=== pwd and cd ===
     13The '''pwd''' command lists the present working directory. The '''cd''' command changes directory.
     15[tulaneID@cypress1 ~]$ pwd
     17[tulaneID@cypress1 ~]$ cd NextDirectoryUp
     18[tulaneID@cypress1 ~]$ pwd
     21=== ls ===
     22List files.
     24[tulaneID@cypress1 ~]$ ls
     25a.out  code.c  Makefile
     28Setting the ''-l'' flag will display files along with their permissions and ownership.
     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
     37=== mkdir ===
     38Create new directory.
     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
     47=== rm ===
     48Remove files and directories. CAUTION: THERE IS NO UNDOING THIS COMMAND.
     50[tulaneID@cypress1 ~]$ rm testfile
     52If you would like to remove a directory and all of its contents use the following command:
     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 ~]$
     62The ''r'' flag specifies to remove files/directories recursively. ''i'' specifies to prompt before deleting each file.
     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:
     66[tulaneID@cypress1 ~]$ rm -rf testdir
     67[tulaneID@cypress1 ~]$ ls testdir
     68ls: cannot access testdir: No such file or directory
     71=== cp ===
     72Copy file to new location.
     74In the example below file1 already exists, and file2 will become the copy.
     76[tulaneID@cypress1 ~]$ cp file1 file2
     77To copy a directory and all of its contents:
     79[tulaneID@cypress1 ~]$ cp -r dir1 dir2
     81Move a file to a new location.
     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
     88Unlike cp, the mv command does not create a second instance of the file or directory.
     91Display disk quotas.
     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.
     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
     101Print the entire contents of a file.
     103[tulaneID@cypress1 ~]$ cat daysofweek.txt
     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.
     115Find text in a file. grep will return every line in the file that matches your search term.
     117[tulaneID@cypress1 ~]$ cat animals
     124Little Doggie
     126[tulaneID@cypress1 ~]$ grep dog animals
     128Use the -v flag to print out every line excluding those containing the search term. Notice that "dog" (lowercase) is missing from the results.
     130[tulaneID@cypress1 ~]$ grep -v dog animals
     136Little Doggie
     137The -i flag will search without case-sensitivity.
     139[tulaneID@cypress1 ~]$ grep -i dog animals
     143Little Doggie
     144The -i and -v flag can be combined to exclude all lines containing the search term regardless of capitalization.
     146[tulaneID@cypress1 ~]$ grep -iv dog animals
     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.
     153[tulaneID@cypress1 ~]$ cat animals
     160Little Doggie
     162[tulaneID@cypress1 ~]$ sed 's/dog/bird/g' animals
     169Little Doggie
     171awk is a programming language used to modify files. One common use of awk is printing specific columns of a text stream or file.
     173[tulaneID@cypress1 ~]$ cat
     1740.3 0.22 1.8
     1753.1 2.34 3.0
     1760.2 1.0 3.2
     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 file.
     184For more information on awk please visit Awk - A Tutorial and Introduction.
     187Displays lines from the end of a file. Useful for viewing recent results in an output file.
     189[tulaneID@cypress1 ~]$ cat animals
     196Little Doggie
     198[tulaneID@cypress1 ~]$ tail -3 animals
     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.
     205Head is much like tail, except it prints from the top of a file.