1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org" />
<title>Handling Files and Directories</title>
<meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" />
<link rel="HOME" title="Slackware Linux Essentials" href="index.html" />
<link rel="PREVIOUS" title="NFS Mounts" href="filesystem-structure-nfs.html" />
<link rel="NEXT" title="Pagers: more, less, and most" href="file-commands-pagers.html" />
<link rel="STYLESHEET" type="text/css" href="docbook.css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body class="CHAPTER" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"
alink="#0000FF">
<div class="NAVHEADER">
<table summary="Header navigation table" width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<th colspan="3" align="center">Slackware Linux Essentials</th>
</tr>
<tr>
<td width="10%" align="left" valign="bottom"><a href="filesystem-structure-nfs.html"
accesskey="P">Prev</a></td>
<td width="80%" align="center" valign="bottom"></td>
<td width="10%" align="right" valign="bottom"><a href="file-commands-pagers.html"
accesskey="N">Next</a></td>
</tr>
</table>
<hr align="LEFT" width="100%" />
</div>
<div class="CHAPTER">
<h1><a id="FILE-COMMANDS" name="FILE-COMMANDS"></a>Chapter 10 Handling Files and
Directories</h1>
<div class="TOC">
<dl>
<dt><b>Table of Contents</b></dt>
<dt>10.1 <a href="file-commands.html#FILE-COMMANDS-NAVIGATION">Navigation : <tt
class="COMMAND">ls</tt>, <tt class="COMMAND">cd</tt>, and <tt
class="COMMAND">pwd</tt></a></dt>
<dt>10.2 <a href="file-commands-pagers.html">Pagers: <tt class="COMMAND">more</tt>, <tt
class="COMMAND">less</tt>, and <tt class="COMMAND">most</tt></a></dt>
<dt>10.3 <a href="file-commands-output.html">Simple Output: <tt class="COMMAND">cat</tt>
and <tt class="COMMAND">echo</tt></a></dt>
<dt>10.4 <a href="file-commands-creation.html">Creation: <tt class="COMMAND">touch</tt>
and <tt class="COMMAND">mkdir</tt></a></dt>
<dt>10.5 <a href="file-commands-copymove.html">Copy and Move</a></dt>
<dt>10.6 <a href="file-commands-deletion.html">Deletion: <tt class="COMMAND">rm</tt> and
<tt class="COMMAND">rmdir</tt></a></dt>
<dt>10.7 <a href="file-commands-link.html">Aliasing files with <tt
class="COMMAND">ln</tt></a></dt>
</dl>
</div>
<p>Linux aims to the most Unix-like it can be. Traditionally, Unix operating systems have
been command-line oriented. We do have a graphical user interface in Slackware, but the
command-line is still the main level of control for the system. Therefore, it is
important to understand some of the basic file management commands.</p>
<p>The following sections explain the common file management commands and provide
examples of how they are used. There are many other commands, but these will help you get
started. Also, the commands are only briefly discussed here. You will find more detail in
the accompanying man pages for each command.</p>
<div class="SECT1">
<h1 class="SECT1"><a id="FILE-COMMANDS-NAVIGATION" name="FILE-COMMANDS-NAVIGATION">10.1
Navigation : <tt class="COMMAND">ls</tt>, <tt class="COMMAND">cd</tt>, and <tt
class="COMMAND">pwd</tt></a></h1>
<div class="SECT2">
<h2 class="SECT2"><a id="AEN3398" name="AEN3398">10.1.1 <tt
class="COMMAND">ls</tt></a></h2>
<p>This command lists files in a directory. Windows and DOS users will notice its
similarity to the <tt class="COMMAND">dir</tt> command. By itself, <tt
class="COMMAND">ls</tt>(1) will list the files in the current directory. To see what's in
your root directory, you could issue these commands:</p>
<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">cd /</kbd>
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">ls</kbd>
bin cdr dev home lost+found proc sbin tmp var
boot cdrom etc lib mnt root suncd usr vmlinuz
</pre>
</td>
</tr>
</table>
<p>The problem a lot of people have with that output is that you cannot easily tell what
is a directory and what is a file. Some users prefer that <tt class="COMMAND">ls</tt> add
a type identifier to each listing, like this:</p>
<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">ls -FC</kbd>
bin/ cdr/ dev/ home/ lost+found/ proc/ sbin/ tmp/ var/
boot/ cdrom/ etc/ lib/ mnt/ root/ suncd/ usr/ vmlinuz
</pre>
</td>
</tr>
</table>
<p>Directories get a slash at the end of the name, executable files get an asterisk at
the end of the name, and so on.</p>
<p><tt class="COMMAND">ls</tt> can also be used to get other statistics on files. For
example, to see the creation dates, owners, and permissions, you would look at a long
listing:</p>
<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">ls -l</kbd>
drwxr-xr-x 2 root bin 4096 May 7 09:11 bin/
drwxr-xr-x 2 root root 4096 Feb 24 03:55 boot/
drwxr-xr-x 2 root root 4096 Feb 18 01:10 cdr/
drwxr-xr-x 14 root root 6144 Oct 23 18:37 cdrom/
drwxr-xr-x 4 root root 28672 Mar 5 18:01 dev/
drwxr-xr-x 10 root root 4096 Mar 8 03:32 etc/
drwxr-xr-x 8 root root 4096 Mar 8 03:31 home/
drwxr-xr-x 3 root root 4096 Jan 23 21:29 lib/
drwxr-xr-x 2 root root 16384 Nov 1 08:53 lost+found/
drwxr-xr-x 2 root root 4096 Oct 6 12:47 mnt/
dr-xr-xr-x 62 root root 0 Mar 4 15:32 proc/
drwxr-x--x 12 root root 4096 Feb 26 02:06 root/
drwxr-xr-x 2 root bin 4096 Feb 17 02:02 sbin/
drwxr-xr-x 5 root root 2048 Oct 25 10:51 suncd/
drwxrwxrwt 4 root root 487424 Mar 7 20:42 tmp/
drwxr-xr-x 21 root root 4096 Aug 24 03:04 usr/
drwxr-xr-x 18 root root 4096 Mar 8 03:32 var/
</pre>
</td>
</tr>
</table>
<p>Suppose you want to get a listing of the hidden files in the current directory. This
command will do just that:</p>
<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">ls -a</kbd>
. bin cdrom home mnt sbin usr
.. boot dev lib proc suncd var
.pwrchute_tmp cdr etc lost+found root tmp vmlinuz
</pre>
</td>
</tr>
</table>
<p>Files beginning with a period (called dot files) are hidden when you run <tt
class="COMMAND">ls</tt>. You will only see them if you pass the <var
class="OPTION">-a</var> option.</p>
<p>There are many more options that can be found in the online manual page. Don't forget
that you can combine options that you pass to <tt class="COMMAND">ls</tt>.</p>
</div>
<div class="SECT2">
<h2 class="SECT2"><a id="AEN3436" name="AEN3436">10.1.2 <tt
class="COMMAND">cd</tt></a></h2>
<p>The <tt class="COMMAND">cd</tt> command is used to change working directories. You
simply type <tt class="COMMAND">cd</tt> followed by the path name to change to. Here are
some examples:</p>
<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
darkstar:~$ <kbd class="USERINPUT">cd /bin</kbd>
darkstar:/bin$ <kbd class="USERINPUT">cd usr</kbd>
bash: cd: usr: No such file or directory
darkstar:/bin$ <kbd class="USERINPUT">cd /usr</kbd>
darkstar:/usr$ <kbd class="USERINPUT">ls</kbd>
bin
darkstar:/usr$ <kbd class="USERINPUT">cd bin</kbd>
darkstar:/usr/bin$
</pre>
</td>
</tr>
</table>
<p>Notice that without the preceding slash, it tries to change to a directory in the
current directory. Also executing <tt class="COMMAND">cd</tt> with no options will move
you to your home directory.</p>
<p>The <tt class="COMMAND">cd</tt> command is not like the other commands. It is a
builtin shell command. Shell builtins are discussed in <a
href="shell-bash.html#SHELL-BASH-ENVIRONMENT">Section 8.3.1</a>. This may not make any
sense to you right now. Basically it means there is no man page for this command.
Instead, you have to use the shell help. Like this:</p>
<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">help cd</kbd>
</pre>
</td>
</tr>
</table>
<p>It will display the options for <tt class="COMMAND">cd</tt> and how to use them.</p>
</div>
<div class="SECT2">
<h2 class="SECT2"><a id="AEN3463" name="AEN3463">10.1.3 <tt
class="COMMAND">pwd</tt></a></h2>
<p>The <tt class="COMMAND">pwd</tt> command is used to show your current location. To use
the <tt class="COMMAND">pwd</tt> command just type <tt class="COMMAND">pwd</tt>. For
example:</p>
<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">cd /bin</kbd>
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">pwd</kbd>
/bin
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">cd /usr</kbd>
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">cd bin</kbd>
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">pwd</kbd>
/usr/bin
</pre>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="NAVFOOTER">
<hr align="LEFT" width="100%" />
<table summary="Footer navigation table" width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td width="33%" align="left" valign="top"><a href="filesystem-structure-nfs.html"
accesskey="P">Prev</a></td>
<td width="34%" align="center" valign="top"><a href="index.html"
accesskey="H">Home</a></td>
<td width="33%" align="right" valign="top"><a href="file-commands-pagers.html"
accesskey="N">Next</a></td>
</tr>
<tr>
<td width="33%" align="left" valign="top">NFS Mounts</td>
<td width="34%" align="center" valign="top"> </td>
<td width="33%" align="right" valign="top">Pagers: <tt class="COMMAND">more</tt>, <tt
class="COMMAND">less</tt>, and <tt class="COMMAND">most</tt></td>
</tr>
</table>
</div>
</body>
</html>
|