Tanti Technology

My photo
Bangalore, karnataka, India
Multi-platform UNIX systems consultant and administrator in mutualized and virtualized environments I have 4.5+ years experience in AIX system Administration field. This site will be helpful for system administrator in their day to day activities.Your comments on posts are welcome.This blog is all about IBM AIX Unix flavour. This blog will be used by System admins who will be using AIX in their work life. It can also be used for those newbies who want to get certifications in AIX Administration. This blog will be updated frequently to help the system admins and other new learners. DISCLAIMER: Please note that blog owner takes no responsibility of any kind for any type of data loss or damage by trying any of the command/method mentioned in this blog. You may use the commands/method/scripts on your own responsibility. If you find something useful, a comment would be appreciated to let other viewers also know that the solution/method work(ed) for you.

Tuesday, 25 February 2014

EXTREMELY USEFUL COMMANDS



ls -l
- lists files in a directory in long format. You cannot do without this. Here's a more detailed explanation. e.g.
$ ls -l
Part 1Part 2Part 3Part 4Part 5Part 6Part 7
-rw-rw-rw-1rootstaff28Jan 16 09:52README
-rw-------1compjmdstaff4304Jun 24 12:21tabledict
drwxrwxrwx2compjmdstaff512Jul 1 16:30testdir
-rwxrwx---1compjmdsystem0Jul 1 16:30a.out

... is a sample listing.

  • Part 1: Permissions - see chmod for explanation of these. If the first field is set, then the file in question is not really a file at all, but something else, key:
    • -: normal file
    • d: directory
    • l: symbolic link created by 'ln'
    • c or b: device of some sort
    You may sometimes see an 's' where the 'x' should be in the permissions - this is normally on executable files which change other files. e.g. Permissions of 'sqlexec' the file that executes all informix queries should be '-rwsr-sr-x' - this then accesses tables with permissions of '-rw-rw----'. where the table files are owned by informix (group informix). the 's' flags allows changing of the database tables on a program level, but not on a unix level. (can change contents via sqlexec but not use 'rm' command on db file).
  • Part 2: Number of links to this file (directories always have 2+).
  • Part 3: The owner of the file - e.g. If the owner is 'compjmd' and permissions are set to -rw------- then only the user 'compjmd' may read or write to that file. Again, if owner is "compjmd" and permissions are -r-x------ then only the user compjmd may read or execute that file. Only the owner of a file or root may chmod it.
  • Part 4: The group ownership of the file - (bloody hell, this is getting complicated). On a unix system there are certain 'groups' which users can belong to, held in the file '/etc/group'. You will notice that in this file there will be a main group, e.g. 'staff' which contains every user. Which means that any user listed under staff is in that group.....right...every file has a group attached to it. Which means that if a file had permissions ----rw---- and a group reference of 'system', then only users who were part of the group system could modify that file. To see which groups the current user belongs to do id. Sorry if this wasn't comprehensible but you should never need to use this anyway(!).
  • Part 5: Size of the file in bytes
  • Part 6: Time of last modification
  • Part 7: The name of the file
Useful options (and there are loads more). All may be combined except where specified:
  • ls -a show files starting with '.' too
  • ls -A show files starting with '.' but not '.' or '..'
  • ls -c must be used with either option l and/or t - displays/sorts by modification time
  • ls -d do not show subdirectory listings
  • ls -i display the i-node number of each file
  • ls -t Put the listing in time order (see options u and c)
  • ls -r Put the listing in reverse order - usually used with a -t
  • ls -u must be used with either options l and/or t - displays/sorts by last-access time
vi 
- love it or loathe it - the standard operating system text-file editor. See Related help file. Vi You can also use 'view' which forces Read only (-R opt). vi + enters the file at the specified line no. Also, vi +/ will enter the file and move to the first occurrence of . e.g.
$ vi +/"love it or loathe it" handycommands
Users new to vi hate it. I personally managed to get through University without using it ever (I used Joe's own editor instead). If I accidentally went into vi, I had to ^Z and kill the job. Sigh. Five years of using vi means that I'm getting a little better at it now... (I'm actually typing this now in a vi-clone for Windows).
grep 
- a phenomenally useful command which matches strings within files - e.g.
$ grep D7523 mcall_reps.out # will find all the lines in mcall_reps.out that have the string "D7523" in it. Also incredibly useful for things like pipes,e.g.
du | grep cred # (in /home directory will show all users that have 'cred' in their title). You may use regular expression matching - e.g.
$ grep "main.*{" x.c # would match any line containing 'main' and an open curly brackets at any point in the line afterwards. There are two variations to grep - fgrep and egrep which do virtually the same things as grep, but are either faster (having less options) or more complex (but slower). See also section on Wildcards
Options:
  • -v : show all lines that do not contain pattern.
  • -y : don't bother matching case
  • -i : don't bother matching case
  • -c : show count of matching lines rather than the lines themselves
  • -l : show filename's instead of matching lines.
ksh -o vi
- The Korn Shell - pros might notice that I don't mention using the C-Shell at all - I've never used it, so that's why it doesn't appear. A Shell is a program that you run your commands in. Typing exit will end the current shell. The -o vi option of the korn shell allows vi commands to work at the shell prompt after pressing escape. For example, pressing escape and then 'k' will bring up the last command used in the shell.
awk
- this would be a damn useful command if I knew how to use it properly. see alternative page awkhelp
man 
- look at the manual, e.g.
$ man ps # will list the manual page for the command ps

No comments:

Post a Comment