File types and Listing                                          File Security
       Thoughtful Solutions                             file filename            Classify the file                      chmod mode filename
  Creatively Implemented and Communicated               strings filename         Show any ASCII strings in a file                         Change security settings on file
                                                        cat filename             Display contents of file to STDOUT     chown user [:group] filename
 http://www.thoughtful-solutions.info/
                                                        more filename            Display contents of file one                             Change owner [and owning group] of
  Basic Solaris Commands                                                         screenful at a time                                      file
                                                                                                                        chgrp group filename
                                                        head   filename          Display first 10 lines of file
           Quick Reference Card                                                                                                           Change owning group of file
                                                        head   -n filename       Display first n lines of file
Conventions                                                                                                             umask mode        Set default creation permissions
<CR>               RETURN key                           tail   filename          Display last 10 lines of file
<ESC>              ESCAPE key                           tail   -n filename       Display last n lines of file           Symbolic modes
<DEL>              DELETE key                           tail   -f filename       Recursively display last 10 lines of         Mode          Meaning            Mode            Meaning
<Ctrl-X>           press <Control> key and type x                                file
italics            items to be replaced by your own     cut                      Extract character or fields from
                                                                                                                               u             user                   r             read
                   requirements                                                  text                                          g             group                  w             write
                                                        wc filename              Count lines, words and characters             o             other                  x          execute
Shell Commands                                                                   in file
passwd             Change password                      diff f1 f2               Find differences between two files            a              all                  u+s            setuid
logout             End terminal session                 diff3 f1 f2 f3           Find differences between 3 files              =             assign                g+s            setgid
                                                        sort filename            Sort file alphabetically by first             +              add                  +t          sticky bit
File Hierarchy                                                                   letter
cd dir1            Change to directory dir1             uniq                     Report or filter out repeated lines
                                                                                                                               -            remove
ls                 List files in directory                                                                              Octal modes
ls -l              List files in detail                 Redirection                                                     Base directory mode is 777. Base file mode is 666
mkdir dir1         Create new directory dir1            STDIN                    Standard Input, typically the                 user                   group                  other
rmdir dir1         Remove directory dir1                                         keyboard
                                                                                                                          r        w    x      r        w      x         r    w          x
cp f1 f2           Copy file f1 to f2                   STDOUT                   Standard Output, typically the
mv f1 [f2…] dir1   Move files f1 to fn to directory                              screen                                   4        2    1       4       2      1         4    2          1
                   dir1                                 STDERR                   Standard Error, where errors are
                                                                                                                                   7                   7                      7
mv dir1 dir2       Rename directory dir1 as dir2                                 sent. Typically the screen
rm filename        Delete (remove) file filename        comm > file              Output of comm creates file
                                                                                                                        Shell Wildcards
ln file1 name      Create a hard link to file1 called   comm < file              Contents of file used as input to
                   name                                                          comm                                        Meta-                            Meaning
ln -s file1 name   Create a soft link to file1 called   comm 2> filename         Error messages from comm sent to          character
                   name                                                          file                                              *        Any character
pwd                Show path to current directory       comm >> filename         Output from comm appended to                      ?        Any single character
                                                                                 file
Getting Help                                            cat file <<EOF           Create a document called file                 [ ]          A range of characters
man name           Show man page for command            data…                    containing data
                   name                                 EOF
man -k subject     Show man pages relating to           comm1 | comm2            Output from comm1 used as input
                   subject                                                       to comm2
man -s# subject    Show man page relating to            mkfifo name              Create a named pipe called name         This work is licensed under the Creative Commons Attribution-
                   subject in section number #          mknod name p             Create a named pipe called name             ShareAlike License. To view a copy of this license, visit
man -s# Intro      Show introductory man page for                                                                        http://creativecommons.org/licenses/by-sa/2.0/
                   section #
Translations and Searching                                Networking                                                  set -o emacs           Recall commands, edit and re-execute
tr set1 set2         Translates set1 to set2              telnet hostname [port]                                                             using emacs commands
sed                  Powerful text manipulation tool                        Connects to host and opens a              Shell Initialization
grep pattern filename                                                       shell. Optionally on specified port.      /etc/profile ($HOME/.profile)
                     Finds lines containing pattern in    ftp hostname      Connects to a remote host to               sh, bash, ksh system wide (per user) init
                     file                                                   transfer files                             (system wide init has no effect in CDE environment).
grep -v pattern filename                                  ssh hostname [command ]                                     /etc/.login ($HOME/.login)
                     Finds lines NOT containing                             Makes a secure connection to               csh, tcsh system wide (per user) init
                     pattern in file                                        host and opens a shell.                    (system wide init has no effect in CDE environment).
grep -i pattern filename                                                                                              $HOME/.cshrc
                     Finds all lines containing           Processes and Process Control                                per user csh, tcsh init
                     pattern in file ignoring case        ps                   Displays processes running on a         (order: /etc/.login → $HOME/.cshrc → $HOME/.login)
find path condition                                                            host                                   $HOME/.kshrc
                     Finds files matching condition       prstat               Displays iterating list of processes    per user ksh init
                     from path downwards                                       by CPU usage                            (order: /etc/profile → $HOME/.profile → $HOME/.kshrc)
find path -inum n Finds hard links, i.e. All files with   command &            Run command in background              $HOME/.bashrc
                                                          jobs                 Print list of jobs                      per user bash init
                     the same i-node number
                                                                               Resume foreground job n                 (order: /etc/profile → $HOME/.profile → $HOME/.bashrc)
who                  Displays users on system             fg [%n]
who am i             Shows real user id                   bg [%n]              Resume background job n
                                                                                                                      Shell Programming
w                    Displays users on system             stop %n              Suspend background job n
                                                                                                                      #!path/to/shell        'sh-bang' is a special string which
id                   Shows effective username & UID,      kill [%n]            Kill job n
                                                                                                                                             indicates that the path following
                     and group membership                 <Ctrl-c>             Interrupt process
                                                                                                                                             contains the location of the command
                     Searches /usr/dict/words for         <Ctrl-z>             Suspend current process
look word                                                                                                                                    to run the script
                     word                                 kill n               Kill process n
                                                          kill -9 n            Terminate process n                    Flow Control
Regular Expressions                                       <Ctrl-s>             Stop screen scrolling
                                                                                                                                   sh;bash;ksh               csh;tcsh
    .     Any character                                   <Ctrl-q>             Resume screen output
                                                          sleep n              Sleep for n seconds                    if-     if [ condition ];       if (condition)
    ^      Start of line                                                                                              then-   then                    then
                                                                                                                      else    actions_1;              action_1;
    $      End of line                                    Shells and Variables                                                elif [ condition ];     else if (condition)
                                                          variable=value       Create local variable variable                 then                    then
    *      Any number of the preceding characters                              with value value                               actions_2;              action_2;
                                                                                                                              else                    else
    ?      A single character                             export variable      Make variable an
                                                                                                                              actions_3;              action_3;
                                                                               environmental variable                         fi                      endif
   [ ]     Holds a range                                  unset variable       Remove environment variable
                                                                                                                      do      while [ condition ]; while (condition)
   [^ ]    Holds a negated range                          set                  Show local variables                           do                   actions
                                                                                                                      while
                                                          env                  Show environmental variables                   actions;             end
  ( )    Creates a submatch
                                                          alias name1 name2 Create command alias                              done
   1-9    Reference a submatch                           alias                Show command aliases                   until   until [ condition ];         Not available
          Escapes special character meanings             unalias name1        Remove command alias name1                     do
                                                                                                                              actions;
                                                          history              Display recent commands                        done
                                                          ! n                  Submit recent command n
                                                          set -o vi            Recall commands, edit and re-          for     for arg in list… ;      foreach arg (list)
                                                                                                                              do                      actions
                                                                               execute using vi commands                      actions;                end
                                                                                                                              done

Sunadmin

  • 1.
    File types andListing File Security Thoughtful Solutions file filename Classify the file chmod mode filename Creatively Implemented and Communicated strings filename Show any ASCII strings in a file Change security settings on file cat filename Display contents of file to STDOUT chown user [:group] filename http://www.thoughtful-solutions.info/ more filename Display contents of file one Change owner [and owning group] of Basic Solaris Commands screenful at a time file chgrp group filename head filename Display first 10 lines of file Quick Reference Card Change owning group of file head -n filename Display first n lines of file Conventions umask mode Set default creation permissions <CR> RETURN key tail filename Display last 10 lines of file <ESC> ESCAPE key tail -n filename Display last n lines of file Symbolic modes <DEL> DELETE key tail -f filename Recursively display last 10 lines of Mode Meaning Mode Meaning <Ctrl-X> press <Control> key and type x file italics items to be replaced by your own cut Extract character or fields from u user r read requirements text g group w write wc filename Count lines, words and characters o other x execute Shell Commands in file passwd Change password diff f1 f2 Find differences between two files a all u+s setuid logout End terminal session diff3 f1 f2 f3 Find differences between 3 files = assign g+s setgid sort filename Sort file alphabetically by first + add +t sticky bit File Hierarchy letter cd dir1 Change to directory dir1 uniq Report or filter out repeated lines - remove ls List files in directory Octal modes ls -l List files in detail Redirection Base directory mode is 777. Base file mode is 666 mkdir dir1 Create new directory dir1 STDIN Standard Input, typically the user group other rmdir dir1 Remove directory dir1 keyboard r w x r w x r w x cp f1 f2 Copy file f1 to f2 STDOUT Standard Output, typically the mv f1 [f2…] dir1 Move files f1 to fn to directory screen 4 2 1 4 2 1 4 2 1 dir1 STDERR Standard Error, where errors are 7 7 7 mv dir1 dir2 Rename directory dir1 as dir2 sent. Typically the screen rm filename Delete (remove) file filename comm > file Output of comm creates file Shell Wildcards ln file1 name Create a hard link to file1 called comm < file Contents of file used as input to name comm Meta- Meaning ln -s file1 name Create a soft link to file1 called comm 2> filename Error messages from comm sent to character name file * Any character pwd Show path to current directory comm >> filename Output from comm appended to ? Any single character file Getting Help cat file <<EOF Create a document called file [ ] A range of characters man name Show man page for command data… containing data name EOF man -k subject Show man pages relating to comm1 | comm2 Output from comm1 used as input subject to comm2 man -s# subject Show man page relating to mkfifo name Create a named pipe called name This work is licensed under the Creative Commons Attribution- subject in section number # mknod name p Create a named pipe called name ShareAlike License. To view a copy of this license, visit man -s# Intro Show introductory man page for http://creativecommons.org/licenses/by-sa/2.0/ section #
  • 2.
    Translations and Searching Networking set -o emacs Recall commands, edit and re-execute tr set1 set2 Translates set1 to set2 telnet hostname [port] using emacs commands sed Powerful text manipulation tool Connects to host and opens a Shell Initialization grep pattern filename shell. Optionally on specified port. /etc/profile ($HOME/.profile) Finds lines containing pattern in ftp hostname Connects to a remote host to sh, bash, ksh system wide (per user) init file transfer files (system wide init has no effect in CDE environment). grep -v pattern filename ssh hostname [command ] /etc/.login ($HOME/.login) Finds lines NOT containing Makes a secure connection to csh, tcsh system wide (per user) init pattern in file host and opens a shell. (system wide init has no effect in CDE environment). grep -i pattern filename $HOME/.cshrc Finds all lines containing Processes and Process Control per user csh, tcsh init pattern in file ignoring case ps Displays processes running on a (order: /etc/.login → $HOME/.cshrc → $HOME/.login) find path condition host $HOME/.kshrc Finds files matching condition prstat Displays iterating list of processes per user ksh init from path downwards by CPU usage (order: /etc/profile → $HOME/.profile → $HOME/.kshrc) find path -inum n Finds hard links, i.e. All files with command & Run command in background $HOME/.bashrc jobs Print list of jobs per user bash init the same i-node number Resume foreground job n (order: /etc/profile → $HOME/.profile → $HOME/.bashrc) who Displays users on system fg [%n] who am i Shows real user id bg [%n] Resume background job n Shell Programming w Displays users on system stop %n Suspend background job n #!path/to/shell 'sh-bang' is a special string which id Shows effective username & UID, kill [%n] Kill job n indicates that the path following and group membership <Ctrl-c> Interrupt process contains the location of the command Searches /usr/dict/words for <Ctrl-z> Suspend current process look word to run the script word kill n Kill process n kill -9 n Terminate process n Flow Control Regular Expressions <Ctrl-s> Stop screen scrolling sh;bash;ksh csh;tcsh . Any character <Ctrl-q> Resume screen output sleep n Sleep for n seconds if- if [ condition ]; if (condition) ^ Start of line then- then then else actions_1; action_1; $ End of line Shells and Variables elif [ condition ]; else if (condition) variable=value Create local variable variable then then * Any number of the preceding characters with value value actions_2; action_2; else else ? A single character export variable Make variable an actions_3; action_3; environmental variable fi endif [ ] Holds a range unset variable Remove environment variable do while [ condition ]; while (condition) [^ ] Holds a negated range set Show local variables do actions while env Show environmental variables actions; end ( ) Creates a submatch alias name1 name2 Create command alias done 1-9 Reference a submatch alias Show command aliases until until [ condition ]; Not available Escapes special character meanings unalias name1 Remove command alias name1 do actions; history Display recent commands done ! n Submit recent command n set -o vi Recall commands, edit and re- for for arg in list… ; foreach arg (list) do actions execute using vi commands actions; end done