Register to get access to free programming courses with interactive exercises

Manipulating directories and files Basics of Bash

Video may be blocked due to browser extensions. In the article you will find a solution to this problem.

Important note

Wildcards are building blocks for patterns that match files or directories. When you use ls or any other command that works with files and directories, you provide a path (recall relative and absolute paths from the previous lesson). When you refer to a path, you can also use wildcards that will possibly match multiple files or directories at once.

Basic wildcards are:

  • - - represents zero or more characters
  • ? - represents a single character
  • [] - represents a range of characters

Example:

ls docs/photos
saturday.jpg    sunday.jpg    dog.jpg    machine.jpg    scan.tiff    scan2.tiff

ls docs/s*
saturday.jpg    sunday.jpg

ls docs/*.jpg
saturday.jpg    sunday.jpg    dog.jpg    machine.jpg

Also, remember the shortcut for "home directory" — it's ~. You can use it in paths. For example, if your home directory is /home/michael, then ~/docs is the same as /home/michael/docs.

Lesson notes

  • mkdir to create directory
  • mkdir -p to create multiple levels of directories (e.g. mkdir -p dir1/dir2/dir3)
  • touch to change the date of a file or create a new file (e.g. touch newfile.txt)
  • mv to move or rename a file or a directory (e.g. mv old_name new_name)
  • rm to delete a file (e.g. rm readme.txt)
  • rm -r to delete a directory and all the directories inside it (e.g. rm -r photos)

Hexlet Experts

Are there any more questions? Ask them in the Discussion section.

The Hexlet support team or other students will answer you.

About Hexlet learning process

Sign up

Programming courses for beginners and experienced developers. Start training for free

  • 130 courses, 2000+ hours of theory
  • 1000 practical tasks in a browser
  • 360 000 students
By sending this form, you agree to our Personal Policy and Service Conditions

Our graduates work in companies:

<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.bookmate">Bookmate</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.healthsamurai">Healthsamurai</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.dualboot">Dualboot</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.abbyy">Abbyy</span>

Use Hexlet to the fullest extent!

  • Ask questions about the lesson
  • Test your knowledge in quizzes
  • Practice in your browser
  • Track your progress

Sign up or sign in

By sending this form, you agree to our Personal Policy and Service Conditions

Toto Image

Ask questions if you want to discuss a theory or an exercise. Hexlet Support Team and experienced community members can help find answers and solve a problem.