This is a useful tip for system admins we will examine local configuration files to get an idea of user accounts, group accounts, security settings, and other basic configuration information on your systems.
We will display and search a log file using various commands. We will also create a directory structure and populate with files using the touch command.
Before we do anything we first want to switch into a user whos log we want to view. In this case we will view "user1"s logs.
Run: su - user1 (switches you to user1) whoami (shows what user you currently are)
We will read the dnf.log file located in /var/log. The dnf.log contains package information, timestamps. repository information, error messages and more. This file contains a long list of logs, to long to just read and find what you want with just your eyes. We can view the first few lines of any files with the "head" command.
Run: head /var/log/dnf.log
As you see we get a few lines of logs, mainly just debugging information. We can also review the most recent logs or logs at the end by using the "tail" command.
Run: tail /var/log/dnf.log
At the end of user1's logs we see that the debugging proccess has completed.
The grep command matches strings of characters, making it useful to search for specific items in a long list. We will be viewing user2's logs for this example.
Run: cat /var/log/dnf.log | grep "timer"
As you see any log that contains the string "timer" will populate our terminal. You can also add the " -i " switch for grep to remove case sensitivity.
Run: cat /var/log/dnf.log | grep -i "fail"
As you can see even any string with "fail" are populated. It is a good habbit to add the " -i " switch when grepping because you may miss something you didn't know existed.
We will go over copying files, we will be using user1's account. We will copy the /opt/files to our home directory.
Run: cp -R /opt/files ~ (the -R switch copies everything in the folder files, subfolders, etc. The ~ is the home directory)
We then moved into the files location and viewed it contents. It is good practice to type ls after every movement, or manipulation of files to make sure it is doing what you told it to do.
You can create new directories and able to copy files into them using a terminal. To make a directory use the "mkdir" command.
Run: mkdir documents
Now we will copy the contents that are in the "file" directory into the "documents" directory.
Run: cp * ../documents/ (copies everything in the directory you are currently in and place them into the documents folder)
You can also create blank files by using the "touch" command.
Run: touch File1.txt
When deleting a directory we use rmdir but, this will not work if the directory has files inside.
Run: rm -rf files
The -r switch deletes everything the -f switch deletes without a confirmation BECAREFUL using this switch.
Fin.