Navigating and Managing Files

Harry · 14 Sep 2026 · 1 views
Advertisement
Advertisement

Where am I, and what is here

pwd            # print working directory
ls             # list files
ls -l          # long format: permissions, size, date
ls -la         # also show hidden files (those starting with .)
cd /var/log    # change directory
cd ~           # go home
cd ..          # go up one level

Looking at files

cat file.txt        # print a whole file
less file.txt       # scroll through a large file (q to quit)
head -n 20 file     # first 20 lines
tail -n 20 file     # last 20 lines
tail -f app.log     # follow a log live as it grows

tail -f is invaluable for watching a server log in real time.

Creating and removing

mkdir project           # make a directory
mkdir -p a/b/c          # make nested directories
touch notes.txt         # create an empty file
rm notes.txt            # remove a file
rm -r olddir            # remove a directory and its contents
rmdir emptydir          # remove an empty directory

Care: there is no recycle bin. rm -r is permanent, and rm -rf / is catastrophic – always double-check the path.

Copying and moving

cp file.txt backup.txt       # copy a file
cp -r src/ dest/             # copy a directory
mv file.txt archive/         # move (or rename) a file
mv old.txt new.txt           # rename

Finding things

find . -name "*.log"         # find files by name
grep "ERROR" app.log         # find lines containing text
grep -r "TODO" src/          # search recursively

Key points

  • pwd, ls and cd orient and move you around the tree.
  • View files with cat, less, head, tail (-f to follow logs).
  • Create/remove with mkdir, touch, rm – deletion is permanent.
  • find locates files; grep searches inside them.
Share this post:

Comments (0)

Please login or register to comment.