Skip to main content

Command Line Cheat Sheet

A rapid-fire reference for day-to-step Linux navigation and file manipulation.

CommandDescription
pwdPrint working directory.
ls -laList all files in long format (including hidden).
cd /pathChange directory.
treeDisplay directory structure as a tree.

File Operations

CommandDescription
cp -r dir1 dir2Copy directories recursively.
mv file1 file2Move or rename a file.
rm -rf dirForcefully remove a directory and its contents.
touch file.txtCreate an empty file or update timestamp.
mkdir -p a/b/cCreate nested directories.

Viewing Files

CommandDescription
cat fileOutput file contents to standard output.
less fileView file with pagination.
head -n 10 fileShow first 10 lines of a file.
tail -f fileOutput the last appended data as the file grows.

Text Processing

# Find lines matching pattern
grep "pattern" file.txt

# Search and replace
sed 's/old/new/g' file.txt

# Print the second column of a file
awk '[print $2]' file.txt

(Note: brackets used in awk example for markdown compatibility)