File and directory management (creation, deletion, renaming) – Linux Installation and Basic Commands – Linux operating system

File and directory management is an essential aspect of working with Linux. Here are some common commands for creating, deleting, and renaming files and directories:

  1. Creating Files and Directories:
    • To create a new directory: mkdir directory_name
    • To create a new file: touch file_name
  2. Deleting Files and Directories:
    • To delete a file: rm file_name
    • To delete an empty directory: rmdir directory_name
    • To delete a directory and its contents: rm -r directory_name
  3. Renaming Files and Directories:
    • To rename a file: mv old_file_name new_file_name
    • To rename a directory: mv old_directory_name new_directory_name
  4. Moving Files and Directories:
    • To move a file to a different location: mv file_name /path/to/destination
    • To move a directory to a different location: mv directory_name /path/to/destination
  5. Copying Files and Directories:
    • To copy a file to a different location: cp file_name /path/to/destination
    • To copy a directory to a different location: cp -r directory_name /path/to/destination
  6. Listing Files and Directories:
    • To list files and directories in the current directory: ls
    • To list files and directories in a specific directory: ls /path/to/directory
  7. Viewing File Contents:
    • To display the contents of a file: cat file_name
    • To display the contents of a file with pagination: less file_name
  8. Modifying File Permissions:
    • To change file permissions: chmod permissions file_name
      • Example: chmod +x script.sh (to make a script executable)
  9. Checking File and Directory Information:
    • To display detailed information about a file or directory: ls -l file_name
    • To display file and directory permissions: ls -l file_name
    • To display file size: ls -l file_name

These commands provide the basic functionality for managing files and directories in Linux. Remember to exercise caution when deleting or renaming files and directories, as these actions are not reversible and can result in data loss if done incorrectly.

SHARE
By John

Leave a Reply

Your email address will not be published. Required fields are marked *

No widgets found. Go to Widget page and add the widget in Offcanvas Sidebar Widget Area.