Surfalytics
CLI course overview

Just Enough CLI · Step 4 Free

Working with files: cat, cp, mv, rm, mkdir

The daily file toolkit. Each command is tiny; together they replace the file manager.

Creating

touch report.csv       # create an empty file (or update its timestamp)
mkdir data             # create a directory
echo "hello" > note.txt  # create a file with content

echo prints its arguments to standard output; the > sends that output into a file instead of the screen.

Viewing

cat file.txt           # print the whole file
less big_file.log      # scroll through a big file (q to quit)
head data.csv          # first 10 lines
tail data.csv          # last 10 lines
tail -f app.log        # follow a log file live — a data engineer classic

Use cat for small files, less for big ones, and head to peek at a CSV before loading it.

Copying and moving

cp file1 file2         # copy
cp file dir/           # copy into a directory
mv file1 file2         # rename
mv file dir/           # move into a directory

Deleting

rm file                # delete a file
rmdir dir              # delete an EMPTY directory
rm -r dir              # delete a directory and everything inside

rm is forever

There is no trash bin in the terminal. rm -r deletes a whole directory tree immediately. Read the path twice before pressing Enter — especially as root.

Inspecting

file mystery_download        # guess what format a file is
diff config_old config_new   # show line differences between two files
sort names.txt               # print lines in alphanumeric order

diff is how you compare two versions of a config before deploying the change.

Practice in your terminal:

  1. Make a practice area: mkdir cli-practice && cd cli-practice
  2. Create a file: echo "first line" > test.txt, then view it with cat test.txt.
  3. Copy it (cp test.txt copy.txt), rename the copy (mv copy.txt backup.txt).
  4. Compare them: diff test.txt backup.txt (no output = identical).
  5. Clean up: cd .. && rm -r cli-practice