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

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. hande@p439a:~$ mkdir phys343 hande@p439a:~$ cd phys343 hande@p439a:~$ mkdir lab-01 hande@p439a:~$ cd lab-01 hande@p439a:~$ 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. hande@p439a:~$ 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 : hande@p439a:~$ ls my-file ls: my-file: No such file or directory hande@p439a:~$ touch my-file hande@p439a:~$ ls -l my-file-rw-r--r-- 1 hande users 0 2007-10-02 21:22 my-file hande@p439a:~$ touch my-file hande@p439a:~$ 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 : hande@p439a:~$ ls my-file ls: my-file: No such file or directory hande@p439a:~$ 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 hande@p439a:~$ cat my-file Without the > sign, it only prints contents of file. This is the first line. This is the second line. hande@p439a:~$ cp my-file my-file2 2 hande@p439a:~$ 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. hande@p439a:~$ cat my-file my-file2 > my-file3 The > sign redirects into a file hande@p439a:~$ cat my-file3 This is the first line....
View Full Document

Page1 / 9

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

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