Skip to content

Latest commit

 

History

History
112 lines (91 loc) · 4.24 KB

command-line-file-management-tools.md

File metadata and controls

112 lines (91 loc) · 4.24 KB

Here are some commonly used command-line file management tools for various tasks in Unix/Linux environments. These tools help you efficiently handle files and directories:

1. ls (List Directory Contents)

  • Purpose: Display files and directories.
  • Example:
    • ls -l: List files with details (permissions, size, date).
    • ls -a: Show hidden files.

2. cp (Copy Files or Directories)

  • Purpose: Copy files and directories.
  • Example:
    • cp file1.txt file2.txt: Copy file1.txt to file2.txt.
    • cp -r dir1 dir2: Copy directory dir1 to dir2.

3. mv (Move or Rename Files)

  • Purpose: Move or rename files and directories.
  • Example:
    • mv file.txt /path/to/directory/: Move a file.
    • mv oldname.txt newname.txt: Rename a file.

4. rm (Remove Files or Directories)

  • Purpose: Delete files or directories.
  • Example:
    • rm file.txt: Remove a file.
    • rm -r directory/: Remove a directory and its contents.

5. mkdir (Make Directory)

  • Purpose: Create directories.
  • Example:
    • mkdir newdir: Create a new directory.
    • mkdir -p /path/to/newdir: Create nested directories if they don’t exist.

6. rmdir (Remove Empty Directory)

  • Purpose: Delete empty directories.
  • Example:
    • rmdir directory/: Remove an empty directory.

7. find (Search for Files)

  • Purpose: Search for files and directories.
  • Example:
    • find /path -name "*.txt": Find all .txt files under /path.
    • find /path -size +1G: Find files larger than 1GB.

8. tar (Archive and Extract Files)

  • Purpose: Create and extract archives.
  • Example:
    • tar -czvf archive.tar.gz /path: Create a compressed archive.
    • tar -xzvf archive.tar.gz: Extract the archive.

9. zip/unzip (Compress and Extract Files)

  • Purpose: Compress and extract files using ZIP format.
  • Example:
    • zip archive.zip file1.txt file2.txt: Create a ZIP archive.
    • unzip archive.zip: Extract the archive.

10. rsync (Remote Sync)

  • Purpose: Sync files between directories or machines.
  • Example:
    • rsync -av /source/ /destination/: Synchronize files from source to destination.

11. du (Disk Usage)

  • Purpose: Estimate file and directory space usage.
  • Example:
    • du -sh directory/: Show human-readable size of a directory.

12. df (Disk Free)

  • Purpose: Display available disk space.
  • Example:
    • df -h: Show human-readable disk space usage.

13. chmod (Change File Permissions)

  • Purpose: Modify file permissions.
  • Example:
    • chmod 755 file.txt: Set permissions (read, write, execute).

14. chown (Change Ownership)

  • Purpose: Change file owner and group.
  • Example:
    • chown user:group file.txt: Change the owner and group of a file.

15. ln (Link Files)

  • Purpose: Create symbolic or hard links to files.
  • Example:
    • ln -s /path/to/file linkname: Create a symbolic link.

16. head and tail (View File Contents)

  • Purpose: Display the first or last lines of a file.
  • Example:
    • head -n 10 file.txt: Show the first 10 lines.
    • tail -f log.txt: Follow the latest lines added to a file.

17. cat (Concatenate and Display File)

  • Purpose: View or combine file contents.
  • Example:
    • cat file.txt: Display the content of a file.

18. grep (Search Text in Files)

  • Purpose: Search for patterns within files.
  • Example:
    • grep "search_term" file.txt: Find lines containing the search term.

19. stat (File Status)

  • Purpose: Display detailed file information.
  • Example:
    • stat file.txt: Show details like size, permissions, and timestamps.

20. touch (Create Empty File or Update Timestamp)

  • Purpose: Create an empty file or update timestamps.
  • Example:
    • touch newfile.txt: Create a new empty file or update the timestamp of an existing file.

Do you need help with any specific commands or a more detailed explanation?