Most useful Linux commands for daily
# Display how long has the system been running – since tle last restart.
# List directory contents
# List files in directory but better attributes and human-readable
# List files in directory sorted by file date/time.
# Change directory
cd /var/log/ #will change current directory to /var/log/
cd ~ # the ~ character indicates the current logged in user's home directory.
When filtering for files or directories you can use * to match multiple files.
ls -lht /var/log/*log
This will list all files that have any name in the /var/log/ directory and their file names end with .log
#Show file contents, can concatenate multiple files contents.
# Sudo allows you to use super user commands under your username.
To be able to issue sudo commands a user must me a member of the wheel group – rhel related distributions.
sudo ls /var/log/
# See any changes made to a log file, display anything that is being appended.
tail -f /var/log/somefile
tail -30f /var/log/somefile
# Another way to monitor file changes is Less where you can press Ctrl+D to scroll up if you want to see more of previous changes. You quit less by pressing q on your keyboard.
# What is the name of the machine.
# For fqdn or long name
# Help with a specific command
Any command can accept the –help parameter option to display help with that command’s options that are available.
# Find matches of a string in another string or file.
Here we cound for each file how many times the search text is found.
grep -1c "Power Button: Found keys" -f /var/log/*
# Using the pipe character | to combine commands in CLI (command line interface).
Here grep will help us filter the file contents and see only what we need. The command output from cat is sent to grep that displays the data.
sudo cat /var/log/secure | grep "COMMAND=/usr/bin/tail"