What are other file manipulation commands?

QuestionsQuestions8 SkillsProDec, 16 2025
0109

That's a great question! Beyond touch, echo > file, mkdir, and ls, there are many other fundamental commands for manipulating files and directories in Linux.

Here are some common ones you'll use frequently:

  1. cp (copy): Used to copy files or directories from one location to another.

    cp myfile.txt mycopy.txt   # Copies myfile.txt to mycopy.txt
    cp myfile.txt /tmp/       # Copies myfile.txt to the /tmp directory
    cp -r mydir /tmp/         # Copies the directory mydir and its contents recursively to /tmp
  2. mv (move / rename): Used to move files or directories, or to rename them.

    mv oldname.txt newname.txt # Renames oldname.txt to newname.txt
    mv myfile.txt /tmp/       # Moves myfile.txt to the /tmp directory
  3. rm (remove / delete): Used to delete files or directories. Be careful with this command, as deleted files are often not recoverable!

    rm myfile.txt             # Deletes myfile.txt
    rm -r mydir               # Deletes the directory mydir and its contents recursively
    • Tip: You can use rm -i for an interactive prompt before deleting, or rm -f to force deletion without confirmation (use with extreme caution!).
  4. cat (concatenate and display): Primarily used to display the content of files, or to combine multiple files into one.

    cat file1.txt             # Displays the content of file1.txt
    cat file1.txt file2.txt > combined.txt # Concatenates file1.txt and file2.txt into combined.txt
  5. head: Displays the beginning (first 10 lines by default) of a file.

    head myfile.txt           # Shows the first 10 lines of myfile.txt
    head -n 5 myfile.txt      # Shows the first 5 lines of myfile.txt
  6. tail: Displays the end (last 10 lines by default) of a file.

    tail myfile.txt           # Shows the last 10 lines of myfile.txt
    tail -n 5 myfile.txt      # Shows the last 5 lines of myfile.txt
    tail -f myfile.txt        # Follows the file as it grows (useful for log files)
  7. find: Used to search for files and directories in a directory hierarchy based on various criteria (name, type, size, modification time, etc.).

    find . -name "*.txt"      # Finds all files ending with .txt in the current directory and its subdirectories
    find /home/labex -type d  # Finds all directories under /home/labex

These commands form the core of file management in Linux. As you continue with the labs, you'll get plenty of opportunities to use them!

Do any of these particular commands pique your interest, or would you like to know more about a specific one?

0 Comments

no data
Be the first to share your comment!