Log inSign up

Linux command line guides

The commands you use every day: files, text, search, editors and manual pages. 16 guides in this topic.

Copy files and directories with cp

Copy single files, whole directory trees and config files with cp, keep owners and timestamps, and avoid silent overwrites on a live server.

Move and rename with mv

Rename files and folders, move them between directories, rename in bulk with a loop or the rename tool, and avoid overwriting data on the way.

Create directories and empty files

Build folder trees in one line with mkdir -p, set modes and owners as you create them, and make or re-date empty files with touch.

List files with ls, find your place with pwd

Read long listings, show hidden files, sort by size or date, list a directory itself, and always know which folder you are standing in.

Read files with cat, less and tail

Print short files with cat, page through long ones with less, watch logs live with tail -f, and read rotated, compressed logs without unpacking them.

Find files with find and locate

Search the live filesystem with find by name, size, age, owner or permission, act on the results, and get instant name lookups from a locate index.

Search text with grep

Find lines in files and logs with grep: case-insensitive and whole-word matches, recursive code searches, regular expressions and context lines.

Edit and report text with sed and awk

Change config values in place with sed, print line ranges, and use awk to pick columns, filter rows and total numbers from logs and command output.

echo, tee and wc

Print text with echo and printf, split output to a file and the screen with tee, and count lines, words and bytes with wc.

Edit files with nano

Open, edit, search and save configuration files over SSH with nano, plus the settings that make it pleasant on a server.

Edit files with Vim

Learn the Vim modes, saving and quitting, motions, search and replace, and a small vimrc for editing config files on a server.

Read manual pages

Find and read the built-in manual on your server: man sections, searching with apropos, help flags, info pages and restoring docs on minimal images.

Users and groups

Create, change, lock and remove Linux users and groups, give sudo rights, and add service accounts that cannot log in.

Ownership with chown and chgrp

Change file owners and groups with chown and chgrp, recursively and safely, and set up shared folders and web roots that keep the right owner.

Symbolic and hard links

Create, inspect, replace and clean up symbolic and hard links with ln, and use them for release switching and config layouts.

Pipes, redirection and xargs

Chain commands with pipes, send output and errors to files, feed lists into xargs safely, and run work in parallel.