X
117 Rate this article:
No rating

Internal: Helpful UNIX (and DOS) commands

Anonym

Topic:

This is an internal help article with extremely helpful UNIX and DOS commands.  It is not external because we don't want to be responsible for out of date information and we do not want be blamed if users use these commands wrong. Also we want to keep this out of the hands of evil doers.

Discussion:

  • Find file "myfile.txt" in the current directory or its subdirectories
       misc:         find . -name myfile.txt
     
  • Find .pro files in current dir containing the string "my string" and on what line
       misc:         grep -n "my string" *.pro
     
  • Find files containing text "my string" in the current directory or its subdirectories
       misc:         find . -exec grep -l "my string" {} \;
     
  • 'tar' Archive a subdirectory './mysubdir/' and all its subdirs into a file that will be named 'mytarfile.tar' in the current dir
       misc:         tar -cvf mytarfile.tar mysubdir
     
  • Untar 'mytarfile.tar' file in the current dir. If that file was 'tar-ed' as above, this will create a new directory tree '/mysubdir/' in your current dir
       misc:         tar -xvf mytarfile.tar
     
  • 'gzip' Compress file 'mytarfile.tar' in current directory to a separate file 'mytarfile.tar.gz'
       misc:         gzip mytarfile.tar
     
  • Uncompress file 'mytarfile.tar.gz' in current directory to a separate file 'mytarfile.tar'
       misc:         gunzip mytarfile.tar
     
  • Check dynamic linking
       sgi:            elfdump -Dl
       sun:            ldd
       linux:         ldd (You can use the LD_DEBUG environment variable to check  dll loaded during runltime)
       hp:            chatr
       mac os x:         otool -L
     
  • Check swap space
       sgi:            /etc/swap -l
       sun 4.1.x:   /etc/pstat -s
       sun sol 2.x:   /etc/swap -l
       hp:            /etc/swapinfo
       ibm:
       osf:            /sbin/swapon -s
     
  • Full process list
       sgi:               ps -ef
       sun 4.1.x:      ps -agx
       sun sol 2.x:   ps -agx
       hp:               ps -ef
       mac os x:      ps -Ajww
       linux, solaris   ps -ef

       ( Typically, for the commands above, the 1st column of output is username,
       2nd is the process ID (PID), 3rd is the parent process ID (PPID).)

       ( To find all processes owned by you, send the output (via a pipe)
       through a grep command looking for your user name, for example:

          ps -ef | grep joeuser
       )
     
  • Hardware inventory
       sgi:               hinv
     
  • System call trace
       sgi:               par -sSS -o logfile
       solaris:         truss -o logfile
       linux:            strace -o logfile

                            strace -p < pid > -o logfile      
                                  (...to hook into a process already running, where "< pid >"
                                  is the process ID of the running process, such as the
                                  core "idl_opserver" process that runs when the IDL
                                  Workbench is started. See the "full process list" section
                                  above to find the PID (process ID) of the target process.)            

      
     
  • System user- and hardware-defined limits
       misc:            limit
                         limit -h
     
  • Symbols in object file
       misc:            nm | grep
     
  • Check for patches
       solaris:         showrev -p
       hp:               swlist
     
  • Get own Operating System version info
       misc:         uname -a
     
  • Get own host name
       misc:         hostname
     
  • Get own IP or Ethernet Mac address
       misc:         /usr/sbin/ifconfig -a
     
  • Get IP Address of other hosts:
       misc:         /usr/sbin/arp [hostname]
       misc:         /usr/sbin/nslookup
                         [then you'll be at a prompt, enter the hostname]
     
  • Show color table
       misc:         xcmap
     
  • Increase the stacksize and datasize on Tru64 4.0F Unix:
       Save the old kernel:
       # cp /vmunix /vmunix.save

       Create a new kernel:
       # /usr/sbin/doconfig -c COOL

       Do you want to edit the configuration file? (y/n) [n]: y

       Modify the datasize:
       dfldsiz 536870912

       Move the new kernel:
       # mv /sys/COOL/vmunix /vmunix

       Reboot:
       # /usr/sbin/shutdown -r now
     
  • Find out if a file is an o32 or n32 object on SGI:
       sgi:      file
     
  • Linux RPM related information:

       rpm -qlp [rpm package filename] * Show the file contents of a rpm package file
       rpm -q [package name]      * Verify an installed package
       rpm -qa | grep [rpm name]   * Find an installed package
       rpm -ql   [package name]      * List files in installed package

    Example download source for RPMs:

       http://download.fedora.redhat.com/pub/fedora/linux/core/4/x86_64/os/Fedora/RPMS/compat-libstdc++-33-3.2.3-47.fc4.i386.rpm
     
  • Ubuntu/Debian Linux (verify existence of library package)

Command:

    dpkg-query -l lsb-core

Result:

    Package status code (Desired action/Package status)

-> "un" (action / status = unknown / not-installed)

-> "ii" (action / status = install / installed)

Command:

    dpkg-query -L lsb-core

Result:

-> Not installed:  "package 'lsb-core' is not installed"

-> Installed:  [ A list of files is displayed ]

  • Mac OS X command to get Mac OS X version information:

    sw_vers

  • Remove the quarantine extended-attribute on downloaded file or folder:

    File:
        sudo xattr -c -r /path/to/file

    Recursively on folder:

        sudo xattr -c -r /path/to/folder_containing_the_app_file

    Afterward, the command "ls -l@" on the directory should no longer display the @ attribute on the directory or the contained files.

    (Note also that the "xattr" utility (/usr/bin/xattr) is actually a Python script.  I also understand that it specifically requires the use of Python 2.7.)

     

    • Mac OS X command for Mac file copying including related resource fork file and permission preservation:


       ditto [source] [destination]      (* Like copying via the Apple Finder)
     

    • Mac OS X command to determine the currently installed JRE version:

         java -version
       
    • The following 2 commands will make the hidden files (files that start with a dot) visible from the Apple Finder:

         defaults write com.apple.finder AppleShowAllFiles TRUE

         killall Finder

      The second command will re-start the Finder. Once restarted the hidden files will be visible.
       
    • Check if a MAC OSX system is 64-bit capable: 

      /usr/sbin/sysctl -n hw.cpu64bit_capable

    • Commands to reliably determine current shell type on Linux, Mac and Solaris
      (because "echo  $SHELL" doesn't always give you the correct information)
       
    • Command on Linux and Mac OS X to see the status of active TCP/IP ports on a system:
       
    • Command that an be used to stop Linux firewall to test to see if license manager connection is blocked by firewall. Should start firewall back up again after done testing.
       
      • Mac OS X steps to get equivalent of a stack trace for an IDL session (11/21/2017 - ju)

      Here's a method for getting system call information from the customer's IDL session by doing the following (assumes a bash shell):

      1. Open *two* XQuartz xterm windows.

      2. In xterm #1 open a root shell with the command:

          sudo -s

      3. In xterm #2, source the idl_setup.bash script:

          source /Applications/harris/idl86/bin/idl_setup.bash

      4. In xterm #1, enter the command:

          dtruss -as -W idl > /Users/joeuser/dtruss_out.txt 2>&1

      where the customer should use their actual home directory name instead of "joeuser".

      5. Then in xterm #2 issue the command:

          idl

      After the IDL session dies, the system call output should be in the output file to send to tech support for examination.
       

    • Linux: Encode a binary executable file into an alphanumeric stream and then decode back to binaray using utility "base64":

      Encode from binary to alphanumeric stream:

        base64 mybinary > mybinary.txt

    Decode resulting alphanumeric stream back to the original binary:

        base64 -d -i mybinary.txt > mybinary

    Then give the resulting file execute permission before running the program:

        chmod +x mybinary
        mybinary

     

    LINUX:

    Both of the following may be generally relevant but also useful for shared memory usage issues, but also for IDL_IDLBridge, semaphores, threading, and ESE issues

    Shared memory usage commands:

        ipcs

        ipcs -l

        ipcs -u

    User resource limits:

        ulimit -a     <-- bash

        limit            <-- tcsh or csh

        ulimit -n 4096   <-- If allowed by the system, increases the number of file descriptors to 4096

    Permanently open TCP listening port 7070 in firewall from command line on CentOS 7 

        firewall-cmd --get-active-zones
        firewall-cmd --zone=public --add-port=7070/tcp --permanent
        firewall-cmd --reload

        firewall-cmd --get-active-zones
        firewall-cmd --list-all

    Possible approaches to see if TRACE(TRACK) is enabled (potential security vulnerability) on HTTP or HTTPS server

            curl -v -X TRACE http://www.yourserver.com
            curl --insecure -v -X TRACE https://www.google.com/

     

    JAVA:

        Java Installation Home Directory

            (In the context of the new Flexera License Server (2016), from the "java.home" location, if "./bin/javac" exists then you should consider this the JAVA_HOME  directory.  If only "./bin/java" exists then this would be the JRE_HOME directory.)

        * One way to try to find the Java installation directory location of "java" command (ju 8aug2016):

              java -XshowSettings:properties -version

            Linux:        

                For example (bash -- redirecting stderr to stdout):

                $ ./java -XshowSettings:properties -version 2>&1 | grep java.home
                java.home = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.101-3.b13.el7_2.x86_64/jre

            Windows:

                For example, from a Windows Command Prompt window:
        
                    java -XshowSettings:properties -version 2>&1 | find "java.home"

        Java Installation Bit Version

        * To find the bit-version of the Java installation, run the command:

                java -version

            If  the result indicates a 64-bit version then it is 64-bit Java.  If no bit-version is indicated then the Java installation is 32-bit.  Example output from a 64-bit Java installation:

                java version "1.8.0_101"
                Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
                Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

    ==================

    PYTHON:

    -----------------------

      To install additional Python packages to your Anaconda installation using conda from within the Harris network, you'll first need to disable SSL verification:

        conda config --set ssl_verify false

      To reenable SSL verification:

        conda config --set ssl_verify false

    -----------------------

     

    =================

    DOS COMMANDS
    =================
    Send a file to a network printer:
    print /d:\\printsrv\flr3prt3 myfile.txt
    print /d:\\printsrv\flr3prt3 mybinarypsfile.ps

    Run a program without invoking a new DOS shell window:
    START "[a-title-string]" [path-to-windows-executable][executable-arguments]

     

    ===============================
    * Change Windows process priority on the fly using WMIC command *

    The command line syntax:

        wmic process where name="AppName" CALL setpriority ProcessIDLevel

    The customary notepad example setting it to "Above Normal":

        wmic process where name="notepad.exe" CALL setpriority 32768 

    NOTE: Be careful setting the priories higher than normal because it could cause problems with system critical processes. 

    Idle: 64
    Below Normal: 16384
    Normal: 32
    Above Normal: 32768
    High Priority: 128
    Real Time: 256

    ===============================

    * Windows XP: Get the file path of a running executable with WMIC

    See also Microsoft article:

    http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/wmic.mspx?mfr=true

    For example:

    C:\>wmic
    wmic:root\cli>PROCESS WHERE (Description="idl.exe")
    Caption  CommandLine                                          CreationClassName  CreationDate               CSCreationClassName   CSName   Description  ExecutablePath                                     ExecutionState  Handle  HandleCount  InstallDate  KernelModeTime  MaximumWorkingSetSize  MinimumWorkingSetSize  Name     OSCreationClassName    OSName                                                                     OtherOperationCount  OtherTransferCount  PageFaults  PageFileUsage  ParentProcessId  PeakPageFileUsage  PeakVirtualSize  PeakWorkingSetSize  Priority  PrivatePageCount  ProcessId  QuotaNonPagedPoolUsage  QuotaPagedPoolUsage  QuotaPeakNonPagedPoolUsage  QuotaPeakPagedPoolUsage  ReadOperationCount  ReadTransferCount  SessionId  Status  TerminationDate  ThreadCount  UserModeTime  VirtualSize  WindowsVersion  WorkingSetSize  WriteOperationCount  WriteTransferCount
    idl.exe  "C:\Program Files\Exelis\IDL82\bin\bin.x86\idl.exe"  Win32_Process      20121224154854.068993-420  Win32_ComputerSystem  TEKXP32  idl.exe      C:\Program Files\Exelis\IDL82\bin\bin.x86\idl.exe                  1984    46                        468750          1413120                204800                 idl.exe  Win32_OperatingSystem  Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition2  283                  139878              723         1040384        2096             1040384            32423936         2879488             8         1040384           1984       3240                    30008                3376                        34036                    65                  17269              0                                   4            156250        29655040     5.1.2600        2879488         41                   329

    wmic:root\cli>

     =======================================================
    Windows 7 (and later?) - How to re-map .pro and .sav file name extensions 
    to open with the appropriate version IDL and IDL RT executables
    =======================================================

    To see what program version is associated to .pro and .sav files on your system, from a Windows Command Prompt window, issue the 2 commands:

        ftype IDLprogramFile

        ftype IDLbinaryFile

    To remap the .pro and .sav file extension to a different version of IDL, from Windows Command Prompt window running as Administrator (e.g., for IDL 8.5):

        ftype IDLprogramFile="C:\Program Files\Exelis\IDL85\bin\bin.x86_64\IDLSnapFileOpen.exe" "%1"

        ftype IDLbinaryFile="C:\Program Files\Exelis\IDL85\bin\bin.x86_64\idlrt.exe" "%1"

    Also, if needed, the ASSOC command shows the current file name extension association to a program reference, for example:

        C:\Users\joeuser> assoc | find ".sav"
        .sav=IDLbinaryfile

    and can also be used to establish a connection to the program reference (although we would normally assume that this is already defined), for example:

        ASSOC .sav=IDLbinaryfile


    =======================================================
    Windows: How to change the default "idlde" command used with Start 
    command from command prompt (e.g.: "start idlde") or from Start 
    menu > Run interface?
    =======================================================
    For example, for IDL 8.5, running PowerShell as Administrator, issue the following 2 commands:

        set-itemproperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\App Paths\idlde.exe" -name "(Default)" "C:\Program Files\Exelis\IDL85\bin\bin.x86_64\idlde.exe"

        set-itemproperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\App Paths\idlde.exe" -name "Path" "C:\Program Files\Exelis\IDL85\bin\bin.x86_64\"

     

    Windows: How to enable executable to listen through firewall from command prompt:

        netsh advfirewall firewall add rule name="My App" dir=in action=allow program="C:\Path\to\myapp.exe" enable=yes

    ===============================

    keywords: useful unix commands, to know, helpful unix commands