test - check file types and compare values
To print “Yes, that’s true.” when 100 is greater than 99.
$ test 100 -gt 99 && echo "Yes, that's true." || echo "No, that's false."
To print "No, that's false." when 99 is greater than 100.
$ test 99 -gt 100 && echo "Yes, that's true." || echo "No, that's false."
To check if a file exists and is a regular file
$ test -f /etc/resolv.conf && echo "File /etc/resolv.conf found." || echo
"File /etc/resolv.conf not found."
$ test -f /etc/ssh/sshd_config && echo "File /etc/ssh found." || echo "File
/etc/ssh not found."
To print 0 when the expression is true and two strings are identical.
$ [ "awesome" = "awesome" ]; echo $?
To print 1 when the expression is false and two strings are not identical.
$ [ "awesome" = "1awesome" ]; echo $?
To print "1" because the expression is false
$ [ 7 -eq 10 ]; echo $?
To print "0" because the expression is true
$ [ 10 -eq 10 ]; echo $?
regards,
T.Dhanasekar
telnet - is used for interactive communication with another host using the
TELNET protocol
$ telnet -l [username] [remote machine IP] [port (optional)]
To connect to the device with specific IP address
$ telnet 192.168.122.105
To quit the connected machine
$ logout
To connect remote server with user and port number
$ telnet -l remote_user 192.168.122.105 3000
To connect to the telnet shell
$ telnet
telnet>
To print help options
$ telnet
telnet > h
To exit the telnet shell
telnet > quit
regards,
T.Dhanasekar
tcpdump - prints out a description of the contents of packets on a network
interface
To capture packets from Specific Interface
$ sudo tcpdump -i eth1
To capture only N number of packets
$ sudo tcpdump -c 4 -i eth1
To display the package in ASCII format
$ sudo tcpdump -A -i eth1
To Display Available Interfaces
$ sudo tcpdump -D
To Display Captured Packets in HEX and ASCII
$ sudo tcpdump -XX -i eth1
To capture and save packets in a file
$ sudo tcpdump -w 0002.pcap -i eth1
To read captured packets file
$ sudo tcpdump -r 0002.pcap
To capture IP address packets
$ sudo tcpdump -n -i eth1
To capture only TCP packets.
$ sudo tcpdump -i eth1 tcp
To capture packet from specific port
$ sudo tcpdump -i eth1 port 22
To capture packets from source IP
$ sudo tcpdump -i eth1 src 192.168.122.50
To capture packets from destination IP
$ sudo tcpdump -i eth1 dst 192.168.122.100
regards,
T.Dhanasekar
tar - an archiving utility
syntax
$ tar <options> <files>
To create an archive file
$ tar -cvf myfile.txt /home/ilugc/
To create tar.gz Archive File
$ tar cvzf mydoc.tar.gz /home/ilugc/Documents
To create tar.bz2 archive file
$ tar cvfj mydownloads.tar.bz2 /home/ilugc/Downloads
To untar tar Archive file
$ tar -xvf mydoc.tar
To untar tar archive file in different location
$ tar -xvf mydoc.tar -C /home/ilugc/Music/
To uncompress tar.gz Archive File
$ tar -xvf mydoc.tar.gz
To Uncompress tar.bz2 Archive File
$ tar -xvf mydownloads.tar.bz2
To list Content of tar Archive File
$ tar -tvf mydoc.tar
To List Content tar.gz Archive File
$ tar -tvf mydoc.tar.gz
To List Content tar.bz2 Archive File
$ tar -tvf mydownloads.tar.bz2
To Untar Single file from tar File
$ tar -xvf files.sh.tar file.sh
To Untar Single file from tar.gz File
$ tar -zxvf backup.tar.gz backup.html
To Untar Single file from tar.bz2 File
$ tar -jxvf Python.tar.bz2 demo.py
To Untar Multiple files from tar, tar.gz, and tar.bz2 File
$ tar -xvf file.tar "file1" "file2" "file3"
$ tar -zxvf myfile.tar.gz "file1" "file2" "file3"
$ tar -jxvf myfiles.tar.bz2 "file1" "file2" "file3"
To Extract Group of Files using Wildcard
$ tar -xvf Python.tar --wildcards '*.py'
$ tar -zxvf Perl.tar.gz --wildcards '*.pl'
$ tar -jxvf Bash.tar.bz2 --wildcards '*.sh'
To add files or directories to the existing tar archive files
$ tar -rvf file.tar file.txt
$ tar -rvf file.tar demo.py
To Add Files or Directories to tar.gz and tar.bz2 Files
$ tar -rvf file.tar.gz sample.txt
$ tar -rvf Php.tar.bz2 sample.php
To verify any tar or compressed archive file
$ tar tvfW sample.tar
To Check the Size of the tar, tar.gz, and tar.bz2 Archive File
$ tar -czf - sample.tar | wc -c
$ tar -czf - mydocs.tar.gz | wc -c
$ tar -czf - mydownloads.tar.bz2 | wc -c
To Exclude Files and Directories When Creating Tar File
$ tar --exclude='example.txt' -zcvf file.tar.gz /home/ilugc
$ tar --exclude='/home/ilugc/songs' -zcvf backup.tar.gz /home/ilugc
To exclude files with specific file extensions when creating a tar archive
file,
$ tar --exclude='*.txt' -zcvf backup.tar.gz /home/ilugc
$ tar --exclude='*.py' -zcvf backup.tar.gz /home/ilugc
To remove File and Directory from Tar Archive
$ tar --delete -f backup.tar.gz sample.txt
$ tar --delete -f backup.tar.gz '/home/tecmint/songs'
To extract Specific File Extension in Tar Archive
$ tar -xvf backup.tar.gz --wildcards '*.mp4'
regards,
T.Dhanasekar
taskset - is used to set or retrieve the CPU affinity of a running process
To fetch the CPU Affinity of a Process
$ pidof sshd
$ taskset -p <PID_of_sshd>
To get the CPU range of a process
$ taskset -cp <PID_of_sshd>
To change the CPU affinity of a process by assigning the new value to the
PID of the existing process
$ taskset -p 0x7 <PID_of_sshd>
To Change CPU range
$ taskset -cp 0,2 <PID_of_sshd>
To set the CPU core
$ taskset -c 3,5 sshd
$ taskset -c 0-4 sshd
regards,
T.Dhanasekar
tail - output the last part of files
To display the last 10 lines of a file
$ tail /var/log/messages
To Display the last N lines in a file
$ tail -n 4 /var/log/messages
To Print filename header
$ tail -v example.txt
$ tail -v /var/log/messages
To Display the last n lines from multiple files
$ tail -n 4 file1.txt file2.txt
$ tail -n 4 /var/log/messages /var/log/apache2/access.log
To Save the output of tail command to a text file
$ tail -n 10 /var/log/apache2/access.log > output.txt
To append to output.txt
$ tail -n 10 /var/log/messages >> output.txt
To monitor real-time log files
$ tail -f /var/log/messages
To use pipes
$ tail -file.txt | sort
$ tail /var/log/messages | sort
$ tail /var/log/messages | tail -n 6 | sort
To Print N number of bytes data from a file
$ tail -c 500 /var/log/messages
$ tail -c 10M /var/log/messages
To print help options
$ tail --help
regards,
T.Dhanasekar
tac - is used to concatenate and print files in reverse
syntax
$ tac [OPTION]... [FILE]...
$ cat example.txt
This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
$ cat example1.txt
This is msg 1
This is msg 2
This is msg 3
This is msg 4
This is msg 5
To print files in reverse
$ tac example.txt
To attach the separator before instead of after
$ tac -b example.txt example1.txt
To make the STRING as the separator
$ tac --separator="STRING" example1.txt example.txt
To interpret the separator as a regular expression
$ tac -r example.txt example1.txt
regards,
T.Dhanasekar
systemd-machine-id-setup - Initialize the machine ID in /etc/machine-id
To clear the original “machine-id”
$ sudo rm /etc/machine-id
To create the new “machine-id” value
$ sudo systemd-machine-id-setup
To verify the new value of machine-id.
$ cat /etc/machine-id
regards,
T.Dhanasekar
systemd-analyse - Analyze and debug system manager
To determine system boot-up performance statistics
$ systemd-analyze
To Print time required to boot the machine
$ systemd-analyze time
To Print list of running units ordered by time to init
$ systemd-analyze blame
To Print a tree of the time critical chain of units
$ systemd-analyze critical-chain
Output state serialization of service manager
$ systemd-analyze dump
Output SVG graphic showing service initialization
$ systemd-analyze plot
To List load directories for units
$ systemd-analyze unit-paths
To List exit status definitions
$ systemd-analyze exit-status
To Analyze security of unit
$ systemd-analyze security
regards,
T.Dhanasekar