author | amit |
Thu, 02 Sep 2010 23:18:50 +0530 | |
changeset 121 | caf2b538fa0a |
parent 98 | 678c7c01b5d5 |
child 122 | 70b86355e851 |
permissions | -rw-r--r-- |
44
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
1 |
Introducing Linux |
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
2 |
================= |
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
3 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
4 |
GNU/Linux is an operating system that uses the Linux Kernel. It is similar to the Unix operating system. It is an open source operating system which basically means you can view and change the code. |
25
4df1ca9766b8
Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff
changeset
|
5 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
6 |
The Linux Kernel written by Linus Torvalds in 1991. Although written only for x86 architecture , it was ported to many other architectures.The whole operating system contains the kernel and several other system and application software contributed by many different projects. A major contributor has been the GNU project. GNU project was started by Richard Stallman in 1983. Richard Stallman wrote the GNU General Public License which gave the first impetus to the free software movement leading up do development of the family of Linux operating systems that we see today . |
25
4df1ca9766b8
Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff
changeset
|
7 |
|
4df1ca9766b8
Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff
changeset
|
8 |
Design and Implications |
4df1ca9766b8
Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff
changeset
|
9 |
------------------------ |
4df1ca9766b8
Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff
changeset
|
10 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
11 |
Linux is a modular operating system, deriving much of its basic design from principles established in Unix earlier. The kernel manages the systems resources like process control, networking, peripherals and file system access. Application Software written on top of it gives higher level functionality. |
25
4df1ca9766b8
Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff
changeset
|
12 |
|
4df1ca9766b8
Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff
changeset
|
13 |
Reasons for Using Linux |
4df1ca9766b8
Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff
changeset
|
14 |
----------------------- |
27
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
15 |
- Linux is free: |
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
16 |
|
73
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
17 |
As in "free beer". Linux can be downloaded in its entirety from the Internet completely for free. No registration fees, no costs per user, free updates, and freely available source code in case you want to change the behavior of your system. |
27
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
18 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
19 |
- Linux can be deployed easily on clusters for parallel and distributed computing |
27
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
20 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
21 |
There are many distributions of Linux meant for clusters. One of the popular ones is Rocks Cluster Distribution. |
27
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
22 |
|
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
23 |
- Linux was made to keep on running: |
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
24 |
|
73
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
25 |
As with UNIX, a Linux system expects to run without rebooting all the time. That is why a lot of tasks are being executed at night or scheduled automatically for other times, resulting in higher availability during busier periods and a more balanced use of the hardware. This property allows for Linux to be applicable to environments where people do not have the time or the possibility to control their systems constantly. |
27
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
26 |
|
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
27 |
- Linux is secure and versatile: |
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
28 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
29 |
The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. |
25
4df1ca9766b8
Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff
changeset
|
30 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
31 |
- Linux contains a tools for scientific computing |
27
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
32 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
33 |
Linux contains many tools like latex for reading and writing scientific text. It also contains many softwares like scilab , python and fortran used for scientific computing needs. |
27
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
34 |
|
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
35 |
|
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
36 |
|
44
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
37 |
Getting Started |
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
38 |
================ |
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
39 |
|
27
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
40 |
Logging in, activating the user interface and logging out |
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
41 |
---------------------------------------------------------- |
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
42 |
Linux supports multiple users on a machine. Each user must log in with his or her username and password. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
43 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
44 |
In order to work on a Linux system directly, one needs to provide a username and password. You always need to authenticate to the system. After booting , you will see a login screen/prompt asking for username and password , enter the username and password , if it is correct you will be logged in . One can logout by typing logout on the prompt or navigating to logout button if using Graphical User Interface . |
27
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
45 |
|
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
46 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
47 |
When you see the login screen again, asking to enter username and password, logout was successful. |
27
fe0672fd1be4
Introduction, midway session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
25
diff
changeset
|
48 |
|
25
4df1ca9766b8
Introduction, added session 1.
Kadambari Devarajan <kadambarid@fossee.in>
parents:
diff
changeset
|
49 |
|
44
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
50 |
Basic Commands |
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
51 |
=============== |
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
52 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
53 |
What files do I have on my computer? |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
54 |
------------------------------------- |
44
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
55 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
56 |
All content in Linux is kept on data structure called files.We can list those files to know what all is there. |
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
57 |
*ls* lists the files in the current working directory. A directory that is not the current working directory can be specified and ls will list the files there.:: |
44
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
58 |
|
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
59 |
|
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
60 |
$ ls |
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
61 |
jeeves.rst psmith.html blandings.html Music |
73
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
62 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
63 |
How do I move around the file system? |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
64 |
------------------------------------- |
44
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
65 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
66 |
This stands for "change directory". When one wants to change the directory . |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
67 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
68 |
$cd Music |
44
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
69 |
|
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
70 |
One dot '.' represents the current directory while two dots '..' represent the parent directory. |
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
71 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
72 |
“ cd -” will return you to the previous directory. |
44
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
73 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
74 |
You can also use cd [absolute path] or cd [relative path] (see below): |
44
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
75 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
76 |
Absolute paths: |
44
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
77 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
78 |
Absolute Path is the path of the directory from root i.e / . / is the top most level in file system. |
44
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
79 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
80 |
For example to get to /var/www you would type:: |
44
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
81 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
82 |
$cd /var/www |
44
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
83 |
|
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
84 |
This is an absolute path because you start at the top of the hierarchy and go downwards from there (it doesn't matter where in the filesystem you were when you typed the command). |
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
85 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
86 |
Relative paths: |
44
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
87 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
88 |
Releative Path is path in relation to your current location . |
44
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
89 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
90 |
For example if you are in Music directory and want to get to Rock directory inside Music, you type:: |
44
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
91 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
92 |
Music$ cd Rock |
44
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
93 |
|
6a9f6526b4f4
Added few basic commands
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
27
diff
changeset
|
94 |
Please note that there is no / using the above cd command. Using a / would cause this to be an absolute path, working from the top of the hierarchy downward. |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
95 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
96 |
Linux is multiuser system so *who* all are using my system now? |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
97 |
-------------------------------------------------------- |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
98 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
99 |
The standard Unix command *who* displays a list of users who are currently logged into a computer.:: |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
100 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
101 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
102 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
103 |
$who |
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
104 |
user tty7 2009-09-08 10:50 (:0) |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
105 |
harry pts/0 2009-09-08 11:25 (:0.0) |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
106 |
dumbledore pts/1 2009-09-08 18:11 (potter.xyz.in) |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
107 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
108 |
The columns represent user, current terminal , date and time of login and the host from which he is logged in respectively. |
73
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
109 |
The command can be invoked with the arguments *am i* or *am I* (so it is invoked as *who am i* or * who am I*), showing information about the current terminal only (see the *-m* option below, of which this invocation is equivalent). |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
110 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
111 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
112 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
113 |
How do I organize my files? |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
114 |
--------------------------- |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
115 |
|
73
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
116 |
This command is used to make a new directory. Normal usage is as straightforward as follows:: |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
117 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
118 |
$mkdir name_of_directory |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
119 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
120 |
Where *name_of_directory* is the name of the directory one wants to create. When typed as above (ie. normal usage), the new directory would be created within the current directory. On Unix, multiple directories can be specified, and *mkdir* will try to create all of them. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
121 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
122 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
123 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
124 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
125 |
Where am I now in the filesystem? |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
126 |
-------------- |
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
127 |
pwd is a Linux / Unix command which prints the current working directory. If you wish to know the full path of the directory in which you are in from the Linux console, then the pwd command will come to your rescue. pwd stands for Print Working Directory. |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
128 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
129 |
Usage of pwd command:: |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
130 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
131 |
$ cd Examples |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
132 |
$ pwd |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
133 |
/home/user/Examples |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
134 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
135 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
136 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
137 |
I wish some commads were a bit smarter ? |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
138 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
139 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
140 |
The standard commands in Linux have a lot of options also called flags to change or provide some additional functionality to the command For example :: |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
141 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
142 |
$ls -l |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
143 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
144 |
* *ls with flag -l* displays the result in long format, displaying Unix file types, permissions, number of hard links, owner, group, size, date, and filename :: |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
145 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
146 |
$ls a |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
147 |
* *ls with flag -a* lists all files including hidden files |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
148 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
149 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
150 |
Similarly, mkdir with -p option automatically creates parent directory even if it does not exist.:: |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
151 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
152 |
$mkdir -p this/path/never/existed/earlier/ |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
153 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
154 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
155 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
156 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
157 |
Getting Help |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
158 |
============ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
159 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
160 |
How do I find what a command does? |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
161 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
162 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
163 |
A short index of explanations for commands is available using the *whatis* command, like in the examples below:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
164 |
|
73
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
165 |
$whatis ls |
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
166 |
ls (1) - list directory contents |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
167 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
168 |
This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
169 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
170 |
More extensive Documentation |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
171 |
---------------------------- |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
172 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
173 |
Man pages (short for "manual pages") are the extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems. The Unix command used to display them is *man*. Each page is a self-contained document. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
174 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
175 |
To read a manual page for a Unix command, one can use:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
176 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
177 |
$ man <command_name> |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
178 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
179 |
To see the manual on man itself do:: |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
180 |
|
73
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
181 |
$man man |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
182 |
|
73
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
183 |
The previous example will take you to the "Manual" page entry about manual pages! |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
184 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
185 |
Looking at man pages is a very good way to actually check flags and other help related to a command. |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
186 |
|
74
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
187 |
--help |
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
188 |
------- |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
189 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
190 |
Most GNU commands support the --help, which gives a short explanation about how to use the command and a list of available options. Below is the output of this option with the *mkdir* command:: |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
191 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
192 |
$ mkdir --help |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
193 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
194 |
Usage: mkdir [OPTION]... DIRECTORY... |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
195 |
Create the DIRECTORY(ies), if they do not already exist. |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
196 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
197 |
Mandatory arguments to long options are mandatory for short options too. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
198 |
-m, --mode=MODE set file mode (as in chmod), not a=rwx - umask |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
199 |
-p, --parents no error if existing, make parent directories as needed |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
200 |
-v, --verbose print a message for each created directory |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
201 |
-Z, --context=CTX set the SELinux security context of each created |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
202 |
directory to CTX |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
203 |
--help display this help and exit |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
204 |
--version output version information and exit |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
205 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
206 |
Report mkdir bugs to bug-coreutils@gnu.org |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
207 |
GNU coreutils home page: <http://www.gnu.org/software/coreutils/> |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
208 |
General help using GNU software: <http://www.gnu.org/gethelp/> |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
209 |
Report mkdir translation bugs to <http://translationproject.org/team/> |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
210 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
211 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
212 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
213 |
Basic file handling |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
214 |
=================== |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
215 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
216 |
Copying Files |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
217 |
------------- |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
218 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
219 |
*cp* is the command to copy a file from one place to another including different file system(#change? ellaborate). The original file remains unchanged, and the new file may have the same or a different name. |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
220 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
221 |
Usage |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
222 |
~~~~~ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
223 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
224 |
To copy a file to another file :: |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
225 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
226 |
$ cp SourceFile TargetFile |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
227 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
228 |
To copy a file to a directory:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
229 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
230 |
$ cp SourceFile TargetDirectory |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
231 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
232 |
To copy a directory to a directory:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
233 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
234 |
$ cp -r SourceDirectory TargetDirectory |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
235 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
236 |
In case target Directory has a file of the same name:: |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
237 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
238 |
TargetDirectory$ls |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
239 |
jeeves.rst psmith.html |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
240 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
241 |
SourceDirectory$ls |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
242 |
jeeves.rst index.html |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
243 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
244 |
$cp -i jeeves.rst TargetDirectory/ |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
245 |
cp: overwrite 'TargetDirectory/jeeves.rst'? |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
246 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
247 |
-i option is for interactive usage. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
248 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
249 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
250 |
Flags |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
251 |
~~~~~ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
252 |
*-i* (interactive) – prompts you with the name of a file to be overwritten. This occurs if the TargetDirectory or TargetFile parameter contains a file with the same name as a file specified in the SourceFile or SourceDirectory parameter. If you enter y or the locale's equivalent of y, the cp command continues. Any other answer prevents the cp command from overwriting the file. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
253 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
254 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
255 |
*-r* (recursive) – copy directories (recursively copying all the contents) |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
256 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
257 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
258 |
Moving Files |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
259 |
------------ |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
260 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
261 |
*mv* (short for move) is a Unix command that moves one or more files or directories from one place to another. The original file is deleted, and the new file may have the same or a different name.An interesting usage of mv is actualy to rename it by moving it in same directory under a different name. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
262 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
263 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
264 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
265 |
Usage |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
266 |
~~~~~~~~ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
267 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
268 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
269 |
To rename a file :: |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
270 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
271 |
$ mv myfile mynewfilename |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
272 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
273 |
To move to a different directory :: |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
274 |
$ mv myfile otherdir/ |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
275 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
276 |
To move a directory :: |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
277 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
278 |
$mv mydir otherdir |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
279 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
280 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
281 |
Using -i to avoid overwrite(just like cp):: |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
282 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
283 |
$mv -i mydir otherdir |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
284 |
mv: overwrite `otherdir/mydir'? |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
285 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
286 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
287 |
Removing files |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
288 |
-------------- |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
289 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
290 |
*rm* is used to delete files from a filesystem. |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
291 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
292 |
Here's example to remove a file named "foo" from a directory, here shown with the -i option:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
293 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
294 |
$ rm -i foo |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
295 |
remove foo? y |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
296 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
297 |
Options |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
298 |
~~~~~~~ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
299 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
300 |
Common options that rm accepts include: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
301 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
302 |
* *-r*, which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in) ("recursive") |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
303 |
* *-i*, which asks for every deletion to be confirmed ("interactive") |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
304 |
* *-f*, which ignores non-existent files and overrides any confirmation prompts ("force") |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
305 |
* *-v*, which shows what is being removed as it happens ("verbose") |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
306 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
307 |
*rm* is often aliased to "rm -i" so as to avoid accidental deletion of files. |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
308 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
309 |
*rm -rf* (variously, rm -rf /, rm -rf `*`, and others) is frequently used in jokes and anecdotes about Unix disasters. The rm -rf variant of the command, if run by a superuser on the root directory, would cause the contents of every writable mounted filesystem on the computer to be deleted. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
310 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
311 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
312 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
313 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
314 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
315 |
Permissions |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
316 |
~~~~~~~~~~~ |
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
317 |
Linux is a proper multi-user environment. In a multi-user environment, security of user and system data is very important. Access should be given only to users who need to access the data. Since Linux is essentially a server OS, good and efficient file security is built right . The permissions are based on whether one is allowed to read, write or execute a file. |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
318 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
319 |
Usually, on most filesystems, deleting a file requires write permission on the parent directory (and execute permission, in order to enter the directory in the first place). (Note that, confusingly for beginners, permissions on the file itself are irrelevant. However, GNU rm asks for confirmation if a write-protected file is to be deleted, unless the -f option is used.) |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
320 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
321 |
To delete a directory (with rm -r), one must delete all of its contents recursively. This requires that one must have read and write and execute permission to that directory (if it's not empty) and all non-empty subdirectories recursively (if there are any). |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
322 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
323 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
324 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
325 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
326 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
327 |
Working with text |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
328 |
================= |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
329 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
330 |
How do I look into a file? |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
331 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
332 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
333 |
more |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
334 |
----- |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
335 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
336 |
In computing, *more* is a command to view contents of a text file one screen at a time |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
337 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
338 |
Usage |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
339 |
~~~~~ |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
340 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
341 |
The command-syntax is:: |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
342 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
343 |
$ more [options] [file_name] |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
344 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
345 |
Traversing the pages :: |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
346 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
347 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
348 |
SPACE Display next k lines of text. Defaults to current screen |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
349 |
size. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
350 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
351 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
352 |
RETURN Display next k lines of text. Defaults to 1. Argument |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
353 |
becomes new default. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
354 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
355 |
/pattern Search for kth occurrence of regular expression. Defaults to |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
356 |
1 . |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
357 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
358 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
359 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
360 |
less |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
361 |
----- |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
362 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
363 |
*less* is similar to *more* in the sense that it is used to view files , but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers, *less* does not need to read the entire file before starting, resulting in faster load times with large files. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
364 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
365 |
Usage |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
366 |
~~~~~~ |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
367 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
368 |
*less* can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While *less* is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both *more* and *vi*. It is also possible to search for character patterns in the file. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
369 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
370 |
By default, *less* displays the contents of the file to the standard output (one screen at a time). If the file name argument is omitted, it displays the contents from standard input (usually the output of another command through a pipe). If the output is redirected to anything other than a terminal, for example a pipe to another command, less behaves like cat. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
371 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
372 |
The command-syntax is :: |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
373 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
374 |
$ less [options] file_name |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
375 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
376 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
377 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
378 |
Frequently Used Commands |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
379 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
380 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
381 |
* [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
382 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
383 |
* [Space bar]: Next page. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
384 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
385 |
* b: Previous page. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
386 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
387 |
* ng: Jump to line number n. Default is the start of the file. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
388 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
389 |
* nG: Jump to line number n. Default is the end of the file. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
390 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
391 |
* /pattern: Search for pattern. Regular expressions can be used. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
392 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
393 |
* '^ or g: Go to start of file. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
394 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
395 |
* '$ or G: Go to end of file. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
396 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
397 |
* =: File information. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
398 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
399 |
* h: Help. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
400 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
401 |
* q: Quit. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
402 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
403 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
404 |
cat |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
405 |
--- |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
406 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
407 |
The *cat* command is a standard Unix program used to concatenate and display files. The name is from "catenate", a synonym of *concatenate*. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
408 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
409 |
The Single Unix Specification specifies the behavior that the contents of each of the files given in sequence as arguments will be written to the standard output in the same sequence, and mandates one option, -u, where each byte is printed as it is read. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
410 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
411 |
If the filename is specified as -, then *cat* will read from standard input at that point in the sequence. If no files are specified, *cat* will read from standard input entered. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
412 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
413 |
Usage :: |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
414 |
$ cat foo boo |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
415 |
This is file foo |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
416 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
417 |
This is file boo. |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
418 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
419 |
Text Processing |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
420 |
--------------- |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
421 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
422 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
423 |
How do look at part of a file? |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
424 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
425 |
|
74
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
426 |
head |
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
427 |
----- |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
428 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
429 |
*head* is a program on Unix and Unix-like systems used to display the first few lines of a text file or piped data. The command syntax is:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
430 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
431 |
$ head [options] <file_name> |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
432 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
433 |
By default, *head* will print the first 10 lines of its input to the standard output. The number of lines printed may be changed with a command line option. The following example shows the first 20 lines of filename:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
434 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
435 |
$ head -n 20 filename |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
436 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
437 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
438 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
439 |
|
74
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
440 |
tail |
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
441 |
---- |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
442 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
443 |
*tail* is a program on Unix and Unix-like systems used to display the last few lines of a text file or piped data. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
444 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
445 |
The command-syntax is:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
446 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
447 |
$ tail [options] <file_name> |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
448 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
449 |
By default, *tail* will print the last 10 lines of its input to the standard output. With command line options the number of lines printed and the printing units (lines, blocks or bytes) may be changed. The following example shows the last 20 lines of filename:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
450 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
451 |
$ tail -n 20 filename |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
452 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
453 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
454 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
455 |
This example shows all lines of filename from the second line onwards:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
456 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
457 |
$ tail -n +2 filename |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
458 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
459 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
460 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
461 |
Monitoring a continously changing file(example: A log file) |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
462 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
463 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
464 |
*tail* has a special command line option *-f* (follow) that allows a file to be monitored. Instead of displaying the last few lines and exiting, tail displays the lines and then monitors the file. As new lines are added to the file by another process, tail updates the display. This is particularly useful for monitoring log files. The following command will display the last 10 lines of messages and append new lines to the display as new lines are added to messages:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
465 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
466 |
$ tail -f /var/log/dmesg |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
467 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
468 |
To interrupt tail while it is monitoring, break-in with *Ctrl+C*. This command can be run "in the background" with &, see job control. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
469 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
470 |
More serious Text Processing: |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
471 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
472 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
473 |
Problem get the names of people in the following file |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
474 |
----------------------------------------------------- |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
475 |
:: |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
476 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
477 |
Foot in Mouth:Bully:Fat:Peter |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
478 |
Rich:Simple:Peabrain:Lois |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
479 |
Self-concious:Wannabe:Adolescent:Meg |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
480 |
Dim-witted:Fat:evil-monkey:Chris |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
481 |
Matricidal:Over-Ambitious:Infant:Stewy |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
482 |
Anthropomorphic:Democrat:Sensible:Brian |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
483 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
484 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
485 |
$cut -d : -f 4- file |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
486 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
487 |
Peter |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
488 |
Lois |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
489 |
Meg |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
490 |
Chris |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
491 |
Stewy |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
492 |
Brian |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
493 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
494 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
495 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
496 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
497 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
498 |
|
74
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
499 |
cut |
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
500 |
---- |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
501 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
502 |
In computing, *cut* is a Unix command line utility which is used to extract sections from each line of input — usually from a file. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
503 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
504 |
Extraction of line segments can typically be done by a *delimiter (-d — the tab character by default)*. A range must be provided in which consists of one of N, N-M, N- (N to the end of the line), or -M (beginning of the line to M), where N and M are counted from 1 (there is no zeroth value). |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
505 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
506 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
507 |
Options |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
508 |
------- |
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
509 |
:: |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
510 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
511 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
512 |
|
121
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
513 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
514 |
|
caf2b538fa0a
Added a question answer format for initial introduction to make it recipie based .
amit
parents:
98
diff
changeset
|
515 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
516 |
|
74
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
517 |
paste |
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
518 |
------ |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
519 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
520 |
*paste* is a Unix command line utility which is used to join files horizontally (parallel merging) by outputting lines consisting of the sequentially corresponding lines of each file specified, separated by tabs, to the standard output. It is effectively the horizontal equivalent to the utility *cat* command which operates on the vertical plane of two or more files. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
521 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
522 |
To paste several columns of data together into the file *www* from files *who*, *where*, and *when*:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
523 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
524 |
$ paste who where when > www |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
525 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
526 |
If the files contain: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
527 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
528 |
+-----------+------------+------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
529 |
| who | where | when | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
530 |
+===========+============+============+ |
73
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
531 |
| Batman | GothamCity | January 3 | |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
532 |
+-----------+------------+------------+ |
73
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
533 |
| Trillian | Andromeda | February 4 | |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
534 |
+-----------+------------+------------+ |
73
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
535 |
| Jeeves | London | March 19 | |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
536 |
+-----------+------------+------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
537 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
538 |
This creates the file named *www* containing :: |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
539 |
|
73
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
540 |
Batman GothamCity January 3 |
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
541 |
Trillian Andromeda February 4 |
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
542 |
Jeeves London March 19 |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
543 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
544 |
Shell Meta Characters |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
545 |
====================== |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
546 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
547 |
Unix recognizes certain special characters, called "meta characters," as command directives. The shell meta characters are recognized anywhere they appear in the command line, even if they are not surrounded by blank space. For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and the period, dash, and underscore characters when naming files and directories on Unix. If your file or directory has a shell meta character in the name, you will find it difficult to use the name in a shell command. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
548 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
549 |
The shell meta characters include: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
550 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
551 |
\ / < > ! $ % ^ & * | { } [ ] " ' ` ~ ; |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
552 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
553 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
554 |
As an example, |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
555 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
556 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
557 |
$ ls file.* |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
558 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
559 |
run on a directory containing the files file, file.c, file.lst, and myfile would list the files file.c and file.lst. However,:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
560 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
561 |
$ ls file.? |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
562 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
563 |
run on the same directory would only list file.c because the ? only matches one character, no more, no less. This can save you a great deal of typing time. For example, if there is a file called california_cornish_hens_with_wild_rice and no other files whose names begin with 'c', you could view the file without typing the whole name by typing this:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
564 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
565 |
$ more c* |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
566 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
567 |
because the c* matches that long file name. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
568 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
569 |
Filenames containing metacharacters can pose many problems and should never be intentionally created. |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
570 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
571 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
572 |
Looking At Files |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
573 |
================ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
574 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
575 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
576 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
577 |
|
74
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
578 |
more |
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
579 |
----- |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
580 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
581 |
In computing, *more* is a command to view (but not modify) the contents of a text file one screen at a time (terminal pager). It is available on Unix and Unix-like systems, DOS, OS/2 and Microsoft Windows. Programs of this sort are called pagers. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
582 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
583 |
Usage |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
584 |
~~~~~ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
585 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
586 |
The command-syntax is:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
587 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
588 |
$ more [options] [file_name] |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
589 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
590 |
If no file name is provided, *more* looks for input from stdin. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
591 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
592 |
Once *more* has obtained input, it displays as much as can fit on the current screen and waits for user input to advance, with the exception that a form feed (^L) will also cause *more* to wait at that line, regardless of the amount of text on the screen. In the lower-left corner of the screen is displayed the text "--More--" and a percentage, representing the percent of the file that *more* has paged through. (This percentage includes the text displayed on the current screen.) When *more* reaches the end of a file (100%) it exits. The most common methods of navigating through a file are *Enter*, which advances the output by one line, and *Space*, which advances the output by one screen. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
593 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
594 |
There are also other commands that can be used while navigating through the document; consult *more*'s *man* page for more details. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
595 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
596 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
597 |
|
74
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
598 |
less |
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
599 |
----- |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
600 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
601 |
*less* is a terminal pager program on Unix, Windows and Unix-like systems used to view (but not change) the contents of a text file one screen at a time. It is similar to *more*, but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers, *less* does not need to read the entire file before starting, resulting in faster load times with large files. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
602 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
603 |
Usage |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
604 |
~~~~~~ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
605 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
606 |
*less* can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While *less* is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both *more* and *vi*. It is also possible to search for character patterns in the file. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
607 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
608 |
By default, *less* displays the contents of the file to the standard output (one screen at a time). If the file name argument is omitted, it displays the contents from standard input (usually the output of another command through a pipe). If the output is redirected to anything other than a terminal, for example a pipe to another command, less behaves like cat. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
609 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
610 |
The command-syntax is :: |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
611 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
612 |
$ less [options] file_name |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
613 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
614 |
Frequently Used Options |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
615 |
~~~~~~~~~~~~~~~~~~~~~~~ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
616 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
617 |
* -g: Highlights just the current match of any searched string. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
618 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
619 |
* -I: Case-insensitive searches. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
620 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
621 |
* -M: Shows more detailed prompt, including file position. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
622 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
623 |
* -N: Shows line numbers (useful for source code viewing). |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
624 |
|
73
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
625 |
* -S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling. |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
626 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
627 |
* -?: Shows help. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
628 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
629 |
Frequently Used Commands |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
630 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
631 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
632 |
* [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
633 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
634 |
* [Space bar]: Next page. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
635 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
636 |
* b: Previous page. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
637 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
638 |
* ng: Jump to line number n. Default is the start of the file. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
639 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
640 |
* nG: Jump to line number n. Default is the end of the file. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
641 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
642 |
* /pattern: Search for pattern. Regular expressions can be used. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
643 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
644 |
* '^ or g: Go to start of file. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
645 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
646 |
* '$ or G: Go to end of file. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
647 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
648 |
* h: Help. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
649 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
650 |
* q: Quit. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
651 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
652 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
653 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
654 |
------------------------------------------------------------------- |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
655 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
656 |
Examples |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
657 |
~~~~~~~~~ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
658 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
659 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
660 |
$ less -M readme.txt #Read "readme.txt." |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
661 |
$ less +F /var/log/mail.log #Follow mode for log |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
662 |
$ file * | less #Easier file analysis. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
663 |
$ grep -i void *.c | less -I -p void #Case insensitive search for "void" in all .c files |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
664 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
665 |
Directory Structure |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
666 |
==================== |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
667 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
668 |
In the File Hierarchy Standard (FHS) all files and directories appear under the root directory "/", even if they are stored on different physical devices. Note however that some of these directories may or may not be present on a Unix system depending on whether certain subsystems, such as the X Window System, are installed. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
669 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
670 |
The majority of these directories exist in all UNIX operating systems and are generally used in much the same way; however, the descriptions here are those used specifically for the FHS, and are not considered authoritative for platforms other thanmajor Linux distros. |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
671 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
672 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
673 |
| Directory | Description | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
674 |
+===============+================================================+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
675 |
| / | Primary hierarchy root and root directory of | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
676 |
| | the entire file system hierarchy. | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
677 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
678 |
| /bin/ | Essential command binaries that need to be | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
679 |
| | available in single user mode; for all users, | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
680 |
| | e.g., *cat*, *ls*, *cp*. | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
681 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
682 |
| /boot/ | Boot loader files, e.g., *kernels*, *initrd*; | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
683 |
| | often a separate partition. | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
684 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
685 |
| /dev/ | Essential devices, e.g., /dev/null | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
686 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
687 |
| /etc/ | Host-specific system-wide configuration files | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
688 |
| | (the name comes from *et cetera*) | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
689 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
690 |
| /home/ | User's home directories, containing saved | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
691 |
| | files, personal settings, etc.; often a | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
692 |
| | separate partition. | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
693 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
694 |
| /lib/ | Libraries essential for the binaries in | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
695 |
| | */bin/* and */sbin/* | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
696 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
697 |
| /media/ | Mount points for removable media such as | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
698 |
| | CD-ROMs, external hard disks, USB sticks, etc. | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
699 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
700 |
| /mnt/ | Temporarily mounted file systems | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
701 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
702 |
| /opt/ | Optional application software packages | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
703 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
704 |
| /proc/ | Virtual filesystem documenting kernel and | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
705 |
| | process status as text files; e.g., uptime, | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
706 |
| | network. In Linux, corresponds to a *Procfs* | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
707 |
| | mount. | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
708 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
709 |
| /root/ | Home directory for the root user | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
710 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
711 |
| /sbin/ | Essential system binaries; e.g., *init*, | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
712 |
| | *route*, *mount*. | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
713 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
714 |
| /srv/ | Site-specific data which is served by the | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
715 |
| | system. | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
716 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
717 |
| /tmp/ | Temporary files. Often not preserved between | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
718 |
| | system reboots. | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
719 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
720 |
| /usr/ | Secondary hierarchy for read-only user data; | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
721 |
| | contains the majority of (multi-)user | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
722 |
| | utilities and applications. | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
723 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
724 |
| /var/ | Variable files - files whose content is | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
725 |
| | expected to continually change during normal | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
726 |
| | operation of the system - such as logs, spool | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
727 |
| | files, and temporary e-mail files. | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
728 |
| | Sometimes a separate partition. | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
729 |
+---------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
730 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
731 |
|
74
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
732 |
man hier |
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
733 |
--------- |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
734 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
735 |
This is the manual page on the UNIX filesystem. The syntax for this is:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
736 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
737 |
$ man hier |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
738 |
|
74
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
739 |
ls -l |
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
740 |
----- |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
741 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
742 |
Shows you huge amounts of information (permissions, owners, size, and when last modified) for folders and files. The syntax is :: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
743 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
744 |
$ ls -l |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
745 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
746 |
This can be done after entering the required directory. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
747 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
748 |
Permissions and Ownership |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
749 |
========================= |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
750 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
751 |
let's check out the file permissions. File permissions are defined |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
752 |
for users, groups and others. User would be the username that you are |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
753 |
logging in as. Further more, users can be organized into groups for better |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
754 |
administration and control. Each user will belong to at least one default |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
755 |
group. Others includes anyone the above categories exclude. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
756 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
757 |
Given below is the result of an 'ls -l' |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
758 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
759 |
drwxr-x--- 2 user group 4096 Dec 28 04:09 tmp |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
760 |
-rw-r--r-- 1 user group 969 Dec 21 02:32 foo |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
761 |
-rwxr-xr-x 1 user group 345 Sep 1 04:12 somefile |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
762 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
763 |
Relevant information in the first column here is the file type followed by the file permissions. The third and the fourth column show the owner of the file and the group that the file belongs to.The fifth column is no bytes and sixth modification date .The first entry here is tmp. The first character in the first column is 'd', which means the tmp is a directory. The other entries here are files,as indicated by the '-'. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
764 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
765 |
d rwx r-x --- |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
766 |
file type users group others |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
767 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
768 |
The next 9 characters define the file permissions. These permissions are given in groups of 3 each. The first 3 characters are the permissions for the owner of the file or directory. The next 3 are permissions for the group that the file is owned by and the final 3 characters define the access permissions for everyone not part of the group. There are 3 possible attributes that make up file access permissions. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
769 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
770 |
r - Read permission. Whether the file may be read. In the case of a directory, this would mean the ability to list the contents of the directory. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
771 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
772 |
w - Write permission. Whether the file may be written to or modified. For a directory, this defines whether you can make any changes to the contents |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
773 |
of the directory. If write permission is not set then you will not be able |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
774 |
to delete, rename or create a file. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
775 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
776 |
x - Execute permission. Whether the file may be executed. In the case of a directory, this attribute decides whether you have permission to enter,run a search through that directory or execute some program from that directory. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
777 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
778 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
779 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
780 |
|
74
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
781 |
chmod |
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
782 |
------ |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
783 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
784 |
The *chmod* command (abbreviated from 'change mode') is a shell command and C language function in Unix and Unix-like environments. When executed, it can change file system modes of files and directories. The modes include permissions and special modes. |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
785 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
786 |
Usage |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
787 |
~~~~~ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
788 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
789 |
The *chmod* command options are specified like this: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
790 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
791 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
792 |
$ chmod [options] mode[,mode] file1 [file2 ...] |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
793 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
794 |
To view what the permissions currently are, type: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
795 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
796 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
797 |
$ ls -l file |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
798 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
799 |
Command line options |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
800 |
~~~~~~~~~~~~~~~~~~~~ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
801 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
802 |
The *chmod* command has a number of command line options that affect its behavior. The most common options are: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
803 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
804 |
* -R: Changes the modes of directories and files recursively |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
805 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
806 |
* -v: Verbose mode; lists all files as they are being processed |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
807 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
808 |
Symbolic modes |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
809 |
+++++++++++++++ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
810 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
811 |
To the *chmod* utility, all permissions and special modes are represented by its mode parameter. One way to adjust the mode of files or directories is to specify a symbolic mode. The symbolic mode is composed of three components, which are combined to form a single string of text: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
812 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
813 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
814 |
$ chmod [references][operator][modes] file1 ... |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
815 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
816 |
The references (or classes) are used to distinguish the users to whom the permissions apply. If no references are specified it defaults to “all” but modifies only the permissions allowed by the umask. The references are represented by one or more of the following letters: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
817 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
818 |
+--------------+--------+---------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
819 |
| Reference | Class | Description | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
820 |
+==============+========+=============================================+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
821 |
| u | user | the owner of the file | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
822 |
+--------------+--------+---------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
823 |
| g | group | users who are members of the file's group | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
824 |
+--------------+--------+---------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
825 |
| o | others | users who are not hte owner of the file or | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
826 |
| | | members of the group | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
827 |
+--------------+--------+---------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
828 |
| a | all | all three of the above; is the same as *ugo*| |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
829 |
+--------------+--------+---------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
830 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
831 |
The *chmod* program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
832 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
833 |
+--------------+------------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
834 |
| Operator | Description | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
835 |
+==============+======================================================+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
836 |
| + | adds the specified modes to the specified classes | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
837 |
+--------------+------------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
838 |
| - | removes the specified modes from the specified | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
839 |
| | classes | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
840 |
+--------------+------------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
841 |
| = | the modes specified are to be made the exact modes | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
842 |
| | for the specified classes | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
843 |
+--------------+------------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
844 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
845 |
The modes indicate which permissions are to be granted or taken away from the specified classes. There are three basic modes which correspond to the basic permissions: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
846 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
847 |
+-----+--------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
848 |
|Mode | Name | Description | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
849 |
+=====+==============+================================================+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
850 |
| r | read | read a file or list a directory's contents | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
851 |
+-----+--------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
852 |
| w | write | write to a file or directory | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
853 |
+-----+--------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
854 |
| x | execute | execute a file or recurse a directory tree | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
855 |
+-----+--------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
856 |
| X | special | which is not a permission in itself but rather | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
857 |
| | execute | can be used instead of 'x'. It applies execute | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
858 |
| | | permissions to directories regardless of their | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
859 |
| | | current permissions and applies execute | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
860 |
| | | permissions to a file which already has at | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
861 |
| | | least 1 execute permission bit already set | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
862 |
| | | (either user, group or other). It is only | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
863 |
| | | really useful when used with '+' and usually | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
864 |
| | | in combination with the *-R* option for giving | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
865 |
| | | group or other access to a big directory tree | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
866 |
| | | without setting execute permission on normal | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
867 |
| | | files (such as text files), which would | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
868 |
| | | normally happen if one just used 'chmod -R | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
869 |
| | | a+rx .', whereas with 'X' one can do 'chmod -R | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
870 |
| | | a+rX .' instead. | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
871 |
+-----+--------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
872 |
| s | setuid/gid | are Unix access rights flags that allow users | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
873 |
| | | to run an executable with the permissions of | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
874 |
| | | the executable's owner or group.They are often | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
875 |
| | | used to allow users on a computer system to run| |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
876 |
| | | programs with temporarily elevated privileges | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
877 |
| | | in order to perform a specific task. While the | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
878 |
| | | assumed user id or group id privileges provided| |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
879 |
| | | are not always elevated, at a minimum they are | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
880 |
| | | specific.They are needed for tasks that require| |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
881 |
| | | higher privileges than those which a common | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
882 |
| | | user has, such as changing his or her login | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
883 |
| | | password. | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
884 |
+-----+--------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
885 |
| t | sticky | The most common use of the sticky bit today is | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
886 |
| | | on directories, where, when set, items inside | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
887 |
| | | the directory can be renamed or deleted only by| |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
888 |
| | | the item's owner, the directory's owner, or the| |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
889 |
| | | superuser; without the sticky bit set, any user| |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
890 |
| | | with write and execute permissions for the | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
891 |
| | | directory can rename or delete contained files,| |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
892 |
| | | regardless of owner. | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
893 |
+-----+--------------+------------------------------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
894 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
895 |
The combination of these three components produces a string that is understood by the chmod command. Multiple changes can be specified by separating multiple symbolic modes with commas. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
896 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
897 |
Symbolic examples |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
898 |
+++++++++++++++++ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
899 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
900 |
Add the 'read' and 'write' permissions to the 'user' and 'group' classes of a directory: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
901 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
902 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
903 |
$ chmod ug+rw mydir |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
904 |
$ ls -ld mydir |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
905 |
drw-rw---- 2 starwars yoda 96 Dec 8 12:53 mydir |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
906 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
907 |
For a file, remove *write* permissions for all classes: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
908 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
909 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
910 |
$ chmod a-w myfile |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
911 |
$ ls -l myfile |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
912 |
-r-xr-xr-x 2 starwars yoda 96 Dec 8 12:53 myfile |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
913 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
914 |
Set the permissions for the *u*ser and the *g*roup to read and execute only (no write permission) on *mydir*. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
915 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
916 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
917 |
$ chmod ug=rx mydir |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
918 |
$ ls -ld mydir |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
919 |
dr-xr-x--- 2 starwars yoda 96 Dec 8 12:53 mydir |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
920 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
921 |
Octal numbers |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
922 |
+++++++++++++ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
923 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
924 |
The *chmod* command also accepts three and four-digit octal numbers representing modes. Using a three-digit octal number to set the modes of a file named myfile : |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
925 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
926 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
927 |
$ chmod 664 myfile |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
928 |
$ ls -l myfile |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
929 |
-rw-rw-r-- 1 57 Jul 3 10:13 myfile |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
930 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
931 |
Foe each one, you define the right like that : |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
932 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
933 |
* a read right correspond to 4 |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
934 |
* a write right correspond to 2 |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
935 |
* an execute right correspond to 1 |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
936 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
937 |
You want the user to have all the rights? : 4 + 2 + 1 = 7 |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
938 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
939 |
you want the group to have read and write rights : 4 + 2 = 6 |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
940 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
941 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
942 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
943 |
Since the *setuid*, *setgid* and *sticky* bits are not set, this is equivalent to: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
944 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
945 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
946 |
$ chmod 0664 myfile |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
947 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
948 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
949 |
chown |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
950 |
~~~~~ |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
951 |
The chown command is used to change the owner and group of files, directories and links. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
952 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
953 |
By default, the owner of a filesystem object is the user that created it. The group is a set of users that share the same access permissions (i.e., read, write and execute) for that object. |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
954 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
955 |
The basic syntax for using chown to change owners is |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
956 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
957 |
chown -v alice wonderland.txt |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
958 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
959 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
960 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
961 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
962 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
963 |
Redirection and Piping |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
964 |
======================= |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
965 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
966 |
In computing, *redirection* is a function common to most command-line interpreters, including the various Unix shells that can redirect standard streams to user-specified locations. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
967 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
968 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
969 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
970 |
Redirecting standard input and standard output |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
971 |
----------------------------------------------- |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
972 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
973 |
Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
974 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
975 |
$ command1 > file1 |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
976 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
977 |
executes *command1*, placing the output in file1. Note that this will truncate any existing data in *file1*. To append output to the end of the file, use the >> operator.:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
978 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
979 |
$ command1 < file1 |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
980 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
981 |
executes *command1*, using *file1* as the source of input (as opposed to the keyboard).:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
982 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
983 |
$ command1 < infile > outfile |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
984 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
985 |
combines the two capabilities: *command1* reads from *infile* and writes to *outfile* |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
986 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
987 |
Piping |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
988 |
------- |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
989 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
990 |
Programs can be run together such that one program reads the output from another with no need for an explicit intermediate file: |
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
991 |
A pipeline of two programs run on a text terminal:: |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
992 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
993 |
$ command1 | command2 |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
994 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
995 |
executes *command1*, using its output as the input for *command2* (commonly called piping, since the "|" character is known as a "pipe"). |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
996 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
997 |
This is equivalent to using two redirects and a temporary file:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
998 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
999 |
$ command1 > tempfile |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1000 |
$ command2 < tempfile |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1001 |
$ rm tempfile |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1002 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1003 |
A good example for command piping is combining *echo* with another command to achieve something interactive in a non-interactive shell, e.g.:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1004 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1005 |
$ echo -e "user\npass" | ftp localhost |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1006 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1007 |
This runs the ftp client with input user, press return, then pass. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1008 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1009 |
Redirecting to and from the standard file handles |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1010 |
-------------------------------------------------- |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1011 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1012 |
In Unix shells derived from the original Bourne shell, the first two actions can be further modified by placing a number (the file descriptor) immediately before the character; this will affect which stream is used for the redirection. The Unix standard I/O streams are: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1013 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1014 |
+------------+-------------+------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1015 |
| Handle | Name | Description | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1016 |
+============+=============+========================+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1017 |
| 0 | stdin | Standard input | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1018 |
+------------+-------------+------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1019 |
| 1 | stdout | Standard output | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1020 |
+------------+-------------+------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1021 |
| 2 | stderr | Standard error | |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1022 |
+------------+-------------+------------------------+ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1023 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1024 |
For example: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1025 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1026 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1027 |
$ command1 2> file1 |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1028 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1029 |
executes *command1*, directing the standard error stream to *file1*. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1030 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1031 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1032 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1033 |
Another useful capability is to redirect one standard file handle to another. The most popular variation is to merge standard error into standard output so error messages can be processed together with (or alternately to) the usual output. Example: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1034 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1035 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1036 |
$ find / -name .profile > results 2>&1 |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1037 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1038 |
will try to find all files named *.profile*. Executed without redirection, it will output hits to *stdout* and errors (e.g. for lack of privilege to traverse protected directories) to *stderr*. If standard output is directed to file results, error messages appear on the console. To see both hits and error messages in file results, merge *stderr* (handle 2) into *stdout* (handle 1) using 2>&1 . |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1039 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1040 |
It's possible use 2>&1 before ">" but it doesn't work. In fact, when the interpreter reads 2>&1, it doesn't know yet where standard output is redirected and then standard error isn't merged. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1041 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1042 |
If the merged output is to be piped into another program, the file merge sequence 2>&1 must precede the pipe symbol, thus: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1043 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1044 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1045 |
$ find / -name .profile 2>&1 | less |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1046 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1047 |
A simplified form of the command: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1048 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1049 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1050 |
$ command > file 2>&1 |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1051 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1052 |
is: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1053 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1054 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1055 |
$ command &>file |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1056 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1057 |
or: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1058 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1059 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1060 |
$command >&file |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1061 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1062 |
Chained pipelines |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1063 |
------------------ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1064 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1065 |
The redirection and piping tokens can be chained together to create complex commands. For example: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1066 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1067 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1068 |
$ ls | grep '\.sh' | sort > shlist |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1069 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1070 |
lists the contents of the current directory, where this output is filtered to only contain lines which contain *.sh*, sort this resultant output lexicographically, and place the final output in *shlist*. This type of construction is used very commonly in shell scripts and batch files. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1071 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1072 |
Redirect to multiple outputs |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1073 |
----------------------------- |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1074 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1075 |
The standard command *tee* can redirect output from a command to several destinations. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1076 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1077 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1078 |
$ ls -lrt | tee xyz |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1079 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1080 |
This directs the file list output to both standard output as well as to the file *xyz*. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1081 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1082 |
More Text Processing |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1083 |
==================== |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1084 |
|
74
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
1085 |
grep |
7dbeae0fac70
Removed numbering for sections
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
73
diff
changeset
|
1086 |
----- |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1087 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1088 |
*grep* is a command line text search utility originally written for Unix. The name is taken from the first letters in *global / regular expression / print*, a series of instructions for the *ed* text editor. The *grep* command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1089 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1090 |
Usage |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1091 |
~~~~~~ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1092 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1093 |
This is an example of a common *grep* usage: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1094 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1095 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1096 |
$ grep apple fruitlist.txt |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1097 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1098 |
In this case, *grep* prints all lines containing 'apple' from the file *fruitlist.txt*, regardless of word boundaries; therefore lines containing 'pineapple' or 'apples' are also printed. The *grep* command is case sensitive by default, so this example's output does not include lines containing 'Apple' (with a capital A) unless they also contain 'apple'. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1099 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1100 |
Like most Unix commands, *grep* accepts command line arguments to change this and many other behaviors. For example: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1101 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1102 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1103 |
$ grep -i apple fruitlist.txt |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1104 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1105 |
This prints all lines containing 'apple' regardless of capitalization. The '-i' argument tells *grep* to be case insensitive, or to ignore case. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1106 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1107 |
To print all lines containing 'apple' as a word ('pineapple' and 'apples' will not match): |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1108 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1109 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1110 |
$ grep -w apple fruitlist.txt |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1111 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1112 |
Regular expressions can be used to match more complicated queries. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1113 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1114 |
Variations |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1115 |
+++++++++++ |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1116 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1117 |
There are countless implementations and derivatives of *grep* available for many operating systems. Early variants of *grep* included *egrep* and *fgrep*. The former applies an extended regular expression syntax that was added to Unix after Ken Thompson's original regular expression implementation. The latter searches for any of a list of 'fixed' strings using the Aho-Corasick algorithm. These variants are embodied in most modern *grep* implementations as command-line switches (and standardized as -E and -F in POSIX). In such combined implementations, *grep* may also behave differently depending on the name by which it is invoked, allowing *fgrep*, *egrep*, and *grep* to be links to the same program. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1118 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1119 |
*pcregrep* is an implementation of *grep* that uses Perl regular expression syntax. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1120 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1121 |
Other commands contain the word 'grep' to indicate that they search (usually for regular expression matches). The *pgrep* utility, for instance, displays the processes whose names match a given regular expression. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1122 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1123 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1124 |
Elementary Regex |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1125 |
================= |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1126 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1127 |
In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. A regular expression (often shortened to regex or regexp) is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1128 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1129 |
Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. For example, Perl, Ruby and Tcl have a powerful regular expression engine built directly into their syntax. Several utilities provided by Unix distributions—including the editor *ed* and the filter *grep* — were the first to popularize the concept of regular expressions. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1130 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1131 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1132 |
Regular Expressions are a feature of UNIX. They describe a pattern to match, a sequence of characters, not words, within a line of text. Here is a quick summary of the special characters used in the grep tool and their meaning: |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1133 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1134 |
* ^ (Caret) = match expression at the start of a line, as in ^A. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1135 |
* $ (Question) = match expression at the end of a line, as in A$. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1136 |
* \ (Back Slash) = turn off the special meaning of the next character, as in \^. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1137 |
* [ ] (Brackets) = match any one of the enclosed characters, as in [aeiou]. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1138 |
Use Hyphen "-" for a range, as in [0-9]. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1139 |
* [^ ] = match any one character except those enclosed in [ ], as in [^0-9]. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1140 |
* . (Period) = match a single character of any value, except end of line. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1141 |
* * (Asterisk) = match zero or more of the preceding character or expression. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1142 |
* \{x,y\} = match x to y occurrences of the preceding. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1143 |
* \{x\} = match exactly x occurrences of the preceding. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1144 |
* \{x,\} = match x or more occurrences of the preceding. |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1145 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1146 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1147 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1148 |
Here are some examples using grep: |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1149 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1150 |
* grep smug files {search files for lines with 'smug'} |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1151 |
* grep '^smug' files {'smug' at the start of a line} |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1152 |
* grep 'smug$' files {'smug' at the end of a line} |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1153 |
* grep '^smug$' files {lines containing only 'smug'} |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1154 |
* grep '\^s' files {lines starting with '^s', "\" escapes the ^} |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1155 |
* grep '[Ss]mug' files {search for 'Smug' or 'smug'} |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1156 |
* grep 'B[oO][bB]' files {search for BOB, Bob, BOb or BoB } |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1157 |
* grep '^$' files {search for blank lines} |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1158 |
* grep '[0-9][0-9]' file {search for pairs of numeric digits} |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1159 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1160 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1161 |
|
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1162 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1163 |
Lazy quantification |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1164 |
-------------------- |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1165 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1166 |
The standard quantifiers in regular expressions are greedy, meaning they match as much as they can, only giving back as necessary to match the remainder of the regex. For example, someone new to regexes wishing to find the first instance of an item between < and > symbols in this example: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1167 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1168 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1169 |
Another whale explosion occurred on <January 26>, <2004>. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1170 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1171 |
...would likely come up with the pattern <.*>, or similar. However, this pattern will actually return "<January 26>, <2004>" instead of the "<January 26>" which might be expected, because the `*` quantifier is greedy — it will consume as many characters as possible from the input, and "January 26>, <2004" has more characters than "January 26". |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1172 |
|
73
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
1173 |
Though this problem can be avoided in a number of ways (e.g., by specifying the text that is not to be matched: <[^>]*>), modern regular expression tools allow a quantifier to be specified as *lazy* (also known as non-greedy, reluctant, minimal, or ungreedy) by putting a question mark after the quantifier (e.g., <.*?>), or by using a modifier which reverses the greediness of quantifiers (though changing the meaning of the standard quantifiers can be confusing). By using a lazy quantifier, the expression tries the minimal match first. Though in the previous example lazy matching is used to select one of many matching results, in some cases it can also be used to improve performance when greedy matching would require more backtracking. |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1174 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1175 |
One Liners |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1176 |
=========== |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1177 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1178 |
A *one-liner* is textual input to the command-line of an operating system shell that performs some function in just one line of input. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1179 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1180 |
The one liner can be |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1181 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1182 |
1. An expression written in the language of the shell. |
73
d32a19958ad9
Completed first review and cuts of ULT
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
55
diff
changeset
|
1183 |
2. The invocation of an interpreter together with program source for the interpreter to run. |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1184 |
3. The invocation of a compiler together with source to compile and |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1185 |
instructions for executing the compiled program. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1186 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1187 |
Certain dynamic scripting languages such as AWK, sed, and perl have traditionally been adept at expressing one-liners. Specialist shell interpreters such as these Unix shells or the Windows PowerShell, allow for the construction of powerful one-liners. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1188 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1189 |
The use of the phrase one-liner has been widened to also include program-source for any language that does something useful in one line. |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1190 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1191 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1192 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1193 |
Here is a one line shell script to show directories: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1194 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1195 |
:: |
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1196 |
|
98
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1197 |
$grep user * | cut -d":" -f1|uniq |
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1198 |
|
678c7c01b5d5
changes to Intorduction to Linux and Text Processing in ULT
amit@thunder
parents:
74
diff
changeset
|
1199 |
This returns list of all files which has the word user in it . |
55
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1200 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1201 |
|
6aa9568b5874
Completed rough draft of first three sessions in module one.
Kadambari Devarajan <kadambari.devarajan@gmail.com>
parents:
44
diff
changeset
|
1202 |