A store procedure to insert values into multitable without duplicate records

The previous store procedure have records repeated and here is the improve one.

the table like this:

tables

 


  
CREATE PROCEDURE [dbo].[spStoreLMStatusRecording]       
@parameterJobID varchar(30),  
@parameterLMStatus nvarchar(10),  
@parameterEntry_datetime datetime   
   
AS  
BEGIN  
declare   
 @username varchar(500),  
 @Job_Acceptance bit   
    SET @Job_Acceptance = '1'  
   
   
 IF NOT EXISTS(SELECT * FROM tblJob where JobID = @parameterJobID)    
 begin   
  insert into tblJob values(@parameterJobID,@Job_Acceptance);  
  select @username = username from tblUserAuthentication    
  insert into tblLMStatus values(@parameterLMStatus,@parameterEntry_datetime,@parameterJobID,@username)  
 end  
 else  
 begin  
  select @username = username from tblUserAuthentication    
  insert into tblLMStatus values(@parameterLMStatus,@parameterEntry_datetime,@parameterJobID,@username)  
 end  
   
END  

Cookies in ASP.NET

Cookies is a small piece of information stored on the client machine. This file is located on client machines “C:\Document and Settings\Currently_Login user\Cookie” path.  Its is used to store user preference information like Username, Password,City and PhoneNo etc on client machines. We need to import namespace called  Systen.Web.HttpCookie before we use cookie.
 
Type of Cookies?

  1. Persist Cookie – A cookie has not have expired time Which is called as Persist Cookie

  2. Non-Persist Cookie – A cookie has expired time Which is called as Non-Persist Cookie

How to create a cookie?
 
Its really easy to create a cookie in the Asp.Net with help of Response object or HttpCookie
 
Example 1:
 
        HttpCookie userInfo = new HttpCookie(“userInfo”);
        userInfo["UserName"] = “Annathurai”;
        userInfo["UserColor"] = “Black”;
        userInfo.Expires.Add(new TimeSpan(0, 1, 0));
        Response.Cookies.Add(userInfo);

Example 2:
 
        Response.Cookies["userName"].Value = “Annathurai”;
        Response.Cookies["userColor"].Value = “Black”;
                       
How to retrieve from cookie?

Its easy way to retrieve cookie value form cookes by help of Request object.
 
Example 1:
 
        string User_Name = string.Empty;
        string User_Color = string.Empty;
        User_Name = Request.Cookies["userName"].Value;
        User_Color = Request.Cookies["userColor"].Value;

Example 2:
 
        string User_name = string.Empty;
        string User_color = string.Empty;
        HttpCookie reqCookies = Request.Cookies["userInfo"];
        if (reqCookies != null)
        {
            User_name = reqCookies["UserName"].ToString();
            User_color = reqCookies["UserColor"].ToString();
        }
 
When we make request from client to web server, the web server process the request and give the lot of information with big pockets  which will have Header information, Metadata, cookies etc., Then repose object can do all the things with browser.

Cookie’s common property:

  1. Domain => Which is used to associate cookies to domain.

  2. Secure  => We can enable secure cookie to set true(HTTPs).

  3. Value    => We can manipulate individual cookie.

  4. Values  => We can manipulate cookies with key/value pair.

  5. Expires => Which is used to set expire date for the cookies.

Advantages of Cookie:

  1. Its clear text so user can able to read it.

  2. We can store user preference information on the client machine.

  3. Its easy way to maintain.

  4. Fast accessing.

Disadvantages of Cookie

  1. If user clear cookie information we can’t get it back.

  2. No security.

  3. Each request will have cookie information with page.

How to clear the cookie information?

 

  • we can clear cookie information from client machine on cookie folder

 

  1. To set expires to cookie object
    userInfo.Expires = DateTime.Now.AddHours(1);
    It will clear the cookie with one hour duration.

 

This article  is copy from http://www.c-sharpcorner.com/uploadfile/annathurai/cookies-in-Asp-Net/ some article is very useful, I past it here, so I could use it  when I need it.

How to create or customize drupal theme

I thought that I am programmer, but recently I also did a lot of front end job. This post will help the guys want to find out how to customize drupal theme.

For customize or create a new drupal theme, you don’t need to understand the php just need some knowledge about the HTML and CSS then will make you successfully create or customize drupla theme.

First, you need understand the construction of the drupal page. See below the picture, that is the most common useful template.

drupal_template1

Second, here is your theme direction should look like

drupal_theme2

third, those three need have the same name

drupal_theme3

Now we could start now. go to find this file

drupal_theme4

here is the header

drupal_theme6

drupal_theme7

Here is your page.tpl.php

drupal_theme9

the rest of just css and javascript:

drupal_theme10

drupal_theme11

 

 

 

 

 

 

Bootrap Jumbotron into WordPress Theme

In this post I will use a bootstrap Jumbotron template,here is the link http://getbootstrap.com/examples/jumbotron/  I will  customize it into wordpress theme

You need download bootstrap into” yourtheme “folder, whatever theme name you like to call it.

bootstrap_to_wordpress2

 

Those fold should inside your theme folder, don’t worry what are inside it except everything from bootstrap, the other file is empty now.

1) for wordpress could read you theme you need put those on top of your style.css:

/*
Theme Name: Bootstrap to WordPress
Theme URI: http://sandywebdesigner.com
Author: Sandy Zhang
Author URI: http://sandywebdesigner.com
Description: Example theme for  how to convert static Bootstrap site into dynamic WordPress theme
Version: 1.0
License:
License URI:
Text Domain: bootstrap-to-wp

This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you’ve learned with others.
*/

/* Move down content because we have a fixed navbar that is 50px tall */
body {
padding-top: 50px;
padding-bottom: 20px;
}
.admin-bar .navbar-fixed-top {
margin-top: 30px;
}
/* Below is the style for navigation in functions.php add a class to sub-menu to the navigation so I just write a simple style to it,you could customize it by yourself */
@media (min-width:768px) {
.sub-menu {
display: none;
position: absolute;
background: #222;
padding: 10px 15px;
width: 150px;
}

li:hover .sub-menu {
display: block;
}

}

.sub-menu li {
margin-bottom: 10px;
list-style: none;
}

.sub-menu li:last-child {
margin-bottom: 0;
}

.sub-menu a  {
color: #999;
text-decoration: none;
}

.sub-menu a:hover  {
color: #fff;
}

.current-menu-item > a, .current-menu-parent > a {
background: #000;
}
.current-menu-parent li a {
background: inherit;
}
.current-menu-parent .current-menu-item a {
color: #fff;
font-weight: bold;
}

.sidebar{
margin-top:40px;
color:#444;
}
.sidebar h3{
color:#888;
}
.widget{
margin:10px 0 30px;
}
article .post{
margin:20px 0;
}

.featured-image img,
.portfolio-piece img,
.portfolio-image img {
max-width:100%;
}

.prev-next{
font-size:24px;
margin-top:30px;
text-align:right;
}

@media (max-width:540px) {
.portfolio-piece h4{
font-size:.8em;
}
.prev-next{
font-size:15px;
margin-top:15px;
text-align:right;
}

}

2)header.php

<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset=”<?php bloginfo( ‘charset’ ); ?>”>
<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link rel=”shortcut icon” href=”<?php bloginfo(‘template_directory’);?>/images/favicon.ico”>

<title>
<?php wp_title(‘|’,true,’right’);?>
<?php bloginfo(‘name’)?>

</title>

<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>

<div class=”navbar navbar-inverse navbar-fixed-top” role=”navigation”>
<div class=”container”>
<div class=”navbar-header”>
<button type=”button” class=”navbar-toggle” data-toggle=”collapse” data-target=”.navbar-collapse”>
<span class=”sr-only”>Toggle navigation</span>
<span class=”icon-bar”></span>
<span class=”icon-bar”></span>
<span class=”icon-bar”></span>
</button>
<a class=”navbar-brand” href=”<?php bloginfo(‘url’); ?>”><?php bloginfo(‘name’); ?></a>
</div>
<div class=”navbar-collapse collapse”>
<?php
$args = array(
‘menu’ => ‘mainmenu’,
‘menu_class’ => ‘nav navbar-nav’,
‘container’ => ‘false’
);
wp_nav_menu($args);
?>
</div><!–/.navbar-collapse –>
</div>
</div>

3)footer.php

<hr>

<footer>
<p>&copy; <?php bloginfo(‘name’);?> <?php echo date(‘Y’); ?></p>
</footer>
</div> <!– /container –>
<?php wp_footer(); ?>
</body>
</html>

3)index.php

<?php get_header(); ?>

<div class=”container”>

<div class=”row”>
<div class=”col-md-9″>
<?php if(have_posts()):while(have_posts()):the_post();?>
<div class=”Page-header”>
<h1><?php the_title(); ?></h1>
</div>
<?php the_content();?>
<?php endwhile; else:?>

<div class=”Page-header”>
<h1>Oh no!</h1>
</div>
<p>No content is appearing for this page!</p>
<?php the_content();?>

<?php endif;?>

</div>
<?php get_sidebar(); ?>

</div>

<?php get_footer(); ?>

4)functions.php

<?php
function theme_styles(){
wp_enqueue_style( ‘bootstrap_css’, get_template_directory_uri() . ‘/css/bootstrap.min.css’ );
wp_enqueue_style( ‘main_css’, get_template_directory_uri() . ‘/style.css’ );
}
add_action( ‘wp_enqueue_scripts’, ‘theme_styles’ );

function theme_js(){
global $wp_scripts;
wp_register_script( ‘html5_shiv’, ‘https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js&#8217;, ”, ”, false );

wp_register_script( ‘respond_js’, ‘https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js&#8217;, ”, ”, false );

$wp_scripts->add_data( ‘html5_shiv’, ‘conditional’, ‘lt IE 9′ );
$wp_scripts->add_data( ‘respond_js’, ‘conditional’, ‘lt IE 9′ );
wp_enqueue_script( ‘bootstrap_js’, get_template_directory_uri() . ‘/js/bootstrap.min.js’, array(‘jquery’), ”, true );
wp_enqueue_script( ‘theme_js’, get_template_directory_uri() . ‘/js/theme.js’, array(‘jquery’,’bootstrap_js’), ”, true );

}

add_action( ‘wp_enqueue_scripts’, ‘theme_js’ );

add_theme_support(‘menus’);
add_theme_support(‘post-thumbnails’);

function register_theme_menus() {
register_nav_menus(
array(
‘header-menu’    => __( ‘mainmenu’ )
)
);
}
add_action( ‘init’, ‘register_theme_menus’ );

function create_widget( $name, $id, $description ) {

register_sidebar(array(
‘name’ => __( $name ),
‘id’ => $id,
‘description’ => __( $description ),
‘before_widget’ => ‘<div class=”widget”>’,
‘after_widget’ => ‘</div>’,
‘before_title’ => ‘<h2>’,
‘after_title’ => ‘</h2>’
));
}

create_widget( ‘Front Page Left’, ‘front-left’, ‘Displays on the left of the homepage’ );
create_widget( ‘Front Page Center’, ‘front-center’, ‘Displays in the center of the homepage’ );
create_widget( ‘Front Page Right’, ‘front-right’, ‘Displays on the right of the homepage’ );
?>

See how simple it is, index.php you completed, then use this index.php to create other template like page.php. single.php, etc. Have fun!

 

 

 

 

 

 

How to customize your own WordPress Theme

Once you could write HTML and CSS website template, then you will be able to customize it to

WordPress Theme.

For to do that, there is some basic thing you need know:

1)Need understand WordPress Template Hierarchy, if you don’t knwo before, don’t scare.
Here is few template you must have in your theme folder.

Index.php //  main Theme templateindex.php
page.php //this is the static page template in wordpress
single.php //this is post page template
home.php // blog template
front-page.php//shown On front
archive.php// for archive page template
search.php// if you don’t have wordpree will use index.php

For more detail could go to http://codex.wordpress.org/Template_Hierarchy

2) WordPress cut page into pieces, so onece you have the html and css page, then slide it into
header.php, footer.php, sidebar.php(if you design have sidebar)

3)Here is the basic function you need it.
The path of style.css is: <?php bloginfo( ‘stylesheet_url’ ); ?>
The path of the theme folder: <?php bloginfo(‘template_directory’); ?>
<?php get_header();?> //this is for you get your header
<?php get_footer();?> // this is for you get your footer
<?php get_sidebar();?> //this is for you get your sidebar, if you have sidebar in your design

<?php if(have_posts()):while(have_posts()):the_post();?>
<?php endwhile; else:?>//this loop is very important,will be use for a lot of times when you

create a wordpress theme

In next post I will use a bootstrap Jumbotron template,here is the link http://getbootstrap.com/examples/jumbotron/  I will  customize it into wordpress theme

Chapter 8: Web Development

1. Html elementary
Create a web page accessible at the URL http://localhost/~student/text.html and within this page insert five headings from largest to smallest heading types. Insert also at least two paragraphs of text, and make some of the text in this page “bold” and some of it “emphasized”.

vim filename.html
<html>
<bold> </bold>
<em> </em>
<h1> </h1> x 5
</html>

 
2. Html hyperlink
Create an HTML web page accessible at the URL http://localhost/~student/extlink.html with exactly one anchor tag linking to http://www.google.com

vim extlink.html
<html>
< a href = “
http://www.google.com”>

 
3. Html preformat
Create a web page accessible at the URL http://localhost/~student/preformat.html and within this page insert two elements: one paragraph, and one block of preformatted text.

vim preformat.html
<p></p>
<pre></pre>

 
4. Html list
Create a web page accessible at the URL http://localhost/~student/list.html. Create within this file only one ordered list with 4 list items. The items may contain any text or html. (You can check your answer by browsing to http://localhost/~student/list.html)

vim list.html
<html>
<ol>
<li> coffee </li>
<li> milk </li>
<li> hot chocolate </li>
<li> tea </li>
</ol>
</html>

 
5. Html table
Create a web page accessible at the URL http://localhost/~student/table.html containing a table with 2 rows and 4 columns, each cell containing a small amount of text.

vim table.html
<tr> </tr> x 2
<td> </td> x 4

 
6. Html picture
Copy the image file /usr/local/linuxgym-data/public_html/fish.jpg into your public_html directory. It should be viewable by following the link http://localhost/~student/fish.jpg Create an HTML web page accessible at the URL http://localhost/~student/picture.html displaying the fish.jpg image, together with some explanatory text.

cp /usr/local/linuxgym-data/public_html/fish.jpg   fish.jpg
vim picture.html
<html>
<img src = “fish.jpg” alt = “Big Fish”>
</html>

 
7. Html index
An index.html file is automatically accessed by the browser without specifying the filename. The goal of this exercise is to create an HTML web page accessible at the URL http://localhost/~student/ As the “front page” of this chapter, give the index.html page links to several other pages in your public_html directory without using “http” in the address. This is called a “relative link”. (A link using “http” in the address is called “absolute”.)

vim index.html
<html>
<a href = “picture.html”>
<a href = “table.html”>
etc
</html>

Chapter 6: Data Processing

In this chapter we will utilise the skills attained in previous chapters to analyse statistics on the popularity of female names. The data to be analysed is in the file /usr/local/linuxgym-data/census/femalenames.txt with each line conaining NAME, FREQUENCY, CUMULATIVE FREQUENCY, and RANK, where RANK=1 is the most popular name. The file is ordered by RANK.
Topics and commands covered: – searching through data (grep -[lvw]); – comparing contents of files (diff); – data manipulation (uniq, sort, join).

1. List manipulation

Create a file called “table.csv” containing all the lines of /usr/local/linuxgym-data/census/femalenames.txt with all white space between words changed into a single comma. For example, the line: MARY 2.629 2.629 1 will become MARY,2.629,2.629,1 Make no other changes. Hints: 1. Notice that the regular expression “\s\+” means “a sequence of one of more white spaces”. 2. Ensure there is no extra whitespace in the file
cat /usr/local/linuxgym-data/census/femalenames.txt > table.csv
Vim table..csv
:%s/\s\+/,/g
:%s(substitute on every line in the file)/abc/ABC/g(replace all occuraences in the line – not just the first)
\s\+ = white space

2. List sorting

Create a file called “alphabetical.txt” in your “ch6-data” directory containing the lines of /usr/local/linuxgym-data/census/femalenames.txt ordered alphabetically by NAME. Ensure that there are no other changes to the data. (Hint: Use “sort” and redirection.)

vim – insert mode
: sort
Or
Cat ………/femalenames.txt | sort > alphabetical.txt

3. List cut

Create a file called “names.txt” containing only the first column of /usr/local/linuxgym-data/census/femalenames.txt in its existing order. Ensure that there are no other changes to the data. (Hint: Use the command “cut” together with its field and delimiter options.)
vim – insert mode
cut –f1 –d (filename/path) > filename.txt

Or
Cat ……femailes.txt | cut –f1 –d’ ‘ > names.txt
-f1(field 1 to be printed), -d (the comma is the delimiter which separates the fields)

4. Search prefix

Create a bash script called searchprefix.sh which takes two arguments, a string and a file (in that order). The output should be each line which matches the string *from the beginning of the line*. For example, given a string “ANA” the line starting with “ANABEL” will be printed, but the line starting with “SUSANA” will not. (Hint: Use grep and ^ to indicate the beginning of the line).

vim
#!/bin/bash
cat $2 | grep ^$1

5. Multiple file string detection

Create a file called “anne-files.txt” containing the list of names of files in /usr/local/linuxgym-data/gutenberg which contain the STRING ‘Anne’ inside them (including Annemarie and Annetta). Ensure there is one filename per line (WITH THE FULL PATHNAME), that there are no extra blank lines in anne-files.txt, and that no filename occurs more than once. Each line should ONLY contain the filename, no additional detail. [Hint: use grep]

vim
egrep –l “Anne” path/filename/* > filename.txt
Grep -l ‘Anne’ ………/Gutenberg/* > anne-files.txt
(-l, — files with matches only print FILE names containing matches)
6. Grep and words

Create a file called “anne-words.txt” containing only the lines of “/usr/local/linuxgym-data/gutenberg/12frd10.txt” containing the name (WORD) ‘Anne’. Note that ‘Annette’ and ‘Annemarie’ do not count. Ensure there are no extra blank lines in the file “anne-words.txt” and the lines should be in the same order as in 12frd10.txt. [Hint: use grep and redirection]

egrep –w “Anne” path/filename > filename.txt

Grep –w “Anne” ……/Gutenberg/12frd10.txt* > anne-words.txt
(-w, —word – regexp force PATTERN to match only whole words)

7. Grep and regular expressions

Create a file called “natmat.txt” containing, IN THE ORIGINAL ORDER, only the lines of /usr/local/linuxgym-data/census/femalenames.txt starting with the string ‘NAT’ or ‘MAT’. Ensure there is no extra white space in the file “natmat.txt”. [Hint: use regular expressions in grep and redirection]

egrep “^[NM]AT” path/filename > filename.txt

Or
Grep ‘\ natmat.txt
(\ the beginning and end of a world
^, $ match the beginning and end of a line, respectively,
. –full-stop matches any character.)

8. Name frequency

Create a bash script called namefreq.sh which takes one argument – a name. The output should be the FREQUENCY of that name’s use, which is the entry in the second column of /usr/local/linuxgym-data/census/femalenames.txt For example ./namefreq.sh ANA will return 0.120 and nothing else, which corresponds to the line “ANA,0.120,55.989,181″ of the file “table.csv” you created in the “List manipulation” question. Hints: 1. Search “table.csv” instead of “/usr/local/linuxgym-data/census/femalenames.txt”; 2. Grep for “words” rather than strings. 3. Use “cut” to output a particular field.

grep –w $1 filename.txt | cut –f2 –c16-20
(-w for word ANA)
(-c16-20, cut from character number16 to 20)

9. Single file word detection

Write a bash script called gender.sh which takes one argument – a name. The script should print “female” if the word appears in the file /usr/local/linuxgym-data/census/femalenames.txt, and “male” otherwise. Hints: 1. Redirect stdout so it doesn’t get printed, or use the grep “quiet” option; 2. View the exit status $? of grep

vim
#!/bin/bash
egrep –iq $1 path/filename
if [ $? == “0” ]; then
echo “female”
else
echo “male”
fi

10. Same frequency

Challenge question Create a bash script called samefreq.sh which takes one argument – a name. The output should be the alphabetically ordered list of all name’s with the same frequency (popularity) as measured in the second column of the table: /usr/local/linuxgym-data/census/femalenames.txt For example ./namefreq.sh ANA will return a list of two names (on separate lines) ANA and RENEE, both of which have frequency 0.120. Hints: 1. Instead of “/usr/local/linuxgym-data/census/femalenames.txt” search “table.csv” (created in the question “List manipulation” of this chapter) using words rather than strings; 2. Store the frequency of the name using backquotes; 3. Search for the frequency while viewing only the first two columns (use cut) – name and frequency; 4. Sort the final list of names.

vim
#!/bin/bash
f=` grep “\” filename.txt | cut –f2 –d,` ( ` not ‘)
grep “\” filename.txt | cut –f1 –d, | sort –d

Chapter 5: Introduction to Scripting

Scripts are files containing a sequence of commands which can be executed by typing the file name – don’t forget to ensure the file is executable. The first line in a bash script should always be: #!/bin/bash
Topics and commands covered: shebang (#!), echo, parameters ($#, $0, $1, $*,…), assignment (=), arithmetic operators.

CHMOD ALL FILES 777

1. Hello world

Create a script called “print.sh”. This script should print out the string: “Hello world” (do not include the speech marks/inverted commas in the output). [hint: echo]

#!/bin/bash
echo Hello World

2. Echo one parameter

Write a bash script called arg.sh which will print out the SECOND argument to the script. For example, if the script was called as ./arg.sh ay bee cee then the script will output bee and NOTHING ELSE.

#!/bin/bash
echo $2

3. Echo all parameters

Write a bash script called “args.sh” which will print out each argument passed to it. Each argument should be separated by a space only.

#!/bin/bash
echo $@

4. Sum of two parameters

Create a script called add.sh in your home directory. This script should add 724 to its first argument and print out the sum. The sum should be the only thing printed out.

#!/bin/bash
sd=724
sum= $(( $1 + $sd))
echo $sum

5. Product of two parameters

Create a script called mult.sh in your home directory. This script should multiply its first argument by 13 and print out the product. The product should be the only thing printed out.

#!/bin/bash
(we didn’t know the rest)

6. Number of arguments

Write a bash script called numargs.sh which will print out the number of arguments to the script. For example, if the script was called as: ./numargs.sh ay bee cee then the script will output: 3 and NOTHING ELSE.

#!/bin/bash
echo $#

7. Echo to standard error

Write a bash script called “stderr.sh” which will print out all arguments passed to it on a single line sent to STDERR.

#!/bin/bash
echo $* 1>&2
OR
echo $* @>&2
OR
echo $@ls

8. List to standard error

Write a bash script called “lsstderr.sh” which will execute ls on the first argument and output the result to STDERR.

ls $1 > &2

The input stream is referred to as ”standard input”; the output stream is referred to as ”standard output”; and the error stream is referred to as ”standard error”. These terms are abbreviated to form the symbols used to refer to these files, namely stdin, stdout, and stderr.
Redirection in Linux
&0 = stdin
&1 = stdout
&2 = stderr

9. Word count script

Write a bash script called wcscript.sh which will perform the word count on the first argument (a file), and print out the number of words it contains and nothing else. For example, if the script were called on a file a.txt containing 95 words with ./wcscript.sh a.txt it will output: 95 and NOTHING ELSE. [HINT: use "cat" to provide standard input to wc]

cat $1 | wc –w

10. Check number of arguments

Write a bash script called “checknumargs.sh” which will echo to STDOUT all arguments passed to it on a single line IF THE NUMBER OF ARGUMENTS IS 3. If the number of arguments is not 3, then it should echo “error” to STDERR.

#!/bin/bash

if [ $# != 3 ]
then
echo error 1>&2
else
echo $*

fi

Chapter 4: Piping and Wildcards

Concepts: pipes (|), appending (>>, 2>>), wildcards(*,?,[]), recursive list and copy. Commands and their options: wc -[mwl], tail -n, ls -[Rrt], cp -r.

wc: displays a count of lines, words, and characters in a file.
wc –m: Count characters.
wc –w: Count words delimited by white space characters or new line characters.
wc –l: Count lines.

tail: Delivers the last part of the file.
tail –n: n = number the starting location in the file is measured in lines instead of bytes. The origin for counting is 1; that is, -n+1 represents the first line of the file, -n-1 the last.

ls: Lists the contents of a directory.
ls –R: Includes the contents of subdirectories.
ls –r: Reverses the order of how the files are displayed.
ls –t: Shows you the files in modification time.

cp: Copies files from one location to another.
cp –r: copy directories recursively

>> : append standard output to a file (command >> file)
*: wildcard match any number of characters
?:wildcard match one character

1. Word count redirect

Use the command “wc” to count the number of words in the file “/usr/local/linuxgym-data/gutenberg/0ws0310.txt”. Store the exact output of the wc command when used with the “word counts” option in the file “count.txt”. Ensure that the filename within the file contains the full pathname. (Hint: Use redirect “>”).

wc -w /usr/local/linuxgym-data/gutenberg/0ws0310.txt > count.txt

2. Character count piping

Experiment by using the command “cat | wc -m”, typing a few lines, and then using ctrl-D to return to the command prompt. This outputs a single number indicating the number of characters you’ve typed. Unlike the previous question, no filename is printed. Modifying this technique, store the number of characters of the file /usr/local/linuxgym-data/gutenberg/0ws0310.txt into a file called “pipecount.txt” with no other text, such as the filename.

cat | wc –m
type a few lines
ctrl d
cat /usr/local/linuxgym-data/gutenberg/0ws0310.txt | wc –m > pipecount.txt

Or
char=$ wc -m pipecount.txt

3. Wild list

List all the files in the directory /usr/local/linuxgym-data/emptystuff/ which contain the string ‘ws’ in their filename, and put the result in a file called “wsfiles.txt”. Do NOT include the full path, and ensure that there is only one filename per line. (HINT: To avoid getting the full pathname for each file, change directory to /usr/local/linuxgym-data/emptystuff/ so that the ls argument refers to local files.)

touch wsfiles.txt
cd /usr/local/linuxgym-data/emptystuff/
*ws* > ~(ect)/wsfiles.txt

Ls *ws* > /home/student/ch4-pipelines/wsfiles.txt

4. View the end of a file

Store the last 103 lines of the file “/usr/local/linuxgym-data/gutenberg/4mwsm10.txt” into the file “lastlines.txt”. [Hint: Look at the bash function "tail" and its options]

touch lastlines.txt
cat /usr/local/linuxgym-data/gutenberg/4mwsm10.txt | tail -103 > lastlines.txt
or
tail -103 /usr/local/linuxgym-data/gutenberg/4mwsm10.txt > lastlines.txt

5. Append the output

Copy the file /usr/local/linuxgym-data/census/a-j_malenames.txt to a file called appendix.txt in your ch4-pipewild directory. Append to appendix.txt the contents of /usr/local/linuxgym-data/census/k-z_malenames.txt making no other modifications. [Hint: cat, ">>"]

touch appendix.txt
cp /usr/local/linuxgym-data/census/a-j_malenames.txt appendix.txt
cat usr/local/linuxgym-data/census/k-z_malenames.txt >> appendix.txt

6. Listing according to a regular expression

Make a list of all the files from the directory “/usr/local/linuxgym-data/gutenberg” who’s names contain the string “rd” and save this list as “rdfiles.txt”. Ensure that only the filenames are listed WITHOUT the pathnames as a prefix.

touch rdfiles.txt
cd /usr/local/linuxgym-data/Gutenberg
ls *rd* > path/filename.txt

7. Copying according to a regular expression

Create a directory called “s2″ under your “ch4-pipewild” directory. Copy all the files from the directory “/usr/local/linuxgym-data/gutenberg” who’s names contain the string “s2″ into your “ch4-pipewild/s2″ directory.

mkdir s2
cp *s2* /usr/local/linuxgym-data/Gutenberg

or
cd usr/local/linuxgym-data/Gutenberg
ls | grep s2 | xargs cp {} ~/ch4-pipewild/s2

mkdir s2
cd usr/local/linuxgym-data/Gutenberg
ls | grep s2
for i(means every variable) in $( ls | grep s2 ); do cp $i /home/student/ch4-pipeline/s2; done

8. Listing files ordered by their modification time

List the (visible AND hidden) files in the directory “/usr/local/linuxgym-data/spacetime” from least, to most recently modified. Store this list into the file “timeordered.txt”, with only the filenames.

touch timeordered.txt
cd /usr/local/linuxgym-data/spacetime
ls –at > ~(etc)timeordered.txt

9. Copying a directory

Copy the whole directory “/usr/local/linuxgym-data/teeny” and its contents into your “ch4-pipewild” directory. [Hint: You can do it with just one call of cp and recursion.]

cp –r /usr/local/linuxgym-data/teeny teeny

10. Listing files ordered by their size

List the (non-hidden) files in “/usr/local/linuxgym-data/gutenberg” ordered by size from large to small, and store this list in a file called “large_to_small” in your “ch4-pipewild” directory. Include only the file names. Do not include the path prefixes.

touch large_to_small
cd /usr/local/linuxgym-data/Gutenberg
ls –S > ~/ch4-piplewild/large_to_small

Chapter 3: People and Permissions

Chmod

7 = all
4 = read
3 = write & execute
2 = write
1 = execute

Topics covered: concepts: users and groups, permissions, standard error redirection (2>)
Commands and their options: whoami, ls -l, chmod, pwd

1. Who am I

The command “whoami” tells you your userid. Store your userid in the file “myuserid” in your ch3-pp directory. (Hint: Redirect the output using “>”)

mkdir ch3-pp
cd ch3-pp
Touch myuserid
Whoami > myuserid

2. Permissions

Create a file called textperm.txt with permissions as follows: You yourself have permission to read and write; Your group has permission to read; The rest of the world have no permissions whatsoever.

Touch textperm.txt
chmod640 textperm.txt

3. Copy executable

There is only one file in the directory /usr/local/linuxgym-data/permissions which is executable. Copy this file into your ch3-pp directory, giving it the name “executable.sh”.

Cd /usr/local/linuxgym-data/permissions
ls –l
cd ~/ch3-pp
Cp /usr/local/linuxgym-data/permissions(executable file name) executable.sh

4. Execute

Execute the file “executable.sh” which you copied in the previous question, and store the output in the file “ex.out” in your ch3-pp directory. (Hint: Executing a file in the current directory requires the filename being preceeded by “./”. Storing the output is to be done using “>”.)

touch ex.out
./executable.sh > ex.out

5. Copy my group file

There is only one file in the directory /usr/local/linuxgym-data/permissions which is assigned to your group. Copy this file into your ch3-pp directory, giving it the name “myfile”.

ls –l /usr/local/linuxgym-data/permissions
cp (group file) myfile

6. Secret file

Create a file called “secret.txt” in your “ch3-pp” directory containing your name and telephone number. Change the permissions of this file so that you can read and write to it, but no-one else can read or write to it. Also ensure that no-one can attempt to execute (run) it.

touch secret.txt
vim secret
chmod 600 secret.txt

7. Small Bash script

The file “/usr/local/linuxgym-data/permissions/hw.sh” is a bash script. Copy it into your “ch3-pp” directory and change the permissions so that you are able to execute it.

cp /usr/local/linuxgym-data/permissions/hw.sh hw.sh
chmod 740 hw.sh

8. Standard error preparation

Create a file called “forgotten.txt” in your “ch3-pp” directory. Change its permissions so that you are not allowed to see its contents.

#cat = reads whats in da files and display them
cat > forgotten.txt
chmod 000 forgotten.txt

9. Standard error message

If you attempt the command “cat forgotten.txt” (as created in the previous question), because you do not have permission to read it, there will be an error. The goal of this question is to store this error in a file called stderr.out in your ch3-pp directory, making sure there are no additional characters or spaces. (Hint: Do not attempt to edit this file by hand. The “>” operator redirects the standard output while the “2>” operator redirects the standard error.)

cat > stderr.out
cat forgotten.txt 2> stderr.out

Best Web Design, web developer, php developer,designers,freelance

Follow

Get every new post delivered to your Inbox.

Join 89 other followers