You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ # when -p is used, mkdir won't give an error if directory already exists
356
+
$ mkdir -p reports
357
+
$ echo$?
358
+
0
359
+
360
+
$ # error because 'a/b' doesn't exist
361
+
$ mkdir a/b/c
362
+
mkdir: cannot create directory ‘a/b/c’: No such file or directory
363
+
$ # with -p, any non-existing directory will be created as well
364
+
$ mkdir -p a/b/c
365
+
$ ls -1R a
366
+
a:
367
+
b
368
+
369
+
a/b:
370
+
c
371
+
372
+
a/b/c:
373
+
```
374
+
375
+
**Further Reading**
329
376
330
-
*`mkdir project_adder` create folder project_adder in current directory
331
-
*`mkdir project_adder/report` create folder report in project_adder directory
332
-
*`mkdir -p project_adder/report` create both project_adder and report directories in one shot
333
-
* if project_adder already exists, it won't be affected
334
-
*`mkdir /home/guest1` add a home directory for user guest1
335
377
*[mkdir Q&A on unix stackexchange](https://unix.stackexchange.com/questions/tagged/mkdir?sort=votes&pageSize=15)
336
378
*[mkdir Q&A on stackoverflow](https://stackoverflow.com/questions/tagged/mkdir?sort=votes&pageSize=15)
379
+
*[unix.stackexchange: Characters best avoided in filenames](https://unix.stackexchange.com/questions/269093/characters-best-avoided-in-filenames-when-used-in-bash-e-g)
337
380
338
381
<br>
339
382
340
383
## <aname="touch"></a>touch
341
384
342
-
>change file timestamps
385
+
* Usually files are created using a text editor or by redirecting output of a command to a file
386
+
* But sometimes, for example to test file renaming, creating empty files comes in handy
387
+
* the `touch` command is primarily used to change timestamp of a file (see [touch](./Working_with_Files_and_Directories.md#touch) section of next chapter)
388
+
* if a filename given to `touch` doesn't exist, an empty file gets created with current timestamp
343
389
344
-
When a filename is passed as argument to `touch` command that doesn't exist, it creates an empty file
345
-
More info on this command is covered in a later chapter
346
-
347
-
*`touch error.log` creates an empty file error.log in current directory if it doesn't exist
348
-
*[touch Q&A on unix stackexchange](https://unix.stackexchange.com/questions/tagged/touch?sort=votes&pageSize=15)
390
+
```bash
391
+
$ touch ip.txt
392
+
$ ls -1F
393
+
a/
394
+
ip.txt
395
+
low power adders/
396
+
reports/
397
+
```
349
398
350
399
<br>
351
400
@@ -367,6 +416,7 @@ More info on this command is covered in a later chapter
367
416
*`rm -d project_tmp` remove project_tmp folder provided it is empty
368
417
*`rmdir project_tmp` can also be used
369
418
* If available, use `gvfs-trash` command to send items to trash instead of permanent deletion
419
+
* or, [unix.stackexchange: creating a simple trash command](https://unix.stackexchange.com/questions/452496/create-a-recycle-bin-feature-without-using-functions)
370
420
* Files removed using `rm` can still be recovered with time/skill. Use `shred` command to overwrite files
@@ -443,6 +493,7 @@ Note: The `perl` based `rename` is presented here and different from [util-linux
443
493
*`rename 's/\.JPG$/.jpg/' *JPG` change the file extension from '.JPG' to '.jpg'
444
494
*`rename 's/ /_/g' *` replace all 'space' characters in filenames with '_'
445
495
*[rename Q&A on unix stackexchange](https://unix.stackexchange.com/questions/tagged/rename?sort=votes&pageSize=15)
496
+
* See [Perl one liners](https://github.com/learnbyexample/Command-line-text-processing/blob/master/perl_the_swiss_knife.md) for examples and details on Perl based substitution command
0 commit comments