Basic Unix Command with examples


  • jar 
Usage: jar {ctxui}[vfmn0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
Options:
    -c  create new archive
    -t  list table of contents for archive
    -x  extract named (or all) files from archive
    -u  update existing archive
    -v  generate verbose output on standard output
    -f  specify archive file name
    -m  include manifest information from specified manifest file
    -n  perform Pack200 normalization after creating a new archive
    -e  specify application entry point for stand-alone application 
        bundled into an executable jar file
    -0  store only; use no ZIP compression
    -M  do not create a manifest file for the entries
    -i  generate index information for the specified jar files
    -C  change to the specified directory and include the following file
If any file is a directory then it is processed recursively.
The manifest file name, the archive file name and the entry point name are
specified in the same order as the 'm', 'f' and 'e' flags.

Example 1: to archive two class files into an archive called classes.jar: 
       jar cvf classes.jar Foo.class Bar.class 
Example 2: use an existing manifest file 'mymanifest' and archive all the files in the foo/ directory into 'classes.jar': 
       jar cvfm classes.jar mymanifest -C foo/ .
Example 3: to extract test.jar 
       jar xf classes.jar
Example 4: to extract test.jar with verbose
       jar xvf classes.jar

refer to : packaging in jar files
  • grep
          
Grep  searches the named input FILEs (or standard input if no files are

       named, or the file name - is given) for lines containing a match to the

       given PATTERN.  By default, grep prints the matching lines.

       In addition, two variant programs egrep and fgrep are available.     Egrep

       is the same as grep -E. Fgrep is the same as grep -F.



Example 1:  searches the file fruitlist.txt for lines containing the text string apple

    grep apple fruitlist.txt

Example 2: searches all txt files at given directory for for text string apple

    grep apple *.txt

Example 3:prints all lines in the file that begin with the letter a, followed by any one character, followed by the letter sequence ple.

    grep ^a.ple fruitlist.txt

Example 4: prints Lines only containing exactly and solely apple 

    $ cat fruitlist.txt

        apple

        apples

        pineapple

        apple-

        apple-fruit

        fruit-apple



        $ grep -x apple fruitlist.txt

        apple

Example 5: prints all lines that do not contain apple

        $ grep -v apple fruitlist.txt

        banana

        pear

        peach

        orange
  
       
  • unzip
Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
  Default action is to extract files in list, except those in xlist, to exdir;
  file[.zip] may be a wildcard.  -Z => ZipInfo mode ("unzip -Z" for usage).

  -p  extract files to pipe, no messages     -l  list files (short format)
  -f  freshen existing files, create none    -t  test compressed archive data
  -u  update files, create if necessary      -z  display archive comment
  -x  exclude files that follow (in xlist)   -d  extract files into exdir

modifiers:                                   -q  quiet mode (-qq => quieter)
  -n  never overwrite existing files         -a  auto-convert any text files
  -o  overwrite files WITHOUT prompting      -aa treat ALL files as text
  -j  junk paths (do not make directories)   -v  be verbose/print version info
  -C  match filenames case-insensitively     -L  make (some) names lowercase
  -X  restore UID/GID info                   -V  retain VMS version numbers
  -K  keep setuid/setgid/tacky permissions   -M  pipe through "more" pager

Example 1: unzip a jar file to output dir
       unzip classes.jar -d classes
Example 2: extract all files except joe from zipfile data1.zip
       unzip data1 -x joe
Example 3: send contents of foo.zip via pipe into program more
       unzip -p foo | more
Example 4: quietly replace existing ReadMe if archive file newer
       unzip -fo foo ReadMe
  • find
Example 1: find file app.properties from current directory
      find ./ - name 'app.properties'
Example 2: find file start with app from current directory
      find ./ - name 'app*'
Example 3: find file start with app from directory /home/david
       find /home/david - name 'app*'


  • cd   - Change directory. This lets you navigate to different directories (folders).

cd Documents
go into a subdirectory (of the current directory) named "Documents"
cd Documents/temp
go into "Documents", then from there into a subdirectory named "temp"
cd ..
go up to the parent of the current directory
cd ../..
go up two levels, to the parent's parent
cd /
go to the top of the boot volume
cd /Users
go to the top of the boot volume, then into the top-level directory named "Users"
cd ~
go to your home directory (note: that's a tilde, not a dash)
cd ~/Documents
go to your home directory, then into your "Documents" directory
cd '/Applications (MacOS 9)'
go to the of the boot volume, then into the top-level directory named "Applications (MacOS 9)". The quote marks tell the shell (command interpreter) to ignore the special characters (spaces and parentheses) in the directory name that would otherwise confuse it.
cd -
go back to the previous directory


  • pwd   - Print working directory. This prints the path of the current working directory 


  • ls   - List the files in the current directory, and (optionally) their characteristics.

ls
list just the names of the files in the current directory
ls -l
(long) list the files with their characteristics (size, privs, owner, etc)
ls -lo
list the files with their flags (see chflags) in addition to the usual characteristics -l shows
ls -a
list all files in the current directory (including those that would normally be invisible)
ls -F
list filenames with a special character at the end that tells you what kind of file it is ("/" for directory, "*" for unix executable, "@" for alias/symlink, etc)
ls *.jpg
list the names of all files with names ending in ".jpg"
ls a*
list the names of all files with names beginning with "a"
ls *att*
list the names of all files with names containing "att"

No comments :

Post a Comment