Linux File Management Commands

  1. mv: Move or rename files and directories
  2. ls: List files and subdirectories in a directory
  3. cp: Copy files or directories
  4. mkdir: Create new directories
  5. pwd: Display the current working directory path
  6. tar: Create, list, and extract archive files
  7. cd: Switch working directories
  8. chmod: Modify file or directory access permissions

Detailed Introduction to File Management Commands

Common Linux file management commands:

  1. mv (move) command:

    • Used for moving or renaming files and directories
    • Syntax: mv [source] [destination]
    • Examples:
      • mv old_file.txt new_file.txt: Renames old_file.txt to new_file.txt
        • mv file1.txt /path/to/directory/: Moves file1.txt into the specified directory
  2. ls (list) command:

    • Used for listing files and subdirectories in a directory
    • Syntax: ls [options] [path]
    • Common options:
      • -l: Display file information in long format
      • -a: Show all files, including hidden ones
      • -R: Recursively display files in subdirectories
  3. cp (copy) command:

    • Used for copying files or directories
    • Syntax: cp [source] [destination]
    • Examples:
      • cp file1.txt file2.txt: Creates a copy of file1.txt as file2.txt
        • cp -r dir1/ dir2/: Copies dir1 and all its subdirectories and files into dir2
  4. mkdir (make directory) command:

    • Used for creating new directories
    • Syntax: mkdir [options] [directory]
    • Common options:
      • -p: Create nested directories as needed
  5. pwd (print working directory) command:

    • Used to display the full path of the current working directory
    • Syntax: pwd
  6. tar (tape archive) command:

    • Used for creating, listing, and extracting tar archive files
    • Syntax: tar [options] [archive_name] [files_or_directories]
    • Common options:
      • c: Create an archive file
      • x: Extract an archive file
      • v: Verbose; display the archiving process
      • f: Specify the name of the archive file
  7. cd (change directory) command:

    • Used for switching working directories
    • Syntax: cd [directory]
    • Special directories:
      • .: Current directory
      • ..: Parent directory
      • ~: User's home directory
  8. chmod (change mode) command:

    • Used for modifying file or directory access permissions
    • Syntax: chmod [options] [mode] [file_or_directory]
    • Permission modes:
      • r: Read permission
      • w: Write permission
      • x: Execute permission
    • Example: chmod 755 file.txt sets the permissions of file.txt to rwxr-xr-x