Home › Other › Command Line

Command Line

The command line feels intimidating until a dozen commands click into place. These are the ones you will use every day.

The shell is a text interface to your computer. It is faster than clicking for a huge range of tasks, and it is often the only interface on a server. This covers the everyday toolkit.

Getting around

pwd            # where am I
ls -la         # list files, including hidden, with detail
cd projects    # change directory
cd ..          # up one level
cd ~           # home

Working with files

cat file.txt          # print a file
less file.txt         # scroll through it (q to quit)
cp a.txt b.txt        # copy
mv a.txt docs/        # move or rename
rm old.txt            # delete
mkdir new-folder      # make a directory

Finding things

grep "error" log.txt           # lines containing "error"
grep -ri "todo" .              # recursive, case-insensitive
find . -name "*.js"            # files by name
find . -type f -mtime -1       # changed in the last day

Pipes: the superpower

Each command does one thing; the pipe | feeds one command’s output into the next. That composition is the whole philosophy of the shell:

# the 5 biggest files here
du -ah . | sort -rh | head -5

# how many lines mention "warning"
grep "warning" log.txt | wc -l

Redirection

command > out.txt     # write output to a file (overwrite)
command >> out.txt    # append
command 2> err.txt    # redirect errors
command < in.txt      # feed a file as input
Shortcuts that save time: Tab completes names, the up arrow recalls commands, Ctrl+C stops a running command, and Ctrl+R searches your history.

Keep reading