What are the common file system commands?

QuestionsQuestions8 SkillsProDec, 11 2025
075

That's an excellent question! In Linux, mastering file system commands is fundamental. Based on what you're learning in this step, here are some of the most common file system commands for managing files and directories:

  1. ls (List Directory Contents):

    • Purpose: Lists the files and subdirectories within a directory.
    • Common Options:
      • -l: (long format) Shows detailed information like permissions, owner, size, and modification date.
      • -a: (all) Shows all files, including hidden ones (those starting with a .).
      • -h: (human-readable) Displays file sizes in an easy-to-read format (e.g., K, M, G).
      • Example: ls -lah (lists all files in long, human-readable format).
  2. cd (Change Directory):

    • Purpose: Navigates between directories.
    • Example: cd /home/labex/project (moves to the /home/labex/project directory).
    • Example: cd .. (moves up one directory).
    • Example: cd ~ or just cd (moves to your home directory).
  3. pwd (Print Working Directory):

    • Purpose: Shows the full path of your current directory.
    • Example: pwd (might output /home/labex/project).
  4. mkdir (Make Directory):

    • Purpose: Creates new directories.
    • Example: mkdir my_new_folder (creates my_new_folder in the current directory).
    • Example: mkdir -p parent/child (creates parent, then child inside parent).
  5. rmdir (Remove Directory):

    • Purpose: Deletes empty directories.
    • Example: rmdir empty_folder (removes empty_folder).
    • Note: It can only remove empty directories. For non-empty directories, you'd typically use rm -r.
  6. touch (Change File Timestamps / Create Empty Files):

    • Purpose: Primarily used to update the access/modification timestamps of a file. If the file doesn't exist, it creates an empty file.
    • Example: touch newfile.txt (creates newfile.txt if it doesn't exist, or updates its timestamp).
  7. cp (Copy Files and Directories):

    • Purpose: Copies files or directories from one location to another.
    • Example: cp file1.txt file_copy.txt (copies file1.txt to file_copy.txt).
    • Example: cp -r testdir backup_testdir (copies the testdir directory and its contents recursively to backup_testdir).
  8. mv (Move/Rename Files and Directories):

    • Purpose: Moves files or directories from one location to another, or renames them.
    • Example: mv oldname.txt newname.txt (renames oldname.txt to newname.txt).
    • Example: mv file1.txt testdir/ (moves file1.txt into the testdir directory).
  9. rm (Remove Files and Directories):

    • Purpose: Deletes files or directories. This command should be used with caution!
    • Common Options:
      • -i: (interactive) Prompts before every removal.
      • -r: (recursive) Deletes directories and their contents.
      • -f: (force) Removes without prompting (use extremely carefully!).
    • Example: rm unwanted.txt (deletes unwanted.txt).
    • Example: rm -r old_folder (deletes old_folder and everything inside it).
  10. cat (Concatenate and Display Files):

    • Purpose: Displays the content of files on the standard output. It can also be used to combine files.
    • Example: cat file2.txt (displays the content of file2.txt).

These commands form the backbone of interacting with the file system in Linux. You're already getting hands-on with cd, touch, echo (used for creating files), mkdir, and ls in this very step!

Do any of these commands particularly spark your interest, or would you like to explore another aspect of Linux commands?

0 Comments

no data
Be the first to share your comment!