Search and extract
| Command | Use | Example |
|---|
awk | Complex text processing, often used for structured data | awk |
grep | Search for specific data, can use Regex | grep -i "fail" /var/log/auth.log |
cut | Trim and extract parts of a document, such as sections of columns | cut -d':' -f1 /etc/passwd |
Modify and replace
| Command | Use | Example |
|---|
sed | Modify and replace text in files | sed "s/hello/hi/g" ./my_textfile.txt |
tr | Translate or delete characters in text | tr 'A-Z' 'a-z' < input.txt > output.txt |
Sort and count
| Command | Use | Example |
|---|
wc | Counts lines, words, chars | wc -l /var/log/syslog |
sort | Arranges in logical order | sort -t: -k,3 -n -r /etc/passwd |
uniq | Filters duplicates | sort /var/log/auth.log | uniq -c |
xargs | Builds and executes further commands, used to process output from other commands in bulk | find /home/logs | xargs -I {} -n 1 -p -t cp {} /backup/logs |
View and navigate
| Command | Use | Example |
|---|
head | Displays the beginning of a file | head -n 50 /etc/apache2/httpd.conf |
tail | Show the end of a file, often to monitor in real time | tail -n 20 -f /var/log/syslog |
more | View a long file one page at a time | cat /var/log/syslog | more |
less | Like more but includes a few other options | cat /etc/passwd | less |
Output and redirect
| Command | Use | Example |
|---|
echo | Displays whatever is specified as output or to a file | echo "$(date):System update completed >> /var/log/update.log |
cat | Reads and merges files | cat log1.txt log2.txt log3.txt > full_log.txt |
tee | Takes input and writes it a file and displays output to screem | ping -c 4 google.com | tee -a network_log.txt |
| Command | Use | Example |
|---|
printf | Print formatted; allows for format specifiers | printf "var1: %s\tvar2: %s\n" "$VAR1" "$VAR2" |
bc | Basic calculator, particularly good for floating point | echo '5 / 3' | bc |
System and scripts
| Command | Use | Example |
|---|
uname | Used to retrieve system information | echo "System Info: $(uname -a)" >> /var/log/update.log |
source | Used to execute scripts in the current shell session | source /path/to/file |