Comprehensive Guide to File Management in Linux

Commands used for File Management

  • pwd - Present working directory

  • ls - To list the files and folders from the current directory

  • ls -a - To list all the files and folders from the current directory including hidden files and folders

  • cd - Change Directory

  • cd / - Take the control to root directory

  • cd ~ - Take the control to home directory

  • cd .. - Move back to previous directory

  • mkdir <dir name> - To Create Directory

  • mkdir .<dir name> - To Create hidden Directory

Create Files in Directory :

  • echo “<message>” - echo Command is to used print any message to the terminal.

  • touch <file_name> - Create Empty file

  • touch .file_name - Create Hidden File

  • echo “<message>” >> file_name - Create a file with content

  • cat file_name - Read the contents of the a file

  • echo “<message>” > file_name - Replace the file content

  • vi file_name - Create/Open a file using vi editor

    • Eg. vi test1

    • press i # Goto Insert Mode

    • //Type the File Contents

    • press esc :wq # Save and Exit from that file

    • press esc :q! # Exit without saving the file

  • cp file_name <Target_Dir_Name> - Copy file to another directory

  • mv file_name <Target_Dir_Name> - Move file to another directory

  • mv existing_file_name <new_file_name> - Rename the File

  • rm <file_name> - Remove a file

  • rm -rf <dir name> - Remove a directory

  • ll - Long Listing