notes - Lab I Introductory Linux and Shell Scripts Example...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lab I : Introductory Linux and Shell Scripts Example 1 : Manipulating and listing files and directories : mv, cp, mkdir, touch, ls The first exercise of this lab period is also going to be a lesson in good computing habits. The best way to confuse yourself about your work is by keeping your files all in one place without making use of directories. You should divide your files into meaningfully-named directories and possibly further into subdirectories. So let’s start by making a directory to contain the work you’ll be doing for this class and subdirectories to separate your work between classes. [email protected]:~$ mkdir phys343 [email protected]:~$ cd phys343 [email protected]:~$ mkdir lab-01 [email protected]:~$ cd lab-01 [email protected]:~$ pwd /home/hande/phys343/lab-01 The command mkdir creates a new directory with the name you supply to it. Then you can go into the newly created directory using the command cd , which stands for change directory and does precisely that. You can equally well create the directory phys343 and the subdirectory lab-01 at the same time. [email protected]:~$ mkdir -p phys343/lab-01 You do, however, have to use the-p option to force the system to simultaneously create the parents of the deepest subdirectory lab-01 . You can then make sure you are in the right place by using the pwd command. pwd gives you the full path or address of the current directory. Now, we can create the files that are necesasry for this lab. In most Linux systems, there are several ways to create a file . 1. Using the touch command : [email protected]:~$ ls my-file ls: my-file: No such file or directory [email protected]:~$ touch my-file [email protected]:~$ ls -l my-file-rw-r--r-- 1 hande users 0 2007-10-02 21:22 my-file [email protected]:~$ touch my-file [email protected]:~$ ls -l my-file-rw-r--r-- 1 hande users 0 2007-10-02 21:23 my-file Here the command touch creates an empty file if the file does not already exist and it only changes its modi- fication date if it does. The command ls lists all the files and directories that are under the directory you are in. The option-l displays different aspects of the files being listed. (See below) 2. Using the cat command : [email protected]:~$ ls my-file ls: my-file: No such file or directory [email protected]:~$ cat > my-file The > sign directs the following into the file. This is the first line. This is the second line. Terminate with Cntrl-d. ^Cntrl-d [email protected]:~$ cat my-file Without the > sign, it only prints contents of file. This is the first line. This is the second line. [email protected]:~$ cp my-file my-file2 2 [email protected]:~$ cat my-file my-file2 This is the first line. This is the second line. This is the first line. This is the second line. [email protected]:~$ cat my-file my-file2 > my-file3 The > sign redirects into a file [email protected]:~$ cat my-file3 This is the first line....
View Full Document

This note was uploaded on 03/31/2010 for the course PHYSICS 343 taught by Professor Üstünel during the Fall '07 term at Middle East Technical University.

Page1 / 9

notes - Lab I Introductory Linux and Shell Scripts Example...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online