|
48 | 48 | 6 25 greeting.txt |
49 | 49 | </code></pre><p>Filename won't be printed for stdin data. This is helpful to save the results in a variable for scripting purposes.<pre><code class=language-bash>$ wc -l <greeting.txt |
50 | 50 | 2 |
51 | | -</code></pre><p>Word count is based on whitespace separation. You'll have to pre-process the input if you do not want certain non-whitespace characters to influence the results. <code>tr</code> can be used to remove a particular set of characters (this command will be discussed in <a href=/assorted-text-processing-tools.html>Assorted Text Processing Tools</a> chapter).<pre><code class=language-bash>$ echo 'apple ; banana ; cherry' | wc -w |
| 51 | +</code></pre><p>Word count is based on whitespace separation. You'll have to pre-process the input if you do not want certain non-whitespace characters to influence the results. <code>tr</code> can be used to remove a particular set of characters (this command will be discussed in the <a href=/assorted-text-processing-tools.html>Assorted Text Processing Tools</a> chapter).<pre><code class=language-bash>$ echo 'apple ; banana ; cherry' | wc -w |
52 | 52 | 5 |
53 | 53 |
|
54 | 54 | # remove characters other than alphabets and whitespace |
|
180 | 180 | $ touch -m -d '2000-01-01 00:00:01' hi.sh |
181 | 181 | $ stat -c '%y' hi.sh |
182 | 182 | 2000-01-01 00:00:01.000000000 +0530 |
183 | | -</code></pre><p>As seen in <a href=./managing-files-directories.html>Managing Files and Directories</a> chapter, <code>touch</code> creates a new file if the target file doesn't exist yet. You can use the <code>-c</code> option to prevent this behavior.<pre><code class=language-bash>$ ls report.txt |
| 183 | +</code></pre><p>As seen in the <a href=./managing-files-directories.html>Managing Files and Directories</a> chapter, <code>touch</code> creates a new file if the target file doesn't exist yet. You can use the <code>-c</code> option to prevent this behavior.<pre><code class=language-bash>$ ls report.txt |
184 | 184 | ls: cannot access 'report.txt': No such file or directory |
185 | 185 | $ touch report.txt |
186 | 186 | $ ls report.txt |
|
344 | 344 | 7.7M report.log |
345 | 345 | 8.2k todos |
346 | 346 | 7.8M total |
347 | | -</code></pre><p><strong>8)</strong> When will you use the <code>df</code> command instead of <code>du</code>? Which <code>df</code> command option will help you to report only specific fields of interest?<p><strong>9)</strong> Display the size of <code>scores.csv</code> and <code>timings.txt</code> files in the format shown below.<pre><code class=language-bash>$ stat # ??? |
| 347 | +</code></pre><p><strong>8)</strong> What does the <code>du --apparent-size</code> option do?<p><strong>9)</strong> When will you use the <code>df</code> command instead of <code>du</code>? Which <code>df</code> command option will help you to report only specific fields of interest?<p><strong>10)</strong> Display the size of <code>scores.csv</code> and <code>timings.txt</code> files in the format shown below.<pre><code class=language-bash>$ stat # ??? |
348 | 348 | scores.csv: 70 |
349 | 349 | timings.txt: 49 |
350 | | -</code></pre><p><strong>10)</strong> Which <code>touch</code> option will help you prevent file creation if it doesn't exist yet?<p><strong>11)</strong> Assume <code>new_file.txt</code> doesn't exist in the current working directory. What would be the output of the <code>stat</code> command shown below?<pre><code class=language-bash>$ touch -t '202010052010.05' new_file.txt |
| 350 | +</code></pre><p><strong>11)</strong> Which <code>touch</code> option will help you prevent file creation if it doesn't exist yet?<p><strong>12)</strong> Assume <code>new_file.txt</code> doesn't exist in the current working directory. What would be the output of the <code>stat</code> command shown below?<pre><code class=language-bash>$ touch -t '202010052010.05' new_file.txt |
351 | 351 | $ stat -c '%y' new_file.txt |
352 | 352 | # ??? |
353 | | -</code></pre><p><strong>12)</strong> Is the following <code>touch</code> command valid? If so, what would be the output of the <code>stat</code> command that follows?<pre><code class=language-bash># change to the 'scripts' directory and source the 'touch.sh' script |
| 353 | +</code></pre><p><strong>13)</strong> Is the following <code>touch</code> command valid? If so, what would be the output of the <code>stat</code> command that follows?<pre><code class=language-bash># change to the 'scripts' directory and source the 'touch.sh' script |
354 | 354 | $ source touch.sh |
355 | 355 |
|
356 | 356 | $ touch -r fruits.txt f{1..3}.txt |
357 | 357 | $ stat -c '%n: %y' f*.txt |
358 | 358 | # ??? |
359 | | -</code></pre><p><strong>13)</strong> Use appropriate option(s) to get the output shown below.<pre><code class=language-bash>$ printf 'αλεπού\n' | file - |
| 359 | +</code></pre><p><strong>14)</strong> Use appropriate option(s) to get the output shown below.<pre><code class=language-bash>$ printf 'αλεπού\n' | file - |
360 | 360 | /dev/stdin: UTF-8 Unicode text |
361 | 361 |
|
362 | 362 | $ printf 'αλεπού\n' | file # ??? |
363 | 363 | UTF-8 Unicode text |
364 | | -</code></pre><p><strong>14)</strong> Is the following command valid? If so, what would be the output?<pre><code class=language-bash>$ basename -s.txt ~///test.txt/// |
| 364 | +</code></pre><p><strong>15)</strong> Is the following command valid? If so, what would be the output?<pre><code class=language-bash>$ basename -s.txt ~///test.txt/// |
365 | 365 | # ??? |
366 | | -</code></pre><p><strong>15)</strong> Given the file path in the shell variable <code>p</code>, how'd you obtain the output shown below?<pre><code class=language-bash>$ p='~/projects/square_tictactoe/python/game.py' |
| 366 | +</code></pre><p><strong>16)</strong> Given the file path in the shell variable <code>p</code>, how'd you obtain the output shown below?<pre><code class=language-bash>$ p='~/projects/square_tictactoe/python/game.py' |
367 | 367 | $ dirname # ??? |
368 | 368 | ~/projects/square_tictactoe |
369 | | -</code></pre><p><strong>16)</strong> Explain what each of the characters mean in the following output.<pre><code class=language-bash>$ stat -c '%A' ../scripts/ |
| 369 | +</code></pre><p><strong>17)</strong> Explain what each of the characters mean in the following output.<pre><code class=language-bash>$ stat -c '%A' ../scripts/ |
370 | 370 | drwxrwxr-x |
371 | | -</code></pre><p><strong>17)</strong> What would be the output of the second <code>stat</code> command shown below?<pre><code class=language-bash>$ touch new_file.txt |
| 371 | +</code></pre><p><strong>18)</strong> What would be the output of the second <code>stat</code> command shown below?<pre><code class=language-bash>$ touch new_file.txt |
372 | 372 | $ stat -c '%a %A' new_file.txt |
373 | 373 | 664 -rw-rw-r-- |
374 | 374 |
|
375 | 375 | $ chmod 546 new_file.txt |
376 | 376 | $ stat -c '%a %A' new_file.txt |
377 | 377 | # ??? |
378 | | -</code></pre><p><strong>18)</strong> How would you specify directory permissions using the <code>mkdir</code> command?<pre><code class=language-bash># instead of this |
| 378 | +</code></pre><p><strong>19)</strong> How would you specify directory permissions using the <code>mkdir</code> command?<pre><code class=language-bash># instead of this |
379 | 379 | $ mkdir back_up |
380 | 380 | $ chmod 750 back_up |
381 | 381 | $ stat -c '%a %A' back_up |
|
386 | 386 | $ mkdir # ??? |
387 | 387 | $ stat -c '%a %A' back_up |
388 | 388 | 750 drwxr-x--- |
389 | | -</code></pre><p><strong>19)</strong> Change the file permission of <code>book_list.txt</code> to match the output of the second <code>stat</code> command shown below. Don't use the number <code>220</code>, specify the changes in terms of <code>rwx</code> characters.<pre><code class=language-bash>$ touch book_list.txt |
| 389 | +</code></pre><p><strong>20)</strong> Change the file permission of <code>book_list.txt</code> to match the output of the second <code>stat</code> command shown below. Don't use the number <code>220</code>, specify the changes in terms of <code>rwx</code> characters.<pre><code class=language-bash>$ touch book_list.txt |
390 | 390 | $ stat -c '%a %A' book_list.txt |
391 | 391 | 664 -rw-rw-r-- |
392 | 392 |
|
393 | 393 | # ??? |
394 | 394 | $ stat -c '%a %A' book_list.txt |
395 | 395 | 220 --w--w---- |
396 | | -</code></pre><p><strong>20)</strong> Change the permissions of <code>test_dir</code> to match the output of the second <code>stat</code> command shown below. Don't use the number <code>757</code>, specify the changes in terms of <code>rwx</code> characters.<pre><code class=language-bash>$ mkdir test_dir |
| 396 | +</code></pre><p><strong>21)</strong> Change the permissions of <code>test_dir</code> to match the output of the second <code>stat</code> command shown below. Don't use the number <code>757</code>, specify the changes in terms of <code>rwx</code> characters.<pre><code class=language-bash>$ mkdir test_dir |
397 | 397 | $ stat -c '%a %A' test_dir |
398 | 398 | 775 drwxrwxr-x |
399 | 399 |
|
|
0 commit comments