1 Introducing Linux |
1 Introducing Linux |
2 ================= |
2 ================= |
3 |
3 |
4 We are here to welcome you to Linux. GNU/Linux is an operating system that is similar to the UNIX operating system, but is open source software. Being an open source program means that (if you wanted to) you could view the source code of the operating system and change it to suit your needs. |
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. |
5 |
5 |
6 The name "Linux" properly refers to an operating system "kernel", a single but key component of a complete operating system. In everyday use, the term "Linux" is frequently used to refer to a complete operating system which consists of the kernel and some of the thousands of other programs required to make an operating system useful. Much of the important system software that is typically installed on a Linux system comes from The GNU Project, a project to build an operating system made entirely of free software. |
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 . |
7 The first Linux kernel was created by Linus Torvalds. It was started as an x86-only, single processor operating system, but grew to become one of the most ported pieces of software. Other parts of a complete GNU/Linux system come from other projects such as the GNU project, and are integrated into a complete GNU/Linux OS by your supplier. Usually your supplier will assign their own version number to the integrated whole.This collection of the kernal and programs maintained by vendor is called distro or distribution. |
|
8 The GNU Project is overseen by the Free Software Foundation. The Free Software Foundation was founded by Richard Stallman. Stallman believes that the people should use the term "GNU/Linux" to refer to such an operating system, because so many of the required programs were in fact, written as part of the GNU Project. |
|
9 |
|
10 |
|
11 |
7 |
12 Design and Implications |
8 Design and Implications |
13 ------------------------ |
9 ------------------------ |
14 |
10 |
15 A Linux-based system is a modular Unix-like operating system, deriving much of its basic design from principles established in Unix earlier. Such a system uses a monolithic kernel, called the Linux kernel, which handles process control, networking, and peripheral and file system access. Device drivers are integrated directly with the kernel. Separate projects that interface with the kernel provide much of the system's higher-level functionality. The GNU userland is an important part of most Linux-based systems, providing the most common implementation of the C library, a popular shell, and many of the common Unix tools which carry out many basic operating system tasks. The graphical user interface (or GUI) used by most Linux systems is based on the "X Window System". |
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. |
16 |
|
17 |
|
18 |
|
19 |
|
20 |
12 |
21 Reasons for Using Linux |
13 Reasons for Using Linux |
22 ----------------------- |
14 ----------------------- |
23 - Linux is free: |
15 - Linux is free: |
24 |
16 |
25 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. |
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. |
26 Most of all, Linux is free as in "free speech": |
18 |
27 |
19 - Linux can be deployed easily on clusters for parallel and distributed computing |
28 |
20 |
29 - Linux is portable to any hardware platform: |
21 There are many distributions of Linux meant for clusters. One of the popular ones is Rocks Cluster Distribution. |
30 |
|
31 A vendor, who wants to sell a new type of computer and who does not know what kind of OS his/her new machine will run, can take a Linux kernel and make it work on his/her hardware, because documentation related to this activity is freely available. |
|
32 |
22 |
33 - Linux was made to keep on running: |
23 - Linux was made to keep on running: |
34 |
24 |
35 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. |
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. |
36 |
26 |
37 - Linux is secure and versatile: |
27 - Linux is secure and versatile: |
38 |
28 |
39 The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. But Linux is not only safe from attacks from the Internet: it will adapt equally to other situations, utilizing the same high standards for security. |
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. |
40 |
30 |
41 - Linux is scalable: |
31 - Linux contains a tools for scientific computing |
42 |
32 |
43 From a Palmtop with 2 MB of memory to a petabyte storage cluster with hundreds of nodes: add or remove the appropriate packages and Linux fits all. |
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. |
44 |
34 |
45 |
35 |
46 |
36 |
47 Getting Started |
37 Getting Started |
48 ================ |
38 ================ |
49 |
39 |
50 Logging in, activating the user interface and logging out |
40 Logging in, activating the user interface and logging out |
51 ---------------------------------------------------------- |
41 ---------------------------------------------------------- |
52 In order to work on a Linux system directly, one needs to provide a user name and password. You always need to authenticate to the system. Most PC−based Linux systems have two basic modes for a system to run in: either quick and clean in text console mode,which includes with mouse, multitasking and multi−user features, or in graphical console mode. |
42 Linux supports multiple users on a machine. Each user must log in with his or her username and password. |
53 |
43 |
54 |
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 . |
55 |
45 |
56 When you see the login screen again, asking to enter user name and password, logout was successful. |
46 |
|
47 When you see the login screen again, asking to enter username and password, logout was successful. |
57 |
48 |
58 |
49 |
59 Basic Commands |
50 Basic Commands |
60 =============== |
51 =============== |
61 |
52 |
62 ls |
53 What files do I have on my computer? |
63 --- |
54 ------------------------------------- |
64 |
55 |
|
56 All content in Linux is kept on data structure called files.We can list those files to know what all is there. |
65 *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.:: |
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.:: |
66 |
58 |
67 |
59 |
68 $ ls |
60 $ ls |
69 jeeves.rst psmith.html blandings.html |
61 jeeves.rst psmith.html blandings.html Music |
70 |
62 |
71 cd |
63 How do I move around the file system? |
72 --- |
64 ------------------------------------- |
73 |
65 |
74 This stands for "change directory". When one wants to change the directory . |
66 This stands for "change directory". When one wants to change the directory . |
75 |
67 |
76 $cd Music |
68 $cd Music |
77 |
69 |
78 One dot '.' represents the current directory while two dots '..' represent the parent directory. |
70 One dot '.' represents the current directory while two dots '..' represent the parent directory. |
79 |
71 |
80 “ cd -” will return you to the previous directory (a bit like an “undo”). |
72 “ cd -” will return you to the previous directory. |
81 |
73 |
82 You can also use cd absolute path or cd relative path (see below): |
74 You can also use cd [absolute path] or cd [relative path] (see below): |
83 |
75 |
84 Absolute paths: |
76 Absolute paths: |
85 |
77 |
86 An “ absolute path” is easily recognised from the leading forward slash, /. The / means that you start at the top level directory and continue down. |
78 Absolute Path is the path of the directory from root i.e / . / is the top most level in file system. |
87 |
79 |
88 For example to get to /boot/grub you would type:: |
80 For example to get to /var/www you would type:: |
89 |
81 |
90 $cd /boot/grub |
82 $cd /var/www |
91 |
83 |
92 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). |
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). |
93 |
85 |
94 Relative paths: |
86 Relative paths: |
95 |
87 |
96 A “ relative path” doesn't have a preceding slash. Use a relative path when you start from a directory below the top level directory structure. This is dependent on where you are in the filesystem. |
88 Releative Path is path in relation to your current location . |
97 |
89 |
98 For example if you are in root's home directory and want to get to /root/music, you type:: |
90 For example if you are in Music directory and want to get to Rock directory inside Music, you type:: |
99 |
91 |
100 $ cd music |
92 Music$ cd Rock |
101 |
93 |
102 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. |
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. |
103 |
95 |
104 who |
96 Linux is multiuser system so *who* all are using my system now? |
105 ---- |
97 -------------------------------------------------------- |
106 |
98 |
107 The standard Unix command *who* displays a list of users who are currently logged into a computer. |
99 The standard Unix command *who* displays a list of users who are currently logged into a computer.:: |
108 |
100 |
109 The *who* command is related to the command *w*, which provides the same information but also displays additional data and statistics.:: |
101 |
110 |
102 |
111 $who |
103 $who |
112 beeblebrox tty7 2009-09-08 10:50 (:0) |
104 user tty7 2009-09-08 10:50 (:0) |
113 beeblebrox pts/0 2009-09-08 11:25 (:0.0) |
105 harry pts/0 2009-09-08 11:25 (:0.0) |
114 dumbledore pts/1 2009-09-08 18:11 (potter.xyz.in) |
106 dumbledore pts/1 2009-09-08 18:11 (potter.xyz.in) |
115 beeblebrox pts/2 2009-09-08 18:53 (:0.0) |
107 |
116 |
108 The columns represent user, current terminal , date and time of login and the host from which he is logged in respectively. |
117 |
|
118 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). |
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). |
119 |
110 |
120 |
111 |
121 |
112 |
122 mkdir |
113 How do I organize my files? |
123 ----- |
114 --------------------------- |
124 |
115 |
125 This command is used to make a new directory. Normal usage is as straightforward as follows:: |
116 This command is used to make a new directory. Normal usage is as straightforward as follows:: |
126 |
117 |
127 $mkdir name_of_directory |
118 $mkdir name_of_directory |
128 |
119 |
129 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. |
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. |
130 |
121 |
131 |
122 |
132 |
123 |
133 |
124 |
134 pwd |
125 Where am I now in the filesystem? |
135 ---- |
126 -------------- |
136 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. |
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. |
137 |
128 |
138 pwd have one option called -P, which lists the current working directory with all the links resolved. |
129 Usage of pwd command:: |
139 |
130 |
140 Usage of pwd command |
131 $ cd Examples |
141 |
132 $ pwd |
142 I have a directory called "Examples/" on my machine which is actually a soft link to the directory /usr/share/example-content/. |
133 /home/user/Examples |
143 |
134 |
144 I move into the "Examples" directory and run the pwd command to get the following output. |
135 |
145 |
136 |
146 $ cd Examples |
137 I wish some commads were a bit smarter ? |
147 $ pwd |
138 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
148 /home/laf/Examples |
139 |
149 |
|
150 |
|
151 FLAGS |
|
152 ~~~~~ |
|
153 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 :: |
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 :: |
154 |
141 |
155 $ls -l |
142 $ls -l |
156 |
143 |
157 * *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 |
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 :: |
|
145 |
|
146 $ls a |
|
147 * *ls with flag -a* lists all files including hidden files |
|
148 |
|
149 |
|
150 Similarly, mkdir with -p option automatically creates parent directory even if it does not exist.:: |
|
151 |
|
152 $mkdir -p this/path/never/existed/earlier/ |
|
153 |
158 |
154 |
159 |
155 |
160 |
156 |
161 Getting Help |
157 Getting Help |
162 ============ |
158 ============ |
163 |
159 |
164 apropos and whatis |
160 How do I find what a command does? |
165 ------------------- |
161 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
166 |
|
167 This is a command to search the manual pages files in Unix and Unix-like operating systems. :: |
|
168 |
|
169 $ apropos grep |
|
170 egrep egrep (1) Search a file for a pattern using full regular expressions |
|
171 fgrep fgrep (1) Search a file for a fixed-character string |
|
172 fmlgrep fmlgrep (1) Search a file for a pattern |
|
173 grep grep (1) Search a file for a pattern |
|
174 gzgrep gzgrep (1) Search a possibly compressed file for a regular expression |
|
175 nisgrep nismatch (1) Utilities for searching NIS+ tables |
|
176 pgrep pgrep (1) Find or signal a process by name or other attribute |
|
177 zgrep zgrep (1) Search a possibly compressed file for a regular expression |
|
178 ... |
|
179 |
|
180 In this example, the user uses *apropos* to search for the string "grep", and apropos returns the indicated *man* pages that include the term "grep". |
|
181 |
162 |
182 A short index of explanations for commands is available using the *whatis* command, like in the examples below:: |
163 A short index of explanations for commands is available using the *whatis* command, like in the examples below:: |
183 |
164 |
184 $whatis ls |
165 $whatis ls |
185 ls (1) - list directory contents |
166 ls (1) - list directory contents |
186 |
167 |
187 This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page. |
168 This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page. |
188 |
169 |
189 If you don't know where to get started and which man page to read, *apropos* gives more information. Say that you do not know how to start a browser, then you could enter the following command:: |
170 More extensive Documentation |
190 |
171 ---------------------------- |
191 $apropos browser |
|
192 gmusicbrowser (1) - Jukebox for large collections of audio files |
|
193 infobrowser (1) - read Info documents |
|
194 libsmbclient (7) - An extension library for browsers and that can be used... |
|
195 opera (1) - a standards-compliant graphical Web browser |
|
196 sensible-browser (1) - sensible editing, paging, and web browsing |
|
197 smbtree (1) - A text based smb network browser |
|
198 tvtk_doc (1) - A GUI based TVTK documentation search browser. |
|
199 viewres (1) - graphical class browser for Xt |
|
200 w3m (1) - a text based Web browser and pager |
|
201 www-browser (1) - a text based Web browser and pager |
|
202 ... |
|
203 |
|
204 man |
|
205 ---- |
|
206 |
172 |
207 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. |
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. |
208 |
174 |
209 To read a manual page for a Unix command, one can use:: |
175 To read a manual page for a Unix command, one can use:: |
210 |
176 |
211 $ man <command_name> |
177 $ man <command_name> |
212 |
178 |
213 at a shell prompt; for example, "man ftp". In order to simplify navigation through the output, *man* generally uses the less terminal pager. |
|
214 |
|
215 To see the manual on man itself do:: |
179 To see the manual on man itself do:: |
216 |
180 |
217 $man man |
181 $man man |
218 |
182 |
219 The previous example will take you to the "Manual" page entry about manual pages! |
183 The previous example will take you to the "Manual" page entry about manual pages! |
220 |
184 |
221 |
185 Looking at man pages is a very good way to actually check flags and other help related to a command. |
222 info |
|
223 ----- |
|
224 |
|
225 *info* is a software utility which forms a hypertextual, multipage documentation and help viewer working on a command line interface, useful when there is no GUI available. |
|
226 |
|
227 The syntax is :: |
|
228 |
|
229 $ info <command_name> |
|
230 |
|
231 *info* processes info files, which are Texinfo formatted files, and presents the documentation as a tree, with simple commands to traverse the tree and to follow cross references. For instance |
|
232 |
|
233 - *n* goes to the next page. |
|
234 - *p* goes to the previous page. |
|
235 - *u* goes to the upper page. |
|
236 - *l* goes to the last(visited) node |
|
237 - To follow a cross reference, the cursor can be moved over a link (a word preceded by a `*`) and enter pressed. |
|
238 |
|
239 info was initially written for use with GNU/Linux and then ported to other Unix-like operating systems. |
|
240 |
186 |
241 --help |
187 --help |
242 ------- |
188 ------- |
243 |
189 |
244 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 *cat* command:: |
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:: |
245 |
191 |
246 $ userprompt@host: cat --help |
192 $ mkdir --help |
247 Usage: cat [OPTION] [FILE]... |
193 |
248 Concatenate FILE(s), or standard input, to standard output. |
194 Usage: mkdir [OPTION]... DIRECTORY... |
249 |
195 Create the DIRECTORY(ies), if they do not already exist. |
250 -A, --show-all equivalent to -vET |
196 |
251 -b, --number-nonblank number nonempty output lines |
197 Mandatory arguments to long options are mandatory for short options too. |
252 -e equivalent to -vE |
198 -m, --mode=MODE set file mode (as in chmod), not a=rwx - umask |
253 -E, --show-ends display $ at end of each line |
199 -p, --parents no error if existing, make parent directories as needed |
254 -n, --number number all output lines |
200 -v, --verbose print a message for each created directory |
255 -s, --squeeze-blank suppress repeated empty output lines |
201 -Z, --context=CTX set the SELinux security context of each created |
256 -t equivalent to -vT |
202 directory to CTX |
257 -T, --show-tabs display TAB characters as ^I |
203 --help display this help and exit |
258 -u (ignored) |
204 --version output version information and exit |
259 -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB |
205 |
260 --help display this help and exit |
206 Report mkdir bugs to bug-coreutils@gnu.org |
261 --version output version information and exit |
207 GNU coreutils home page: <http://www.gnu.org/software/coreutils/> |
262 |
208 General help using GNU software: <http://www.gnu.org/gethelp/> |
263 With no FILE, or when FILE is -, read standard input. |
209 Report mkdir translation bugs to <http://translationproject.org/team/> |
264 |
|
265 Examples: |
|
266 cat f - g Output f's contents, then standard input, then g's contents. |
|
267 cat Copy standard input to standard output. |
|
268 |
|
269 Report bugs to <bug-coreutils@gnu.org>. |
|
270 |
210 |
271 |
211 |
272 |
212 |
273 Basic file handling |
213 Basic file handling |
274 =================== |
214 =================== |
275 |
215 |
276 cp |
216 Copying Files |
277 --- |
217 ------------- |
278 |
218 |
279 *cp* is the command entered in a Unix shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name. |
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. |
280 |
220 |
281 Usage |
221 Usage |
282 ~~~~~ |
222 ~~~~~ |
283 |
223 |
284 To copy a file to another file:: |
224 To copy a file to another file :: |
285 |
225 |
286 $ cp SourceFile TargetFile |
226 $ cp SourceFile TargetFile |
287 |
227 |
288 To copy a file to a directory:: |
228 To copy a file to a directory:: |
289 |
229 |
291 |
231 |
292 To copy a directory to a directory:: |
232 To copy a directory to a directory:: |
293 |
233 |
294 $ cp -r SourceDirectory TargetDirectory |
234 $ cp -r SourceDirectory TargetDirectory |
295 |
235 |
|
236 In case target Directory has a file of the same name:: |
|
237 |
|
238 TargetDirectory$ls |
|
239 jeeves.rst psmith.html |
|
240 |
|
241 SourceDirectory$ls |
|
242 jeeves.rst index.html |
|
243 |
|
244 $cp -i jeeves.rst TargetDirectory/ |
|
245 cp: overwrite 'TargetDirectory/jeeves.rst'? |
|
246 |
|
247 -i option is for interactive usage. |
|
248 |
|
249 |
296 Flags |
250 Flags |
297 ~~~~~ |
251 ~~~~~ |
298 |
|
299 |
|
300 *-P* – makes the cp command copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point. |
|
301 |
|
302 *-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. |
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. |
303 |
253 |
304 *-p* (preserve) – duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory: |
254 |
305 |
255 *-r* (recursive) – copy directories (recursively copying all the contents) |
306 * The time of the last data modification and the time of the last access. |
256 |
307 * The user ID and group ID (only if it has permissions to do this) |
257 |
308 * The file permission bits and the SUID and SGID bits. |
258 Moving Files |
309 |
259 ------------ |
310 *-R* (recursive) – copy directories (recursively copying all the contents) |
260 |
311 |
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. |
312 Examples |
262 |
|
263 |
|
264 |
|
265 Usage |
313 ~~~~~~~~ |
266 ~~~~~~~~ |
314 |
267 |
315 To make a copy of a file in the current directory, enter:: |
268 |
316 |
269 To rename a file :: |
317 $ cp prog.c prog.bak |
270 |
318 |
271 $ mv myfile mynewfilename |
319 This copies prog.c to prog.bak. If the prog.bak file does not already exist, the cp command creates it. If it does exist, the cp command replaces it with a copy of the prog.c file. |
272 |
320 |
273 To move to a different directory :: |
321 To copy a file in your current directory into another directory, enter:: |
274 $ mv myfile otherdir/ |
322 |
275 |
323 $ cp zaphod /home/books/hhgg |
276 To move a directory :: |
324 |
277 |
325 This copies the jones file to /home/books/hhgg/zaphod. |
278 $mv mydir otherdir |
326 |
279 |
327 To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:: |
280 |
328 |
281 Using -i to avoid overwrite(just like cp):: |
329 $ cp -p martin_luther_king martin_luther_king.jr |
282 |
330 |
283 $mv -i mydir otherdir |
331 This copies the *martin_luther_king* file to the *martin_luther_king.jr* file. Instead of creating the file with the current date and time stamp, the system gives the *martin_luther_king.jr* file the same date and time as the *martin_luther_king* file. The *martin_luther_king.jr* file also inherits the *martin_luther_king* file's access control protection. |
284 mv: overwrite `otherdir/mydir'? |
332 |
285 |
333 To copy all the files in a directory to a new directory, enter:: |
286 |
334 |
287 Removing files |
335 $ cp /home/galactica/clients/* /home/hhgg/customers |
288 -------------- |
336 |
289 |
337 This copies only the files in the clients directory to the customers directory. |
290 *rm* is used to delete files from a filesystem. |
338 |
|
339 To copy a directory, including all its files and subdirectories, to another directory, enter: |
|
340 |
|
341 $ cp -R /home/hhgg/clients /home/hhgg/customers |
|
342 |
|
343 This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory. |
|
344 |
|
345 To copy a specific set of files of any extension to another directory, enter:: |
|
346 |
|
347 $ cp zaphod arthur ford /home/hhgg/clients |
|
348 |
|
349 This copies the *zaphod*, *arthur*, and *ford* files in your current working directory to the /home/hhgg/clients directory. |
|
350 |
|
351 To use pattern-matching characters to copy files, enter:: |
|
352 |
|
353 $ cp programs/*.py . |
|
354 |
|
355 This copies the files in the programs directory that end with *.py* to the current directory, signified by the single "." (dot). You must type a space between the *py* and the final dot. |
|
356 |
|
357 mv |
|
358 --- |
|
359 |
|
360 *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. If possible (i.e. when the original and new files are on the same file system), *mv* will rename the file instead. Write permission is required on all directories being modified. |
|
361 |
|
362 Conflicting existing file |
|
363 ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
364 |
|
365 In all cases, when a file is moved to have the name of an existing file (in the same directory), the existing file is deleted. If the existing file is not writable but is in a directory that is writable, then the mv command asks for confirmation if possible (i.e. if run from a terminal) before proceeding, unless the -f (force) option is used. |
|
366 |
|
367 Differences with copy and delete |
|
368 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
369 |
|
370 Note that, usually, when moving files within the same volume, moving (and/or renaming) is not the same as simply copying and then deleting the original. When moving a file, the link is simply removed from the old parent directory and added to the new parent directory. However, the file itself is untouched (i.e. it has the same inodes and resides at the same place on the disk). For example, you cannot copy a file you cannot read, but you can move (and/or rename) it (provided you have write permission to its old and new parent directories). Also, suppose there is a non-empty directory you do not have write permission to. You cannot delete this directory (since you cannot delete its contents); but you can move (and/or rename) it. Also, since moving between filenames on a single volume does not involve copying, it is faster and does not place strain of lots of reads and writes on the disk. Moving files across different volumes, however, does necessitate copying and deleting. |
|
371 |
|
372 Examples |
|
373 ~~~~~~~~ |
|
374 :: |
|
375 |
|
376 $ mv myfile mynewfilename renames a file |
|
377 $ mv myfile /myfile moves 'myfile' from the current directory to the root directory |
|
378 $ mv myfile dir/myfile moves 'myfile' to 'dir/myfile' relative to the current directory |
|
379 $ mv myfile dir same as the previous command (the filename is implied to be the same) |
|
380 $ mv myfile dir/myfile2 moves 'myfile' to dir and renames it to 'myfile2' |
|
381 $ mv foo bar baz dir moves multiple files to directory dir |
|
382 $ mv --help shows a very concise help about the syntax of the command |
|
383 $ man mv prints an extensive user manual for 'mv' in the terminal |
|
384 |
|
385 In all cases, the file or files being moved or renamed can be a directory. |
|
386 |
|
387 Note that when the command is called with two arguments (as *mv name1 name2* or *mv name1 /dir/name2*), it can have three different effects, depending on whether *name2* does not exist, is an existing file, or is an existing directory. If the user intends to refer to an existing directory, */.* (or in some Unix versions */* is sufficient) may be appended to the name to force the system to check this. To move a file to a new directory, the directory must be created first. |
|
388 |
|
389 rm |
|
390 --- |
|
391 |
|
392 *rm* (short for "remove") is one of several basic Unix command lines that operates on files. It is used to delete files from a filesystem. The data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused. |
|
393 |
291 |
394 Here's example to remove a file named "foo" from a directory, here shown with the -i option:: |
292 Here's example to remove a file named "foo" from a directory, here shown with the -i option:: |
395 |
293 |
396 $ rm -i foo |
294 $ rm -i foo |
397 remove foo? y |
295 remove foo? y |
466 |
448 |
467 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:: |
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:: |
468 |
450 |
469 $ tail -n 20 filename |
451 $ tail -n 20 filename |
470 |
452 |
471 This example shows the last 15 bytes of all files starting with *foo*:: |
453 |
472 |
|
473 $ tail -c 15 foo* |
|
474 |
454 |
475 This example shows all lines of filename from the second line onwards:: |
455 This example shows all lines of filename from the second line onwards:: |
476 |
456 |
477 $ tail -n +2 filename |
457 $ tail -n +2 filename |
478 |
458 |
479 |
459 |
480 |
460 |
481 File monitoring |
461 Monitoring a continously changing file(example: A log file) |
482 ~~~~~~~~~~~~~~~ |
462 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
483 |
463 |
484 *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:: |
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:: |
485 |
465 |
486 $ tail -f /var/adm/messages |
466 $ tail -f /var/log/dmesg |
487 |
467 |
488 To interrupt tail while it is monitoring, break-in with *Ctrl+C*. This command can be run "in the background" with &, see job control. |
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. |
489 |
469 |
490 If you have a command's result to monitor, you can use the *watch* command. |
470 More serious Text Processing: |
|
471 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
472 |
|
473 Problem get the names of people in the following file |
|
474 ----------------------------------------------------- |
|
475 :: |
|
476 |
|
477 Foot in Mouth:Bully:Fat:Peter |
|
478 Rich:Simple:Peabrain:Lois |
|
479 Self-concious:Wannabe:Adolescent:Meg |
|
480 Dim-witted:Fat:evil-monkey:Chris |
|
481 Matricidal:Over-Ambitious:Infant:Stewy |
|
482 Anthropomorphic:Democrat:Sensible:Brian |
|
483 |
|
484 |
|
485 $cut -d : -f 4- file |
|
486 |
|
487 Peter |
|
488 Lois |
|
489 Meg |
|
490 Chris |
|
491 Stewy |
|
492 Brian |
|
493 |
|
494 |
|
495 |
|
496 |
491 |
497 |
492 |
498 |
493 cut |
499 cut |
494 ---- |
500 ---- |
495 |
501 |
496 In computing, *cut* is a Unix command line utility which is used to extract sections from each line of input — usually from a file. |
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. |
497 |
503 |
498 Extraction of line segments can typically be done by *bytes (-b), characters (-c)*, or *fields (-f)* separated by a *delimiter (-d — the tab character by default)*. A range must be provided in each case 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). Since version 6, an error is thrown if you include a zeroth value. Prior to this the value was ignored and assumed to be 1. |
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). |
499 |
505 |
500 Assuming a file named file containing the lines:: |
506 |
501 |
507 Options |
502 foo:bar:baz:qux:quux |
508 ------- |
503 one:two:three:four:five:six:seven |
509 :: |
504 alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu |
510 |
505 |
511 |
506 To output the fourth through tenth characters of each line:: |
512 |
507 |
513 |
508 $ cut -c 4-10 file |
514 |
509 |
515 |
510 This gives the output:: |
|
511 |
|
512 :bar:ba |
|
513 :two:th |
|
514 ha:beta |
|
515 |
|
516 To output the fifth field through the end of the line of each line using the colon character as the field delimiter:: |
|
517 |
|
518 $ cut -d : -f 5- file |
|
519 |
|
520 This gives the output:: |
|
521 |
|
522 quux |
|
523 five:six:seven |
|
524 epsilon:zeta:eta:teta:iota:kappa:lambda:mu |
|
525 |
516 |
526 paste |
517 paste |
527 ------ |
518 ------ |
528 |
519 |
529 *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. |
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. |