Loading

Show System Info

systeminfo

$ uname -mrs
$ lsb_release -a
$ dmesg | egrep -i 'err|warn|critical'
$ sudo tail -f /var/log/myapp

Linux System Hardware Information
--
sudo lshw -short
sudo lshw -html > lshw.html
# Hardware Info
dmidecode  -q | less
lshw
lshw -C disk
lscpu
lsusb -v
lspci
lspci -t
lspci -v

SCSI HW Info

lsblk
lsssci -s


Print Information about SATA Devices

sudo hdparm /dev/sda1
sudo hdparm -g /dev/sda1	


Extract Information about Hardware Components
sudo dmidecode -t memory
sudo dmidecode -t bios
sudo dmidecode -t processor
sudo dmidecode -t system

Make sure you are logged in as a user with root privileges

Vim editor	

0	move to beginning of the current line
$	move to end of line
n      search next  below
G - last line of file

Use scp to copy the file


To copy a directory from a local to remote system, use the -r option:

- scp -r /local/directory remote_username@10.10.0.2:/remote/directory
- scp -r  /home/thomasa/Documents/NSX  thomas@192.168.1.108:/data/NSX


Note taking - Connels
- scp -r /data/xwikiconfig_backups/ thomasa@192.168.1.12:/data/xwikiconfig_backups


cp

Copying files from one directory to other with all perm intact 

-a and -R is actually same ( recursive - ie: goes into directory)
-v shows versbose 

cp -aRv ash/ perm2

Use the df and du commands to show filesystem and disk usage

# Print Disk Usage Output In Human Readable Format with Grand Total
  du -ahc /Users/lnxadm
 
 # Print Disk Usage Output In Human Readable Format showing consumption
  du -h --max-depth=1 /var/log | sort -n -r 
  
 # Print Disk Usage with just Grand Total
 du -sh /Users/lnxadm
 
# Display Disk Usage Output In GB
  du -gsh /Users/lnxadm
  
# Check file system disk space usage with filesystem
  df -H .
  df -h --total

# Check Inode usage
  df -i

  

Use the tar command to create an archive file using tar bundle

#To create a .tar archive file.
# tar -cvf <FileName.tar> <Files/Folders To Be Compressed>

#To create a .tar.gz archive file.
tar -zcvf <FileName.tar.gz> <Files/Folders To Be Compressed>

#To Decompress a .tar archive file.
# tar -xvf <FileName.tar>

To Decompress a .tar.gz archive file.
# tar -xzvf <FileName.tar.gz>

View the list of files in the ZIP archive without extracting it.
# zipinfo <FileName.zip>
# less <FileName.zip>


Use the zip command to create an archive file using zip bundle

#create a zip file
zip filename.zip <filenames.txt>

#Unzip a file
unzip filename.zip

#link folder recursively into filename.zip
zip -r filename.zip somefiles

Use the Gzip command to create an archive file using zip bundle

By default gzip removes the original file but if we wish to keep it we should use the '-c' option
# gzip -c myfile > filename.gz

# Compress multiple files into a single gzip
 gzip -c demo1.txt demo2.txt > filename.gz
 
# List the compressed file contents
gzip -l filename.gz

# View the actual contents of a gzip compressed file
zcat filename.gz

# Compress all files in a directory
gzip -r mydirectory

Decompress files with gzip
gzip -d  filename.gz
gunzip filename.gz

Create a dummy file of size 1GB

dd if=/dev/zero of=afile.txt  bs=1G  count=1

Configure OpenVM tools on the VM

  1. Ensure that your Linux virtual machine is powered on.
  2. ssh to VM and run sudo yum install open-vm-tools

Install Netools to get ifconfig

yum install net-tools -y 

Configure hostname

# To set a hostname, run
hostnamectl set-hostname <hostname>
# Check enteries in these files
vi /etc/sysconfig/network
$ vi /etc/hosts

A system reboot is required following a system name change, use one of the below commands to reboot a CentOS VM.

# systemctl reboot or shutdown -r

Configure Static IP on CentOS/RHEL using NMCLI

Nmcli is the command-line-based application to manage the NetworkManager.

With nmcli you can control the NetworkManager and manage network card status on the server.

Before we configure the static IP address, we check all available interfaces on the CentOS 8 server using the nmcli command below.
[root@server1 ~]# nmcli connection show

To set the IP address and the gateway on the interface card using nmcli

[root@server1 ~]# nmcli con mod ens32 ipv4.address 192.168.1.10/24
[root@server1 ~]# nmcli con mod ens32 ipv4.gateway 192.168.1.

Update the DNS server as well if you are using it

[root@server1 ~]# nmcli con mod ens32 ipv4.dns 192.168.1.1

Create A File of a Specific Size 


MacBook-Air:demo root# dd if=/dev/zero of=afile.txt  bs=1G  count=1
1+0 records in
1+0 records out
1073741824 bytes transferred in 3.194800 secs (336090467 bytes/sec)
MacBook-Air:demo root# 
MacBook-Air:demo root# ls -alh
total 2097152
drwxr-xr-x   3 root  wheel    96B 27 Oct 10:29 .
drwxr-x---  13 root  wheel   416B 27 Oct 10:28 ..
-rw-r--r--   1 root  wheel   1.0G 27 Oct 10:29 afile.txt
MacBook-Air:demo root# 

Find recently modified files

The following are the time stamps available in Linux distros.

  • atime: Last access time
  • mtime: Last modification time
  • ctime:  Last change time

For an example,

-mtime +5:  Finds files that were modified 5 days ago.
-mtime -10: Finds all files that were modified in the last 10 days.
-mtime 10:  Find all files that were modified exactly 10 days ago.

# Finding the Top 5 Big Files
# find . -type f -exec ls -s {} \; | sort -n -r | head -5

The following command removes *.zip files that are over 100M.
# find / -type f -name *.zip -size +100M -exec rm -i {} \;"

Finds all the files (under root file system /) that got updated within the last day
 # find / -maxdepth 1 -newermt "2016-12-06"


# find . -type f -exec ls -s {} \; | sort -n -r | head -5

# find Files in a folder that were @Changed in last 15 days
  find . -type f -mtime -15 -ls

# find Files in a folder that were @Modified in last 15 days
  find . -type f -mtime 10 -ls

# find files that were modified within last 30 Mins
  find . -type d -mmin -30 -ls

# find only the folders modified in last 5 Days
  find . -type d -mtime -5 -ls

# List both Files and Folders that were modified in last 15 Days
  find . -mtime -15 -ls

# Find files that have been modified over a period of time
  find . -cmin -20 -ls

# Find list of files created today
  find . -type f -ctime -1 -ls

# find all files and folders modified in the Last 24 Hours
  find . -newermt "-24 hours" -ls  
 
# find modified files and folders starting from a given Date to the latest Date
   find . -newermt "2023-10-07" -ls
   

Find recently modified files and delete them

# Search files older than 20 days
find . -type f -mtime +20 -print

# Delete files older than 20 days

find. -type f -mtime +20 -exec rm -f {} \;
or
find . -type f -mtime +20 | xargs rm -f

# List files older than 10 days with tar.gz extension
find . -type f -name "*.tar.gz" -mtime +10 -print

# Delete it using one of the following commands.
find . -type f -name "*.tar.gz" -mtime +10 -exec rm -f {} \;
or
find . -type f -name ".tar.gz" -mtime +10 | xargs rm -f

# Command Syntax for removal
Just show files
find /var/log -type f -name '*.jpg' -mtime +30 -exec ls {} \;

# Remove files
find /var/log -type f -name '*.jpg' -mtime +30 -exec rm {} \;
Explanation
- First part is the path where your files are located.
- Second part -type is the file type f stands for files
- Thirdpart-name is for using the actual filenames
- Fourth part -mtime gets how many days the files older then will be listed. +30 is
for files older then 30 days.
- Fifth part -exec executes a command. In this case rm is the command, {} gets the
filelist and \; closes the command

Copy directories recursively

# To copy a directory recursively to another location
cp -r /var/logs/ /home/vmadmin

# To copy a file with its permissions
cp -p /var/logs/demofile /home/vmadmin

# To prevent overwrite of a file if it exists in target
cp -n /var/logs/demofile /home/vmadmin

# Copying specific format of files
cp /var/logs/*.gz /home/vmadmin

# Copy hidden files 
cp -R /var/logs.* /home/vmadmin

Monitor log files in realtime

watch tail -n 10 /var/log/vmware-network.1.log 

tail -f /var/log/vmware-network.1.log 

# Provides output from all areas 
journalctl -f

Checking Logs in Linux

# 24 hour (Warnings, Errors and Critical) log summary
 grep -i "`date --date='yesterday' '+%b %e'`" /var/log/wifi.log | egrep -wi 'warning|error|critical' 

filter just enabled config in a file

grep -v '^#' /etc/httpd/conf/httpd.conf | less
(Visited 87 times, 1 visits today)

By Ash Thomas

Ash Thomas is a seasoned IT professional with extensive experience as a technical expert, complemented by a keen interest in blockchain technology.

Leave a Reply