Saturday, August 9, 2014

Shell Commands

1. Aliases - Update these values in .bash_profile file


          Example  : alias l='ls -l'
 
.bash_profile file is a shell script that is executed each time you log in 
 
2. type - Used to determine whether the command is an executable, an alias or a function.
Syntax :  type command

Example : 
Input :
function today {
echo "print data" 
}

>type today
 
output 
today is a function
today () 
{ 
    echo "print data"
}


3. bashrc - appropriate place to store functions and aliases. To read about syntax etc see here.

4. typeset
http://www.unix.com/unix-for-dummies-questions-and-answers/32178-typeset-ksh.html

5. tr - Used to replace/remove certain characters
http://en.wikipedia.org/wiki/Tr_%28Unix%29

6.  uname  - returns certain system information
http://en.wikipedia.org/wiki/Uname

(Taken from man )
SYNOPSIS
       uname [OPTION]...

DESCRIPTION
       Print certain system information.  With no OPTION, same as -s.

       -a, --all
              print  all  information,  in the following order, except omit -p
              and -i if unknown:

       -s, --kernel-name
              print the kernel name

       -n, --nodename
              print the network node hostname

       -r, --kernel-release
              print the kernel release

       -v, --kernel-version
              print the kernel version

       -m, --machine
              print the machine hardware name

       -p, --processor
              print the processor type or "unknown"

       -i, --hardware-platform
              print the hardware platform or "unknown"

       -o, --operating-system
              print the operating system

       --help display this help and exit

       --version
              output version information and exit


Example demonstrating usage of tr and uname :
-bash-4.1$ uname -s | tr -d /
CYGWIN_NT-6.1-WOW64
-bash-4.1$ uname -s | tr -d C
YGWIN_NT-6.1-WOW64
-bash-4.1$
7. Export - In a way, used to make variables global
http://www.cyberciti.biz/faq/linux-unix-shell-export-command/

8. which - Used to locate the executable for a command.
 http://www.computerhope.com/unix/uwhich.htm
Example usage :
/usr/bin/cat
-bash-4.1$ which -p cat
9. whereis - Locates the binary, source and manual page files for a command.
http://www.computerhope.com/unix/uwhich.htm

Example usage :  
-bash-4.1$ whereis cat
cat: /bin/cat.exe /usr/bin/cat.exe /usr/share/man/man1/cat.1.gz
10.env - used to print the env variables or to set  certain values temporarily.
http://www.computerhope.com/unix/uenv.htm

11. id - Print  real and effective ID's and GUIDs
http://linux.about.com/library/cmd/blcmdl1_id.htm
Example usage :
-bash-4.1$ id
uid=500(Administrator) gid=513(None) groups=513(None),545(Users)
-bash-4.1$ id -n
12. sed
http://www.grymoire.com/unix/sed.html

13. pmap - Memory utilization of a process
http://www.tutorialspoint.com/unix_commands/pmap.htm

http://www.cyberciti.biz/tips/howto-find-memory-used-by-program.html


14. svmon - AIX specific parameter that captures and analyses a snapshot of virtual memory.
http://ps-2.kev009.com/tl/techlib/manuals/adoclib/cmds/aixcmds5/svmon.htm

View an output screenshot here :
http://publib.boulder.ibm.com/infocenter/realtime/v2r0/index.jsp?topic=%2Fcom.ibm.softrt.aix32.doc%2Fdiag%2Fproblem_determination%2Faix_cmd_svmon.html

15. iconv - An API used to convert between different standard encodings
http://en.wikipedia.org/wiki/Iconv

16. who - Shows the currently logged in user
 (Taken from man)
SYNOPSIS
       who [OPTION]... [ FILE | ARG1 ARG2 ]

DESCRIPTION
       Print information about users who are currently logged in.

       -a, --all
              same as -b -d --login -p -r -t -T -u

       -b, --boot
              time of last system boot

       -d, --dead
              print dead processes

       -H, --heading
              print line of column headings

17. $$ - The process id of the current shell. Used when creating unique temporary file names.
Example usage :
-bash-4.1$ echo $$
3768
18. mktemp - The secure way of creating temporary files
tempfoo=`basename $0`
TMPFILE=`mktemp -t ${tempfoo}` || exit 1
echo "program output" >> $TMPFILE
 
-t is now deprecated. Use Use mktemp ${tempfoo}.XXXXXX
 
Read below for a discussion on mktemp against $$ for creating temporarily files. 
http://stackoverflow.com/questions/78493/what-does-mean-in-the-shell  
 
18. ps - Reports process status
(Taken from man)
OPTIONS
       -a, --all
              show processes of all users

       -e, --everyone
              show processes of all users

       -f, --full
              show process uids, ppids

       -h, --help
              output usage information and exit

       -l, --long
              show process uids, ppids, pgids, winpids


       ps -W : Shows windows as well as cygwin processes
       

       ps -p p_id : Details of a specific process

Example of ps -f:

-bash-4.1$ ps -f
     UID     PID    PPID  TTY        STIME COMMAND
Administ    3768    3916 pty0       Aug 10 /usr/bin/bash
Administ   12776    3768 pty0     07:16:48 /usr/bin/ps
Administ    3916       1 ?          Aug 10 /usr/bin/mintty

19. pid - Process id
20. ppid - Parent process id
21. pstree -  A program showing the relationship of all processes in a tree like manner.
22. htop - Simpler process management and a better UI.
http://delightlylinux.wordpress.com/2012/06/25/what-is-pid-and-ppid/

23. Use of  single quote (') - To treat it as a command.
Example usage :

Without quotes : 
-bash-4.1$ v=ps -a
-bash: -a: command not found

With quotes
-bash-4.1$ v='ps -a'
-bash-4.1$ $v
      PID    PPID    PGID     WINPID   TTY     UID    STIME COMMAND
     7368    3768    7368       3672  pty0     500 07:16:49 /usr/bin/ps
     3768    3916    3768       1492  pty0     500 08:14:12 /usr/bin/bash
     3916       1    3916       3916  ?        500 08:14:12 /usr/bin/mintty

24. Find the launching command for a particular PID.

-bash-4.1$ ps -a
      PID    PPID    PGID     WINPID   TTY     UID    STIME COMMAND
     7064    3768    7064       8664  pty0     500 07:19:06 /usr/bin/ps
     3768    3916    3768       1492  pty0     500 08:14:12 /usr/bin/bash
     3916       1    3916       3916  ?        500 08:14:12 /usr/bin/mintty

-bash-4.1$ ps -p 3916
      PID    PPID    PGID     WINPID   TTY     UID    STIME COMMAND
     3916       1    3916       3916  ?        500 08:14:12 /usr/bin/mintty

(Strips off the header)
-bash-4.1$ ps -p 3916 | grep -i -v COMM
     3916       1    3916       3916  ?        500 08:14:12 /usr/bin/mintty

25. lslpp -  Lists installed software products


Watch a detailed video here explaining details and usage.
https://www.youtube.com/watch?v=-9oJkRVFvTM

Read here for the text corresponding to the above video.
http://ps-2.kev009.com/tl/techlib/manuals/adoclib/cmds/aixcmds3/lslpp.htm#E088D37887joyc

A complete description of the commands.
http://www-01.ibm.com/support/knowledgecenter/ssw_aix_61/com.ibm.aix.cmds3/lslpp.htm?lang=en

26. /etc/issue - Used to customize your Unix Logon
http://www.linuxfromscratch.org/blfs/view/5.1/postlfs/logon.html

27. egrep - Extended Global regular Expressions
Make sure you go through the examples listed here to get a good feel about egrep.

Also it can be used using grep -E (see man)
http://www.cs.columbia.edu/~tal/3261/fall07/handout/egrep_mini-tutorial.htm

28. GDB/pstack and gstack
gdb - GNU Debugger
http://www.gnu.org/software/gdb/

pstack/gstack - Linux executable
It prints a stack trace of running processes

http://www.linuxcommand.org/man_pages/pstack1.html
http://linux.die.net/man/1/gstack

29. lsof - List open files
http://en.wikipedia.org/wiki/Lsof

30. declare - declare a variable as array, read-only, number only etc
http://www.linuxjournal.com/content/bash-declare-statement

31. kill - To kill a process
http://www.songsinhispresence.com/cdinfo.html#taken%20link

32. shift - This command takes one argument, a number. The positional parameters are shifted to the left by this number.
Read the link below for a good example on the same.
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_07.html

33. sleep - Sleep is used to delay for a particular amount of time.
http://www.computerhope.com/unix/usleep.htm

34. pgrep  - It searches for all the named processes that can be specified as extended regular expression patterns, and—by default—returns their process ID. Alternatives include pidof (finds process ID given a program name) and ps.

http://en.wikipedia.org/wiki/Pgrep
http://linux.die.net/man/1/pgrep

35. cut - Print selected parts of lines from each FILE to standard output.

http://www.thegeekstuff.com/2013/06/cut-command-examples/

http://www.folkstalk.com/2012/02/cut-command-in-unix-linux-examples.html

36. grep -  searches the named input FILEs (or standard input if no files are
       named, or if a single hyphen-minus (-) is given as file name) for lines
       containing  a  match to the given PATTERN.  By default, grep prints the
       matching lines.

-e PATTERN, --regexp=PATTERN
              Use  PATTERN  as  the  pattern.   This  can  be  used to specify
              multiple search patterns, or to protect a pattern beginning with
              a hyphen (-).  (-e is specified by POSIX.)

       -f FILE, --file=FILE
              Obtain  patterns  from  FILE,  one  per  line.   The  empty file
              contains zero patterns, and therefore matches nothing.   (-f  is
              specified by POSIX.)

       -i, --ignore-case
              Ignore  case  distinctions  in  both  the  PATTERN and the input
              files.  (-i is specified by POSIX.)

       -l, --files-with-matches
              Suppress  normal  output;  instead  print the name of each input
              file from which output would normally have  been  printed.   The
              scanning  will  stop  on  the  first match.  (-l is specified by
              POSIX.)

37. set - used to define and determine values of the system environment.
 -m  :
Background jobs will run in a separate process group and a line will print upon completion. The exit status of background jobs is reported in a completion message. On systems with job control, this flag is turned on automatically for interactive shells.

http://www.computerhope.com/unix/uset.htm
http://linux.about.com/library/cmd/blcmdln_set.htm

38. stty - Change and print terminal line settings
http://unixhelp.ed.ac.uk/CGI/man-cgi?stty

       -a, --all
       print all current settings in human-readable form

       -g, --save
       print all current settings in a stty-readable form

       -F, --file=DEVICE
       open and use the specified DEVICE instead of stdin

39. compress  - compacts the files so that it will become smaller.
http://www.computerhope.com/unix/ucompres.htm

40. tput - Utilizes the terminal capabilities
http://en.wikipedia.org/wiki/Tput











 
 

No comments:

Post a Comment