Beyond cat and wc, there are several essential commands you'll use every day in Linux to manage files. Here are the most common ones categorized by what they do:
1. Moving and Renaming
mv(Move): Used to move a file to a different folder or to rename a file.mv old_name.txt new_name.txt # Renames the file mv notes.txt /tmp/ # Moves file to /tmp directorycp(Copy): Creates a duplicate of a file.cp /tmp/hello ./hello_backup # Copies 'hello' to your current folder
2. Creating and Deleting
touch: The quickest way to create a new, empty file.touch empty_file.txtrm(Remove): Deletes a file. Be careful: there is no "Trash Can" in the command line!rm file_to_delete.txt
3. Searching Inside Files
grep: Searches for a specific string of text inside a file.grep "Labby" /tmp/hello # Finds lines containing "Labby"
4. Comparing Files (Crucial for this Lab!)
Since your lab is titled "File Contents and Comparing," these two are very important:
diff: Compares two files line by line and shows you the differences.diff file1.txt file2.txtcmp: Checks if two files are exactly identical. If they are the same, it returns nothing.
5. File Information
file: Tells you what type of file it is (e.g., text, executable, or image).file /tmp/hello # Output: /tmp/hello: ASCII textstat: Provides detailed information about the file, such as when it was last modified and its size.stat /tmp/hello
Summary Table for Quick Reference:
| Command | Action |
|---|---|
ls |
List files in a directory |
touch |
Create an empty file |
cp |
Copy a file |
mv |
Move or Rename a file |
rm |
Delete a file |
grep |
Search text within a file |
diff |
Show differences between two files |
Which of these would you like to try out in your current environment? diff is a great one to practice next!