Linux File Management – Copy, Move, Delete and View Files (cp, mv, rm, cat, less, grep, wc)

Introduction

In VLSI verification and RTL design, file management is a daily task — moving testbenches, creating backups, cleaning log files, or searching through massive simulation outputs.
This tutorial covers essential Linux commands to copy, move, delete, and search files efficiently.


1. Copying Files and Directories – cp

To make a copy of a file:

cp file1 file2

Example:

cp science.txt backup.txt

This creates a new file named backup.txt with the same content as science.txt.

To copy directories recursively (including subfolders):

cp -R dir1 dir2
💡 Example:
cp -R rtl backup_rtl — copies your RTL folder with all files.

2. Moving and Renaming Files – mv

Move or rename files:

mv file1 file2

If file2 doesn’t exist → it renames the file.
If file2 is a directory → it moves the file inside that directory.

Examples:

mv science.txt ~/unixstuff/backups/
mv report.log old_report.log

3. Removing Files and Directories – rm, rmdir

To delete a file:

rm filename

To remove an empty directory:

rmdir dirname

To delete a directory and all its contents (use with care):

rm -r dirname

⚠️ Caution: There is no recycle bin in Linux. Once deleted, it’s gone.


4. Displaying File Contents

cat

Display the entire file:

cat science.txt

less

View a file page-by-page (recommended for long logs):

less science.txt

Use:

  • Space → next page
  • q → quit

head

View the first 10 lines (default):

head science.txt

To see 5 lines:

head -5 science.txt

tail

View the last 10 lines:

tail science.txt

To view last 15 lines:

tail -15 science.txt

💡 EDA Tip: Use tail -f sim.log to monitor a simulation log live while running.


5. Searching Inside Files – grep

Search for a keyword:

grep science science.txt

Ignore case:

grep -i science science.txt

Count matching lines:

grep -c science science.txt

Show non-matching lines:

grep -v science science.txt

Highlight matches:

grep --color -i "error" sim.log

💡 Real-World Example: Quickly locate simulation errors:

grep --color -i "uvm_error" sim.log

6. Counting Words, Lines, and Characters – wc

Example:

wc -l sim.log

This tells you how long your log file is — handy when checking if the simulation completed fully.


Summary Table


Practice Tasks

  1. Copy a file named pcie_tlp.sv into a backup directory using cp.
  2. Rename it as pcie_tlp_v2.sv using mv.
  3. Delete any temporary directory with rm -r tempdir.
  4. Search for “UVM_ERROR” in your simulation log with grep –color.
  5. Count the total number of transactions logged using wc -l txn_log.txt.

Real-World Scenario

When debugging simulations:

  • Use grep -i error *.log to find failing runs.
  • Use tail -f vcs.log to track progress live.
  • Use cp and mv to organize multiple test iterations neatly.

These simple commands can save hours during regression analysis.


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top