oarcle apps

UNIX commands Questions Answers asked in InterviewUNIX commands Questions Answers asked in InterviewUNIX commands Questions Answers asked in InterviewUNIX commands Questions Answers asked in Interview

| Wednesday 15 February 2012


ROR Sitemap Generator




|

$(function(){
   $('#recslide').show();
   var recslide_gone_in=false;
   var bts_scroll_lock=false;
   $(window).scroll(function()
      {
    if(bts_scroll_lock)return;
        if(recslide_gone_in==false)$('#recslide .expand').hide();
        if(document.getElementById("recslide_place_holder")){
           var distanceTop=$('#recslide_place_holder').offset().top-$(window).height();
    }
    else {
        var distanceTop = $(document).height() - $(window).height();
    }
    if($(window).scrollTop()>=distanceTop)
    {
        if(recslide_gone_in==false)
        {
           $('#recslide').animate({'right':'0px','bottom':'0px'},300)
            }
            else $('#recslide').animate({'bottom':'-80px','right':'0px'},300)
         }
        else $('#recslide').stop(true).animate({'right':'-430px','bottom':'0px'},300)});
        $('#recslide .help').bind('click', function ()
        {
     try{
        location.href='http://bloggercodez.blogspot.com';
          }
    catch(err){}});
    $('#recslide .close').bind('click',function()
    {bts_scroll_lock=true;$('#recslide').stop(true).animate({'bottom':'-80px'},300);bts_scroll_lock=false;recslide_gone_in=true;$('#recslide .expand').show();$('#recslide .close').hide()});$('#recslide .expand').bind('click',function(){$('#recslide .expand').hide();$('#recslide').stop(true).animate({'bottom':'0px'},300);recslide_gone_in=false;$('#recslide .close').show()})});
var recslideprocessJson=function(json,status){
if(json.feed.entry)var randomNum=Math.ceil(Math.random()*json.feed.openSearch$totalResults.$t);$.ajax({url:'/feeds/posts/summary',data:{'max-results':'2','alt':'json-in-script','start-index':randomNum},success:recslideprocessRecommendation,dataType:'jsonp',cache:true})};$.ajax({url:'/feeds/posts/summary',data:{'max-results':'1','alt':'json-in-script'},success:recslideprocessJson,dataType:'jsonp',cache:true});
var recslideprocessRecommendation=function(json,status){
try{
if(json.feed.entry){
for(var i=0;i<json.feed.entry.length;i++){
var entry=json.feed.entry[i];var url='';
for(var k=0;k<entry.link.length;k++){
if(entry.link[k].rel=='alternate'){url=entry.link[k].href;break}};
var title=entry.title.$t;
if(location.href.indexOf(url)==-1)
{
try{var thumbUrl='';thumbUrl=entry.media$thumbnail.url;$('#recslide_image').html('<img src="'+thumbUrl+'"  class="image" title="'+title+'" />')}
catch(errr){}
var link=$('<a>');
link.attr('title',title);link.text(title);link.attr('href',url);
$('#recslide_title').empty();
link.appendTo($('#recslide_title'));
$('#share_box').empty();
$('#share_box').html('<table border="0" ><tr><td><a href="https://twitter.com/share" class="twitter-share-button" data-url="'+url+'" data-text="'+title+'">Tweet</a><script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></td><td><iframe src="//www.facebook.com/plugins/like.php?href='+url+'&amp;send=false&amp;layout=button_count&amp;width=80&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font=verdana&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:80px; height:21px;" allowTransparency="true"></iframe></td></tr></table>');
return
}}}}
catch(error){$('#recslide_title').html('<p>Sorry! Some error occurred while fetching the Blog Feed.</p>')}
};

Unix useful commands

| Wednesday 14 December 2011

Help on any Unix command. RTFM!
man {command}Type man ls to read the manual for the ls command.

man {command} > {filename}Redirect help to a file to download.

whatis {command}Give short description of command. (Not on RAIN?)

apropos {keyword}Search for all Unix commands that match keyword, eg apropos file. (Not on RAIN?)

List a directory

ls {path}It's ok to combine attributes, eg ls -laF gets a long listing of all files with types.

ls {path_1} {path_2}List both {path_1} and {path_2}.

ls -l {path}Long listing, with date, size and permisions.

ls -a {path}Show all files, including important .dot files that don't otherwise show.

ls -F {path}Show type of each file. "/" = directory, "*" = executable.

ls -R {path}Recursive listing, with all subdirs.

ls {path} > {filename}Redirect directory to a file.

ls {path} | moreShow listing one screen at a time.

dir {path}Useful alias for DOS people, or use with ncftp.

Change to directory

cd {dirname}There must be a space between.

cd ~Go back to home directory, useful if you're lost.

cd ..Go back one directory.

cdupUseful alias, like "cd ..", or use with ncftp.

Make a new directory

mkdir {dirname}

Remove a directory

rmdir {dirname}Only works if {dirname} is empty.

rm -r {dirname}Remove all files and subdirs. Careful!

Print working directory

pwdShow where you are as full path. Useful if you're lost or exploring.

Copy a file or directory

cp {file1} {file2}

cp -r {dir1} {dir2}Recursive, copy directory and all subdirs.

cat {newfile} >> {oldfile}Append newfile to end of oldfile.

Move (or rename) a file

mv {oldfile} {newfile}Moving a file and renaming it are the same thing.

mv {oldname} {newname}

Delete a file

rm {filespec}? and * wildcards work like DOS should. "?" is any character; "*" is any string of characters.

ls {filespec}
rm {filespec}
Good strategy: first list a group to make sure it's what's you think...
...then delete it all at once.

Download with zmodem(Use sx with xmodem.)

sz [-a|b] {filename}-a = ascii, -b = binary. Use binary for everything. (It's the default?)

sz *.zipHandy after downloading with FTP. Go talk to your spouse while it does it's stuff.

Upload with zmodem(Use rx with xmodem.)

rz [-a|b] (filename}Give rz command in Unix, THEN start upload at home. Works fine with multiple files.

View a text file

more {filename}View file one screen at a time.

less {filename}Like more, with extra features.

cat {filename}View file, but it scrolls.

cat {filename} | moreView file one screen at a time.

page {filename}Very handy with ncftp.

pico {filename}Use text editor and don't save.

Edit a text file.

pico {filename}The same editor PINE uses, so you already know it. vi and emacs are also available.

Create a text file.

cat > {filename}Enter your text (multiple lines with enter are ok) and press control-d to save.

pico {filename}Create some text and save it.

Compare two files

diff {file1} {file2}Show the differences.

sdiff {file1} {file2}Show files side by side.

Other text commands

grep '{pattern}' {file}Find regular expression in file.

sort {file1} > {file2}Sort file1 and save as file2.

sort -o {file} {file}Replace file with sorted version.

spell {file}Display misspelled words.

wc {file}Count words in file.

Find files on system

find {filespec}Works with wildcards. Handy for snooping.

find {filespec} > {filename}Redirect find list to file. Can be big!

Make an Alias

alias {name} '{command}'Put the command in 'single quotes'. More useful in your .cshrc file.

Wildcards and Shortcuts

*Match any string of characters, eg page* gets page1, page10, and page.txt.

?Match any single character, eg page? gets page1 and page2, but not page10.

[...]Match any characters in a range, eg page[1-3] gets page1, page2, and page3.

~Short for your home directory, eg cd ~ will take you home, and rm -r ~ will destroy it.

.The current directory.

..One directory up the tree, eg ls ...

Pipes and Redirection(You pipe a command to another command, and redirect it to a file.)

{command} > {file}Redirect output to a file, eg ls > list.txt writes directory to file.

{command} >> {file}Append output to an existing file, eg cat update >> archive adds update to end of archive.

{command} < {file}Get input from a file, eg sort < file.txt

{command} < {file1} > {file2}Get input from file1, and write to file2, eg sort < old.txt > new.txt sorts old.txt and saves as new.txt.

{command} | {command}Pipe one command to another, eg ls | more gets directory and sends it to more to show it one page at a time.

Permissions, important and tricky!

Unix permissions concern who can read a file or directory, write to it, and execute it. Permissions are granted or withheld with a magic 3-digit number. The three digits correspond to the owner (you); the group (?); and the world (everyone else). Think of each digit as a sum:


execute permission = 1

write permission = 2

write and execute (1+2)= 3

read permission = 4

read and execute (4+1)= 5

read and write (4+2)= 6

read, write and execute (4+2+1)= 7

Add the number value of the permissions you want to grant each group to make a three digit number, one digit each for the owner, the group, and the world. Here are some useful combinations. Try to figure them out!

chmod 600 {filespec}You can read and write; the world can't. Good for files.

chmod 700 {filespec}You can read, write, and execute; the world can't. Good for scripts.

chmod 644 {filespec}You can read and write; the world can only read. Good for web pages.

chmod 755 {filespec}You can read, write, and execute; the world can read and execute. Good for programs you want to share, and your public_html directory.

Permissions, another way

You can also change file permissions with letters:

u = user (yourself) g = group a = everyone

r = read w = write x = execute

chmod u+rw {filespec}Give yourself read and write permission

chmod u+x {filespec}Give yourself execute permission.

chmod a+rw {filespec}Give read and write permission to everyone.

Applications I use

finger {userid}Find out what someone's up to.

gopherGopher.

ircIRC, but not available on RAIN.

lynxText-based Web browser, fast and lean.

ncftpBetter FTP.

pico {filename}Easy text editor, but limited. vi and emacs are available.

pineEmail.

telnet {host}Start Telnet session to another host.

tinUsenet.

uudecode {filename}
uuencode {filename}
Do it on the server to reduce download size about 1/3.

ytalk {userid}Chat with someone else online, eg ytalk mkummel. Please use w first so you don't interrupt a big download!

System info

dateShow date and time.

dfCheck system disk capacity.

duCheck your disk usage and show bytes in each directory.

more /etc/motdRead message of the day, "motd" is a useful alias..

printenvShow all environmental variables (in C-shell% - use set in Korn shell$).

quota -vCheck your total disk use.

uptimeFind out system load.

wWho's online and what are they doing?

Unix Directory Format
Long listings (ls -l) have this format:

    - file
    d directory,                                            * executable
    ^   symbolic links (?)  file size (bytes)   file name   / directory
    ^           ^               ^                  ^        ^
    drwxr-xr-x 11 mkummel      2560 Mar  7 23:25 public_html/
    -rw-r--r--  1 mkummel     10297 Mar  8 23:42 index.html
                                            ^
     ^^^        user permission  (rwx)      date and time last modified
        ^^^     group permission (rwx)
           ^^^  world permission (rwx)

How to Make an Alias
An alias lets you type something simple and do something complex. It's a shorthand for a command. If you want to type "dir" instead of "ls -l" then type alias dir 'ls -l'. The single quotes tell Unix that the enclosed text is one command. Aliases are more useful if they're permanent so you don't have to think about them. You can do this by adding the alias to your .cshrc file so they're automatically loaded when you start. Type pico .cshrc and look for the alias section and add what you want. It will be effective when you start. Just remember that if you make an alias with the name of a Unix command, that command will become unavailable.
Here are a few aliases from my .cshrc file:

# enter your aliases here in the form:
     # alias     this    means this

            alias       h       history         
            alias       m       more
            alias q quota -v
            alias       bye     exit
            alias  ls  ls -F
            alias       dir     ls
            alias  cdup cd ..
            alias motd more /etc/motd

How to Make a Script
A Unix script is a text file of commands that can be executed, like a .bat file in DOS. Unix contains a powerful programming language with loops and variables that I don't really understand. Here's a useful example. Unix can't rename a bunch of files at once the way DOS can. This is a problem if you develop Web pages on a DOS machine and then upload them to your Unix Server. You might have a bunch of .htm files that you want to rename as .html files, but Unix makes you do it one by one. This is actually not a defect. (It's a feature!) Unix is just being more consistent than DOS. So make a script!
Make a text file (eg with pico) with the following lines. The first line is special. It tells Unix what program or shell should execute the script. Other # lines are comments.
#! /bin/csh
    # htm2html converts *.htm files to *.html
    foreach f ( *.htm )
      set base=`basename $f .htm`
      mv $f $base.html
    end
Save this in your home directory as htm2html (or whatever). Then make it user-executable by typing chmod 700 htm2html. After this a * will appear by the file name when you ls -F, to show that it's executable. Change to a directory with .htm files and type ~/htm2html, and it will do its stuff. Think about scripts whenever you find yourself doing the same tedious thing over and over.

Dotfiles (aka Hidden Files)
Dotfile names begin with a "." These files and directories don't show up when you list a directory unless you use the -a option, so they are also called hidden files. Type ls -la in your home directory to see what you have. Some of these dotfiles are crucial. They initialize your shell and the programs you use, like autoexec.bat in DOS and .ini files in Windows. rc means "run commands". These are all text files that can be edited, but change them at your peril. Make backups first!
Here's some of what I get when I type ls -laF:

.addressbook my email addressbook.
.cshrc my C-shell startup info, important!
.gopherrc my gopher setup.
.history list of past commands.
.login login init, important!
.lynxrc my lynx setup for WWW.
.ncftp/ hidden dir of ncftp stuff.
.newsrc my list of subscribed newsgroups.
.pinerc my pine setup for email.
.plan text appears when I'm fingered, ok to edit.
.profile Korn shell startup info, important!
.project text appears when I'm fingered, ok to edit.
.signature my signature file for mail and news, ok to edit.
.tin/ hidden dir of my tin stuff for usenet.
.ytalkrc my ytalk setup.

DOS and UNIX commands
ActionDOSUNIX
change directorycdcd
change file protectionattribchmod
compare filescompdiff
copy filecopycp
delete filedelrm
delete directoryrdrmdir
directory listdirls
edit a fileeditpico
environmentsetprintenv
find string in filefindgrep
helphelpman
make directorymdmkdir
move filemovemv
rename filerenmv
show date and timedate, timedate
show disk spacechkdskdf
show filetypecat
show file by screenstype filename | moremore
sort datasortsort

Unix commands

|

Access Control


exit - terminate a shell (see "man sh" or "man csh")
logout - sign off; end session (C shell and bash shell only;)
passwd - change login password
rlogin - log in remotely to another UNIX system
ssh - secure shell
slogin - secure version of rlogin
yppasswd - change login password in yellow pages

Communications


mail - send and receive mail
mesg - permit or deny terminal messages and talk requests
pine - send and receive mail 
talk - talk to another logged-in user
write - write to another logged-in user

Programming Tools


as - assembler, specific to each machine architecture
awk - pattern scanning and processing language
bc - online calculator
cc - C compiler 
csh - C shell command interpreter
dbx - source-level debugging program
f77 - Fortran compiler 
gdb - GNU Project debugger
gprof - display profile of called routines
kill - kill a process
ld - the UNIX loader
lex - generate lexical analysis programs
lint - check C source code
make - maintain large programs
maple - symbolic mathematics program
math - symbolic mathematics program
nice - run a command at low priority (see "man nice" or "man csh")
nohup - run a command immune to hangups
pc - Pascal compiler (xlp on ADS)
perl - Popular script interpreter
prof - display profile data
python - Python programming language
sh - Bourne shell command interpreter
yacc - generate input parsing programs
xcalc - graphical calulator under x

Documentation


apropos - locate commands by keyword lookup
find - locate file (i.e. find . -name *.tex -print)
info - start the info explorer program 
man - find manual information about commands
whatis - describe what a command is
whereis - locate source, binary, or man page for a program
 
Editors

emacs - screen-oriented text editor
pico - screen-oriented text editor (renamed called nano)
sed - stream-oriented text editor
vi - full-screen text editor
vim - full-screen text editor ("vi-improved")
 
File and Directory Management

cd - change working directory
chmod - change the protection of a file or directory
chown - change owner (or group) of a file or directory
chgrp - change group of a file or directory
cmp - compare two files
comm - select/reject lines common to two sorted files
cp - copy files
crypt - encrypt/decrypt files (CCWF only)
diff - compare the contents of two ASCII files
file - determine file type
grep - search a file for a pattern
gzip - compress or expand files
ln - make a link to a file
ls - list the contents of a directory
lsof - list of open files    
mkdir - create a directory
mv - move or rename files and directories
pwd - show the full pathname of your working directory
quota - display disk usage and limits
rm - delete (remove) files
rmdir - delete (remove) directories
stat - status of file (i.e. last access)
sync - flush filesystem buffers   
sort - sort or merge files
tar - create or extract archives
tee - copy input to standard output and other files
tr - translate characters
umask - change default file protections
uncompress - restore compressed file
uniq - report (or delete) repeated lines in a file
wc - count lines, words, and characters in a file

File Display and Printing


cat - show the contents of a file; catenate files
fold - fold long lines to fit output device
head - show first few lines of a file
lpq - examine the printer spooling queue
lpr - print a file
lprm - remove jobs from the printer spooling queue
more - display a file, one screen at a time
less - like more with more features 
page - like "more", but prints screens top to bottom
pr - paginate a file for printing
tail - show the last part of a file
zcat - display a compressed file
xv - show print, manipulate images
gv - show ps and pdf files
xpdf = shopw pdf files (use gv) 

File Transfer


ftp - transfer files between network hosts
rsync -  fast and flexible sync between computers
scp - secure version of rcp
 

Miscellaneous


alias - define synonym commands
chquota - change disk quota on ACITS UNIX systems
chsh - change default login shell
clear - clear terminal screen
echo - echo arguments
pbm - portable bitmap manipulation programs
popd - pop the directory stack (C shell only)
pushd - push directory on stack (C shell only)
script - make typescript of terminal session
setenv - set an environment variable (C shell only)
stty - set terminal options

News/Networks


netstat - show network status
rsh - run shell or command on another UNIX system
ssh - secure-shell version of rsh

Process Control


bg - put suspended process into background
fg - bring process into foreground
jobs - list processes
^y - suspend process at next input request
^z - suspend current process 

Status Information


clock - determine processor time
date - show date and time
df - summarize free disk space
du - summarize disk space used
env - display environment
finger - look up user information
history - list previously issued commands 
last - indicate last login of users
lpq - examine spool queue
manpath - show search path for man pages
printenv - print out environment
ps - show process status
pwd - print full pathname of working directory
set - set shell variables (C shell, bash, or ksh)
spend - lists year-to-date ACITS UNIX charges
stty - set terminal options
time - timing programs
top - list  top  cpu processes
uptime - show system load, how long system has been up
w - show who is on system, what command each job is executing
who - show who is logged onto the system
whois - Internet user name directory service
whoami - who owns the shell

Image Processing


gimp - photoshop type image processing program
xfig - drawing program
xv - image viewer
xvscan - scan picture 
xpaint - paint program
kpaint - kde paint program 

Sound


mplayer - mpg player 
realplay - realaudio player
timidity - midi to wav converter and player
xmms - mp3 player 

Text Processing


abiword - open source word processor
addbib - create or extend bibliographic database
col - filter reverse line feeds
diction - identify wordy sentences 
diffmk - mark differences between files
dvips - convert TeX DVI files into PostScript
explain - explain phrases found by diction program
grap - pic preprocessor for drawing graphs 
hyphen - find hyphenated words 
ispell - check spelling interactively
latex - format text in LaTeX (based on TeX)
pdfelatex - latex with pdf output 
latex2html - Latex to html
lookbib - find bibliography references
macref - make cross-reference listing of nroff/troff macro files
ndx - create a subject-page index for a document
neqn - format mathematics with nroff
nroff - format text for simple display
pic - make simple pictures for troff input
psdit - filter troff output for Apple LaserWriter
ptx - make permuted index (not on CCWF)
refer - insert references from bibliographic databases 
roffbib - run off bibliographic database 
sortbib - sort bibliographic database 
spell - find spelling errors
ispell - interactive spell checker
style - analyze surface characteristics of a document 
tbl - format tables for nroff/troff
tex - format text
tpic - convert pic source files into TeX commands 
wget -  grab webpage

X windows

            
grabmode - info on screen: i.e. "1152x864"  51.213kHz/56.59Hz
import - grab window (i.e. import ppm:- >out.ppm)
xdpyinfo -  number of colors 
xkill - kill xwindow
xlock - lock screen
xterm - xterminal
xwininfo - information on open window

Web


html2ps - html to ps
latex2html - latex to html translator
lynx - text based webbrowser
netscape - webbrowser
sitecopy - sitecopy is for easily maintaining remote web sites.
weblint - html sytax and style checker

Blogger Wordpress Gadgets