The command-line interface is one of the nearly all well built trademarks of Linux. There exists an ocean of Linux commands, permitting you to do nearly everything you can be under the impression of doing on your Linux operating system. Although, this to the end of time creates a problem: by all of so copious commands accessible to manage, you don't comprehend where and at which point to fly learning them, especially when you are learner. If you are facing this problem, and are peering for a painless method to begin your command line journey in Linux, you've come to the right place, as in this, we will launch you to a hold of well liked and helpful Linux commands.
Display system date and time.
Command:
date
Display calendar.
Command:
cal
Display date, time and calendar.
Command:
date & cal
Display August month 2016 year calendar.
Command:
cal 8 2016
Used to clear the terminal window.
Command:
clear
Exit from the terminal window.
Command:
exit
Display free and used system memory.
Command:
free
Display free and used system memory in bytes.
Command:
free -b
Display free and used system memory in kilobytes.
Command:
free -k
Display free and used system memory in megabytes.
Command:
free -m
Change user password.
Command:
passwd
Power-off the machine.
Command:
shutdown
Power-off the machine immediately.
Command:
shutdown -h now
Power-off the machine after 10 minutes.
Command:
shutdown -h +10
Print current working directory.
Command:
echo $PWD
Print previous working directory.
Command:
echo $OLDPWD
Executes the 11th command in command history.
Command:
!11
Reveals your command history.
Command:
history
Power off or reboot the Operating system.
Command:
sudo reboot
Display the IP address of the host.
Command:
ip address
List the size of files and directories.
Command:
ls -s
View mounted file systems.
Command:
mount
Display the information of disk usage of files and directories.
Command:
du
Tells you how long the system has been running.
Command:
uptime
Set current date as 02 Nov 1988.
Command:
date -- set 1998-11-02
Set current time as 12:11:02 IST.
Command:
date -- set 12:11:02
View Specific Disk Partition in Linux.
Command:
fdisk -l /dev/sda
Lists all files and directories in the present working directory.
Command:
ls
Report the process information.
Command:
ps
Display disk usage.
Command:
df
Display disk usage in gigabytes, megabytes, or kilobytes.
Command:
df -H
Delete every file and every directory.
Command:
rm -r *
Provides a quick overview of the currently running processes.
Command:
top
The system performs an immediate reboot.
Command:
reboot
Terminate processes without having to log out or reboot.
Command:
kill
Change the current working directory.
Command:
cd
Create a new session on the system.
Command:
login
List open files.
Command:
lsof
List USB devices.
Command:
lsusb
Check the status of the network services.
Command:
service network status
Start the network service.
Command:
service network start
Stop the network service.
Command:
service network stop
Restart the network service.
Command:
service network restart
Report information about the users currently on the machine and their processes.
Command:
w
Display the current directory.
Command:
pwd
Displays CPU architecture information (such as number of CPUs, threads, cores, sockets, and more).
Command:
lscpu
Displays the number of processing units available to the current process.
Command:
nproc
The system performs an immediate reboot.
Command:
init 6
Power-off the machine.
Command:
init 0
List files by date.
Command:
ls -lrt
Report information about storage devices such as hard disks, flash drives etc.
Command:
lsblk
Show exit status of previous command.
Command:
echo $?
Lists a few useful info commands.
Command:
info
Prints current year's calendar.
Command:
cal -y
Check the status of all the services.
Command:
service --status-all
Display time in hh:mm:ss.
Command:
date +%T
Tells when the user last logged on and off and from where.
Command:
last -1 username
Sort files and directories by extension name.
Command:
ls -X
Display the manual for the pwd command.
Command:
man pwd
Displays information about running processes in the form of a tree.
Command:
pstree
Resets your terminal.
Command:
reset
Displays What date is it this Friday.
Command:
date -d fri
Displays the size of each individual file.
Command:
du -a
Display information about the Advanced configuration and power Interface.
Command:
acpi
Takes you two folders back.
Command:
cd ../..
Takes you to the previous directory.
Command:
cd -
Displays a list of shell built-in commands.
Command:
help
Lists your last logins.
Command:
last yourusername
Create a new directory called myfiles.
Command:
mkdir myfiles
Remove the directory myfiles.
Command:
rmdir myfiles
Disable password for a specific user "root1".
Command:
passwd -d root1
Switch to user "root1".
Command:
sudo su root1
Exit from the terminal window.
Command:
logout
Creates a user "root1".
Command:
useradd "root1"
Assign password to user "root1".
Command:
passwd "root1"
Repeats the last command.
Command:
!!
Display Who you are logged in as.
Command:
whoami
Display the login name of the current user.
Command:
logname
Report the name of the kernel.
Command:
uname
Print the kernel version.
Command:
uname -v
Print the operating system.
Command:
uname -o
Report the machine hardware name.
Command:
uname -m
Print version information and exit.
Command:
uname --version
Print the kernel release.
Command:
uname -r
Report the network node hostname.
Command:
uname -n
Display all port connections (both TCP and UDP).
Command:
netstat -a
Display only TCP (Transmission Control Protocol) port connections.
Command:
netstat -at
Display only UDP (User Datagram Protocol) port connections.
Command:
netstat -au
Display all active listening ports.
Command:
netstat -I
Display all active listening TCP ports.
Command:
netstat -It
Display all active listening UDP ports.
Command:
netstat -lu
Reveal all the information about the current user (user id, username, group id, group name etc.).
Command:
id
Reveal all the information about the user "root1" (user id, username, group id, group name etc.).
Command:
id root1
Print the machine's architecture.
Command:
arch
Display the list of available fonts.
Command:
fc-list
Create two directories (myfiles, files).
Command:
mkdir myfiles files
install apache (CentOS).
Command:
yum install httpd
install apache (Ubuntu).
Command:
apt install httpd
upgrade apache (CentOS).
Command:
yum update httpd
upgrade apache (Ubuntu).
Command:
apt update httpd
uninstall apache (CentOS).
Command:
yum remove httpd
uninstall apache (Ubuntu).
Command:
apt remove httpd
Display usage summary for the command (date).
Command:
date --help
List active connections to/from system.
Command:
ss -tup
List internet services on a system.
Command:
ss -tupl
Display all active UNIX listening ports.
Command:
netstat -lx
Display all the active interfaces details.
Command:
ifconfig
Display information of all network interfaces.
Command:
ifconfig -a
Compare the contents of two files (1.txt, 2.txt).
Command:
diff 1.txt 2.txt
Tells you how many lines, words, and characters there are in a file (1.txt).
Command:
wc 1.txt
Compresses file (1.txt), so that it take up much less space.
Command:
gzip 1.txt
Uncompresses file (1.txt) compressed by gzip.
Command:
gunzip 1.txt
Examine the contents of the file (1.txt).
Command:
cat 1.txt
Display calendar.
Command:
ncal
Removes the file (1.txt).
Command:
rm 1.txt
Rename a file named 1.txt to 0.txt.
Command:
mv 1.txt 0.txt
Replace the contents of 0.txt with that of 1.txt.
Command:
cp 1.txt 0.txt
Create a empty file (test.txt).
Command:
touch test.txt
Print the last 10 lines of a file (1.txt).
Command:
tail 1.txt
Print N number of lines from the file (1.txt).
Command:
tail -n N 1.txt
Prints the number of words in a file (1.txt).
Command:
wc -w 1.txt
Prints the number of characters from a file (1.txt).
Command:
wc -m 1.txt
Prints the length of the longest line in a file (1.txt).
Command:
wc -L 1.txt
Print information about usb ports, graphics cards, network adapters etc.
Command:
lspci
View contents of a file (1.txt).
Command:
less 1.txt
Display calendar (last month, current month, and next month).
Command:
cal -3
Compare the contents of three files (1.txt, 2.txt, 3.txt) line by line.
Command:
diff3 1.txt 2.txt 3.txt
Compare two files (1.txt, 2.txt) line-by-line.
Command:
comm 1.txt 2.txt
Perform byte-by-byte comparison of two files (1.txt, 2.txt).
Command:
cmp 1.txt 2.txt
Prints the CRC checksum and byte count for the file "myfiles.txt".
Command:
cksum myfiles.txt
Append contents of files (1.txt, 2.txt) into one file (0.txt).
Command:
cat 1.txt 2.txt > 0.txt
Append contents of files (1.txt, 2.txt, 3.txt) into one file (0.txt).
Command:
sed r 1.txt 2.txt 3.txt > 0.txt
Append contents of files (1.txt, 2.txt, 3.txt) into one file (0.txt).
Command:
sed h 1.txt 2.txt 3.txt > 0.txt
Append contents of files (1.txt, 2.txt, 3.txt) into one file (0.txt).
Command:
sed -n p 1.txt 2.txt 3.txt > 0.txt
Shortcuts:
| ctrl+c | Halts the current command |
| ctrl+z | Stops the current command |
| | |
| ctrl+d | Logout the current session |
| ctrl+w | Erases one word in the current line |
| | |
| ctrl+u | Erases the whole line |
| ctrl+r | Type to bring up a recent command |
Writes contents of a file (0.txt) to output, and prepends each line with line number.
Command:
nl 0.txt
Create a empty file (test1.txt) inside a directory (test).
Command:
mkdir test
cd test
pwd
touch test1.txt
Gather information about hardware components such as CPU, disks, memory, USB controllers etc.
Command:
sudo lshw
Gather information about file system partitions.
Command:
sudo fdisk -l
Displays the line (good morning) in which the string (good) is found in the file (1.txt).
Command:
grep good 1.txt
Append contents of files (1.txt, 2.txt, 3.txt) into one file (0.txt) using for loop.
Command:
for i in {1..3}; do cat "$i.txt" >> 0.txt; done
Search for files (test.txt, test1.txt, test2.txt, test.php, test.html) in a directory as well as its sub-directories.
Command:
find test*
Displays status related to a file (1.txt).
Command:
stat 1.txt
###
| Command | Description |
|:-----------------|-------------: |
| vi | Open vi editor |
| i | Go to Insert mode |
| | |
| a =20; b =64; | |
| print (a + b); | |
| Hit Escape to return to Normal mode. |
| :w hello.py | Save text |
| :q | Quit |
| python hello.py |Print the output:84 |
Download the file (file.txt) from url "http: //website.com/files/file.txt".
Command:
wget http://website.com/files/file.txt
Display host's numeric ID in hexadecimal format.
Command:
hostid
Display file type of the file (myfiles.txt).
Command:
file myfiles.txt
Create a file (myfiles.txt) containing a text (Hello World).
Command:
echo 'Hello World' > myfiles.txt
Create a file (myfiles.txt) containing a text (Hello World).
Command:
printf 'Hello World' > myfiles.txt
Display IP address of the hostname.
Command:
hostname -i
Add a new line of text to an existing file (1.txt).
Command:
echo "Hello world!" >> 1.txt
echo "this is 2nd line text" >> 1.txt
echo "last line!" >> 1.txt
Displays a single line description about a command (cal).
Command:
whatis cal
###
| Command | Description |
|:-----------------|-------------: |
| vi | Open vi editor |
| i | Go to Insert mode |
| Type some text. | |
| Hit Escape to return to Normal mode. |
| :w test.txt | Save text |
| :q | Quit |
| :q! |Quit without saving |
###
| Command | Description |
|:-----------------|-------------: |
| vi | Open vi editor |
| i | Go to Insert mode |
| $name = "Paul"; | |
| print "$name"; | |
| Hit Escape to return to Normal mode. |
| :w hello.pl | Save text |
| :q | Quit |
| perl hello.pl |Print the output: Paul |
###
| Command | Description |
|:---------------------------|-------------: |
| vi | Open vi editor |
| i | Go to Insert mode |
| echo "What is your name?" | |
| read PERSON | |
| echo "Hello, $PERSON" | |
| Hit Escape to return to Normal mode. |
| :w hello.sh | Save text |
| :q | Quit |
| sh hello.sh | Output: |
| | What is your name? |
| | If you enter: Zara Ali |
| | Hello, Zara Ali |
Check the network connectivity between host (your connection) and server (Google server).
Command:
ping google.com
Find the location of source/binary file of a command (cal).
Command:
whereis cal
List the files in the bin directory.
Command:
ls /bin
List the files in the bin directory and the etc directory.
Command:
ls /bin /etc
Moves the file test.txt to the folder newrepo.
Command:
mv test.txt ./newrepo
Deletes all the lines in the test.txt containing tue word.
Command:
sed -i "/tue/d" test.txt
Show system reboot history.
Command:
last reboot
Displays the messages from the kernel ring buffer (a data structure that records messages related to the operation of the kernel).
Command:
dmesg
Display CPU information.
Command:
cat /proc/cpuinfo
Display memory information.
Command:
cat /proc/meminfo
Display PCI (Peripheral Component Interconnect) devices.
Command:
lspci -tv
Display USB devices.
Command:
lsusb –tv
Display free and used memory (-h for human readable, -m for MB, -g for GB).
Command:
free -h
Display processor related statistics.
Command:
mpstat 1
Display virtual memory statistics.
Command:
vmstat 1
Display Input / Output statistics.
Command:
iostat 1
Execute "df -h" command, showing periodic updates.
Command:
watch df -h
Display all the currently running processes on the system.
Command:
ps –ef
Display all network interfaces and IP address.
Command:
ip a
Display DNS information for domain (wikipedia.org).
Command:
dig wikipedia.org
Display the IP address details of the specified domain (wikipedia.org).
Command:
host wikipedia.org
Display listening Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP) ports and corresponding programs.
Command:
netstat -nutlp
List all installed packages.
Command:
rpm -qa
List all installed packages (CentOS).
Command:
yum list installed
Display description and summary information about package "httpd" (CentOS).
Command:
yum info httpd
Display disk usage for all files and directories in human readable format.
Command:
du -ah
Display total disk usage off the current directory.
Command:
du -sh
Change to the /etc directory.
Command:
cd /etc
List the status of all the processes along with process id and PID.
Command:
ps -A
Displays the file name of the terminal connected to standard input.
Command:
tty
Displays the contents of myfiles.txt file in octal format.
Command:
od -b myfiles.txt
Displays the contents of myfiles.txt file in character format.
Command:
od -c myfiles.txt
Displays the contents of myfiles.txt file in character format but with no offset information.
Command:
od -An -c myfiles.txt
If the file myfiles.txt has 123 lines, the csplit command would create four files: the xx00 file would contain lines 1−12, the xx01 file would contain lines 13−61, the xx02 file would contain lines 62−100, the xx03 file would contain lines 101−123.
Command:
csplit myfiles.txt 13 62 101
Prints a 32-character (128-bit) checksum of myfiles.txt file using the MD5 algorithm.
Command:
md5sum myfiles.txt
Displays the content of myfiles.txt file.
Command:
more myfiles.txt
Prints Secure Hash Algorithm 1 (160-bit) checksum of myfiles.txt file.
Command:
sha1sum myfiles.txt
Overwrites the myfiles.txt file repeatedly − in order to make it harder for even very expensive hardware probing to recover the data.
Command:
shred myfiles.txt
Print the lines of myfile.txt in reverse (from last line to first).
Command:
cat myfile.txt
01. Einstein
02. Newton
03. Maxwell
04. Tesla
05. Edison
tac myfile.txt
05. Edison
04. Tesla
03. Maxwell
02. Newton
01. Einstein
Displays a list of system services and whether they are started (on) or stopped (off) in run levels 0−6.
Command:
chkconfig --list
Power-off the system.
Command:
halt -p
Prints the details of the last login (login-name, port and last login time).
Command:
lastlog
Displays the login information (1 day ago).
Command:
lastlog -t 1
Display lastlog information for a particular user (manju).
Command:
lastlog -u manju
List all users on Linux.
Command:
cat /etc/passwd
more /etc/passwd
less /etc/passwd
getent passwd
List last 5 users on Linux.
Command:
tail -5 /etc/passwd
List first 5 users on Linux.
Command:
head -5 /etc/passwd
The message (The system will be shutdown in 10 minutes.) will be broadcasted to all users that are currently logged in.
Command:
wall "The system will be shutdown in 10 minutes."
List the password and its related details for a user (manju).
Command:
chage -l manju
Set Password Expiry Date for an user (manju).
Command:
chage -M 10 manju
Set the Account Expiry Date for an User (manju).
Command:
chage -E "2020-07-30" manju
Force the user (manju) account to be locked after 10 inactivity days.
Command:
chage -I 10 manju
Connect to an FTP server at remote server IP address "192.168.42.77".
Command:
ftp 192.168.42.77
Lists all the peers connected at various interfaces along with their MAC Addresses and IP addresses.
Command:
arp –a
Display the system's DNS domain name.
Command:
dnsdomainname
Display the name of the domain your machine belongs to.
Command:
domainname
Encode text (Hello World!) to base64.
Command:
echo 'Hello World!' | base64
Output: SGVsbG8gV29ybGQhCg==
Decode (SGVsbG8gV29ybGQhCg==) to text (Hello World!).
Command:
echo 'SGVsbG8gV29ybGQhCg==' | base64 -d
Output: Hello World!
Build font information cache files.
Command:
fc-cache -f –v
Formats text in a single line.
Command:
cat 1.txt
Einstein
Newton
Albert
fmt 1.txt
Einstein Newton Albert
Prints the route that a packet takes to reach the Google (172.217.26.206) host from the local machine.
Command:
traceroute google.com
View the contents of zipped file.
Command:
cat 1.txt
Einstein
Newton
Albert
gzip 1.txt
zcat 1.txt.gz
Einstein
Newton
Albert
Compare the contents of two zipped files (1.txt.gz, 2.txt.gz).
Command:
zdiff 1.txt.gz 2.txt.gz
List all connections.
Command:
ss | less
Filter out TCP (Transmission Control Protocol) connections.
Command:
ss -aA tcp
Filter out UDP (User Datagram Protocol) connections.
Command:
ss -aA udp
Display only listening sockets.
Command:
ss -lnt
Print process name and PID.
Command:
ss -ltp
Print summary statistics.
Command:
ss -s
Display only IPv6 connections.
Command:
ss -tl6
Display only IPv4 socket connections.
Command:
ss -tl -f inet
Display all IPv4 TCP sockets that are in connected state.
Command:
ss -t4 state established
View the memory map of a process with Process ID (3244).
Command:
pmap 3244
Find command that removes file.
Command:
apropos -r 'remove file'
Display information about the editing programs that are available on a system.
Command:
apropos editor
Provide information about the pstree command (which displays the names of the processes currently on the system in the form of a tree diagram).
Command:
apropos pstree
Print out a list of all environment variables.
Command:
env
Print HOME variable value.
Command:
printenv HOME
Reverse lines of a file (1.txt).
Command:
rev 1.txt
Lists the files with .txt extension.
Command:
ls -l *.txt
Print the Default shell of user.
Command:
echo $SHELL
Display the name of the currently running process ($0 is the name of the running process). If you use it inside of a shell then it will return the name of the shell. If you use it inside of a script, it will return the name of the script.
Command:
echo $0
Print all files and folders − similar to ls command.
Command:
echo *
Print the process ID of the current shell ($$ is the process ID of the current shell).
Command:
ps -p $$
List shells.
Command:
cat /etc/shells
List last logins of users and what happened such as "shutdown" or "crash" etc.
Command:
last
Compresses but does not deletes the original file.
Command:
bzip2 -k phy.txt
Decompresses the compressed file (phy.txt.bz2).
Command:
bzip2 -d phy.txt.bz2
Display the contents of compressed file (phy.txt.bz2).
Command:
bzcat phy.txt.bz2
Decompresses the compressed file (phy.txt.bz2).
Command:
bunzip2 phy.txt.bz2
Display current logged-in user's crontab entries.
Command:
crontab –l
Ping google.com and send the process to the background.
Command:
nohup ping google.com &
Save the ping logs to log.txt.
Command:
nohup ping google.com > log.txt &
Display the contents of /home.
Command:
ls -la /home
Power-off the machine after 2 minutes.
Command:
sudo shutdown 2
Cancel the shutdown process.
Command:
shutdown -c
Display the contents of the file (36.txt) one page after the other.
Command:
pr 36.txt
Display all current terminal settings.
Command:
stty –a
List files one per line.
Command:
ls -1
Outputs a string (John) repeatedly until killed.
Command:
yes John
List files and directories in the current directory (one per line) with details.
Command:
vdir
Print when the system was booted.
Command:
who -b
Display a list of currently mounted file systems.
Command:
findmnt
List IP addresses and network interfaces.
Command:
ip addr show
List active (listening) ports.
Command:
netstat -pnltu
Display systemd, kernel and journal logs.
Command:
Journalctl
Display the status of network service.
Command:
sudo systemctl status network
Start the network service.
Command:
sudo systemctl start network
Stop the network service.
Command:
sudo systemctl stop network
Display the current state of Booleans.
Command:
sestatus -b
Reports whether SELinux is enforcing, permissive or disabled.
Command:
getenforce
Display the current status of the SELinux that is running on your system.
Command:
sestatus
Display full listing of processes on your system.
Command:
ps –aef
Display System Activity Report.
Command:
sar
Report the resource limit of the current user.
Command:
ulimit
Report all the resource limits for the current user.
Command:
ulimit -a
Check the maximum stack size of the current user.
Command:
ulimit –s
Check out the max scheduling priority of the current user.
Command:
ulimit –e
Display the maximum number of user processes.
Command:
ulimit –u
Check out the size of virtual memory.
Command:
ulimit –v
Check out how many file descriptors a process can have.
Command:
ulimit –n
Display the in-depth information on the limits.conf configuration file.
Command:
man limits.conf
Display the sar version.
Command:
sar -V
Report CPU details total 5 times with the interval of 2 seconds.
Command:
sar -u 2 5
Report about network interface, network speed, IPV4, TCPV4, ICMPV4 network traffic and errors.
Command:
sar -n DEV 1 3 | egrep -v lo
Report details about the process, kernel thread, i-node, and the file tables.
Command:
sar -v 1 3
Report statistics about swapping.
Command:
sar -S 1 3
Report statistics about swapping.
Command:
sar -S 1 3
Report details about I/O operations like transaction per second, read per second, write per second.
Command:
sar -b 1 3
Display the status of the firewalld.
Command:
sudo systemctl status firewalld
Start the firewalld service.
Command:
sudo systemctl start firewalld
Start the graphical firewall configuration tool.
Command:
firewall-config
List all zones.
Command:
firewall-cmd --list-all-zones
Check the currently set default zone.
Command:
firewall-cmd --get-default-zone
Display currently allowed service on your system.
Command:
firewall-cmd --list-services
List the ports that are open on your system.
Command:
firewall-cmd --list-ports
List services that are allowed for the public zone.
Command:
firewall-cmd --zone=work --list-services
Provides information about the route that Internet traffic takes between the local system and a remote host (google.com).
Command:
mtr --report google.com
Install Samba (CentOS).
Command:
sudo yum install samba
Add Samba service to firewalld.
Command:
sudo firewall-cmd --add-service samba –permanent
Create a zip file (q.zip).
Command:
zip q.zip q.txt
Unzip a zip file (q.zip).
Command:
unzip q.zip
Display the names of the files with the word (Einstein) present in it.
Command:
zgrep -l "Einstein" *
Split q.zip file to create a sequence of zipfiles (q1.zip, q2.zip…..) − each no larger than 1048576 bytes (one megabyte).
Command:
zipsplit -n 1048576 q.zip
Test the route and connection quality of traffic to the destination host google.com.
Command:
mtr google.com
Display IP routing table of a Linux system.
Command:
route
View all your network devices.
Command:
nmcli dev status
Check network connections on your system.
Command:
nmcli con show
List all TCP ports (sockets) that are open on a server.
Command:
ss –ta
Display all active TCP connections together with their timers.
Command:
ss -to
Check Bash Aliases in Linux.
Command:
type -a alias
Print yesterday's date and time.
Command:
echo "Yesterday = $(date -d "Yesterday")"
Print Tomorrow date and time.
Command:
echo "tomorrow = $(date -d "tomorrow")"
Find what is the date and time before 10 days from now.
Command:
echo "Before 10 days = $(date -d "tomorrow -10 days")"
Find last month and next month.
Command:
echo "Last month = $(date -d "last month" "%B")"
echo "Next month = $(date -d "next month" "%B")"
Find last year and next year.
Command:
echo "Last Year = $(date -d "last year" "+%Y")"
echo "Next Year = $(date -d "next year" "+%Y")"
Get the number of inodes of files in a directory (root directory).
Command:
ls -lai /
Get the total number of inodes in the root directory.
Command:
sudo du --inode /
Get the list of all clients connected to HTTP (Port 80) or HTTPS (Port 443).
Command:
ss -o state established '( sport = :http or sport = :https )'
List the numerical port numbers.
Command:
ss -tn src :80 or src :443
Install PuTTy on CentOS.
Command:
sudo yum install putty
Watch TCP and UDP Open Ports in Real-Time.
Command:
sudo watch netstat -tulpn
Watch TCP and UDP Open Ports in Real-Time.
Command:
sudo watch ss –tulpn
Timeout a ping command after 5 seconds.
Command:
timeout 5s ping google.com
Install curl on CentOS.
Command:
yum install curl
List all UDP Connections.
Command:
ss –ua
List all Listening UDP Connections.
Command:
ss –lu
Display the Process IDs related to socket connections.
Command:
ss -p
Display IPv4 and IPv6 Socket Connections.
Command:
ss -4
Display IPv6 connections.
Command:
ss -6
Filter Connections by Port Number.
Command:
ss -at '( dport = :22 or sport = :22 )'
Show Difference between Two Files (phy.txt and score.txt).
Command:
sdiff phy.txt score.txt
Delete or clear all the entries from bash history.
Command:
history -c
The ping test will stop after sending 5 packets.
Command:
ping -c 5 www.google.com
# count number of lines in each .txt file
ls *.txt | xargs wc -l
# count number of words in each .txt file
ls *.txt | xargs wc -w
# count number of characters in each .txt file
ls *.txt | xargs wc -c
# count lines, words and characters in each .txt file
ls *.txt | xargs wc
Displays user accounts.
Command:
lslogins –u
List all loaded services on your system (whether active; running, exited or failed).
Command:
systemctl list-units --type=service
List all loaded services on your system (whether active; running, exited or failed).
Command:
systemctl --type=service
List all loaded but active services.
Command:
systemctl list-units --type=service --state=active
List all loaded but active services.
Command:
systemctl --type=service --state=active
List all running services (i.e., all loaded and actively running services).
Command:
systemctl list-units --type=service --state=running
List all running services (i.e., all loaded and actively running services).
Command:
systemctl --type=service --state=running
#scan a single port
nc -v -w 2 z 192.168.56.1 22
# scan multiple ports
nc -v -w 2 z 192.168.56.1 22 80
# scan range of ports
nc -v -w 2 z 192.168.56.1 20-25
Find out your DNS Server IP address.
Command:
cat /etc/resolv.conf
Find out your DNS Server IP address.
Command:
less /etc/resolv.conf
Monitor mount, unmount, remount and move actions on a directory (i.e., on /mnt/test).
Command:
findmnt --poll --mountpoint /mnt/test
Check Linux Server Uptime.
Command:
uptime -p
Check Linux Server Starting Time.
Command:
uptime –s
Display uptime's version information.
Command:
uptime –h
Count the number of times "Justin" appears in the file (score.txt).
Command:
grep -o -i Justin score.txt | wc –l
Delete all crontab jobs.
Command:
crontab -r
ADD=$(( 1 + 2 ))
echo $ADD
3
MUL=$(( $ADD * 5 ))
echo $MUL
15
SUB=$(( $MUL - 5 ))
echo $SUB
10
DIV=$(( $SUB / 2 ))
echo $DIV
5
MOD=$(( $DIV % 2 ))
echo $MOD
1
Find the length of a string (This is myw3schools.com).
Command:
expr length "This is myw3schools.com"
echo '3+5' | bc
8
awk 'BEGIN { a = 6; b = 2; print "(a + b) = ", (a + b) }'
(a + b) = 8
Decompose an integer (10) into prime factors.
Command:
factor 10
Display every active process on a Linux system.
Command:
ps -e
Display User Running Processes.
Command:
ps -x
Display a user's processes by user name (manju).
Command:
ps -fU manju
Display a user's processes by real user ID (RUID).
Command:
ps -fu 1000
Display every process running with root user privileges (real and effective ID).
Command:
ps -U root -u root
Install Nix Package Manager in Linux.
Command:
sh <(curl https://nixos.org/nix/install) --daemon
View System Locale in Linux.
Command:
locale
Display a list of all available locales.
Command:
locale –a
cat score.txt
Justin-40
cat score.txt | tr [:lower:] [:upper:]
JUSTIN-40
cat score.txt | tr [a-z] [A-Z] >output.txt
cat output.txt
JUSTIN-40
cat domainnames.txt
www. google. com
www. fb. com
www. mactech. com
# Remove the spaces in the domain names
cat domainnames.txt | tr -d ''
www.google.com
www.fb.com
www.mactech.com
Re-execute previously used command.
Command:
!sud
Re-execute previously used command.
Command:
!sudo
Generate a compact list of all Linux user accounts on the system.
Command:
cut -d: -f1 < /etc/passwd | sort | xargs
View multiple compressed files (phy.txt.gz and myfiles.txt.gz).
Command:
zcat phy.txt.gz myfiles.txt.gz
Find all php files in a directory.
Command:
find . -type f -name "*.php"
Find all the files whose permissions are 777.
Command:
find . -type f -perm 0777 -print
Find all the files without permission 777.
Command:
find / -type f ! -perm 777
Find all SGID set files.
Command:
find / -perm /g=s
Find all Read-Only files.
Command:
find / -perm /u=r
Find all Executable files.
Command:
find / -perm /a=x
Find and remove phy.txt File.
Command:
find . -type f -name "phy.txt" -exec rm -f {} \;
To find and remove multiple .txt files.
Command:
find . -type f -name "*.txt" -exec rm -f {} \;
To find and remove multiple .mp3 files.
Command:
find . -type f -name "*.mp3" -exec rm -f {} \;
Find all Empty Directories.
Command:
find /tmp -type d -empty
File all Hidden Files.
Command:
find /tmp -type f -name ".*"
Find Last 50 Days Modified Files.
Command:
find / -mtime 50
Find Last 50 Days Accessed Files.
Command:
find / -atime 50
Find Changed Files in Last 1 Hour.
Command:
find / -cmin -60
Find Modified Files in Last 1 Hour.
Command:
find / -mmin -60
Find Accessed Files in Last 1 Hour.
Command:
find / -amin -60
Find all 50 MB files.
Command:
find / -size 50M
Find and Delete 100 MB Files.
Command:
find / -type f -size +100M -exec rm -f {} \;
Find all .mp3 files with more than 10 MB and delete them.
Command:
find / -type f -name *.mp3 -size +10M -exec rm {} \;
Find Linux Open File Limit.
Command:
cat /proc/sys/fs/file-max
Check Hard Limit in Linux.
Command:
ulimit -Hn
Check Soft Limits in Linux.
Command:
ulimit -Sn
Display the current time and date on your system.
Command:
timedatectl status
View all available timezones.
Command:
timedatectl list-timezones
Find the local timezone according to your location.
Command:
timedatectl list-timezones | egrep -o "Asia/B.*"
timedatectl list-timezones | egrep -o "Europe/L.*"
timedatectl list-timezones | egrep -o "America/N.*"
Set your local timezone in Linux.
Command:
timedatectl set-timezone "Asia/Kolkata"
View a summary of swap space usage by device.
Command:
swapon --summary
Check swap usage information.
Command:
cat /proc/swaps
# start recording of Linux terminal
script history_log.txt
Script started, file is history_log.txt
exit
Script done, file is history_log.txt
List files and their allocated sizes in blocks.
Command:
dir -shl
Display information about CD-ROM.
Command:
less /proc/sys/dev/cdrom/info
while true; do date >> date.txt ; sleep 5 ; done &
cat date.txt
Mon Aug 16 03:05:36 PDT 2021
Mon Aug 16 03:05:41 PDT 2021
Mon Aug 16 03:05:46 PDT 2021
Mon Aug 16 03:05:51 PDT 2021
Print all .jpeg files.
Command:
echo *.jpeg
a=$(pwd)
echo "Current working directory is : $a"
/home/manju
Break down a word (linux) into individual letters.
Command:
echo 'linux' | fold -w1
Break down a word (linux) into individual letters.
Command:
echo 'linux' | fold -w1
Output the files with respect of the user (root) owned files in the current directory.
Command:
find . -user root
Trace a command (pwd) execution.
Command:
strace pwd
Display specific User (manju) process details.
Command:
top -u manju
Find Out Linux Kernel Version.
Command:
uname –or
Print linux system information.
Command:
uname -a
Display some of your system information including the Linux kernel version.
Command:
cat /proc/version
Find Out Linux Distribution Name and Release Version.
Command:
cat /etc/centos-release
Find Out Linux Distribution Name and Release Version.
Command:
fuser .
Determine which processes are accessing your ~.bashrc file.
Command:
fuser -v -m .bashrc
Displays all the possible signals that can be used with the fuser tool.
Command:
sudo fuser --list-signals
Sends the HUP signal to all processes that have your /boot directory open.
Command:
sudo fuser -k -HUP /boot
Shutdown the system at 23:55 today.
Command:
echo "shutdown -h now" | at -m 23:55
Run updatedb at 23:55 today.
Command:
echo "updatedb" | at -m 23.55
Display the top 15 processes sorted by memory use in descending order.
Command:
top -b -o +%MEM | head -n 22
Redirect the output to a file (report.txt) for later inspection.
Command:
top -b -o +%MEM | head -n 22 > report.txt
Check Top Processes sorted by RAM or CPU Usage in Linux.
Command:
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head
Find all files in the current directory with .sh and .txt file extensions.
Command:
find . -type f \( -name "*.sh" -o -name "*.txt" \)
Find all files in the current directory with .sh, .c and .txt file extensions.
Command:
find . -type f \( -name "*.sh" -o -name "*.txt" -o -name "*.c" \)
Delete repeated lines in the file (myfiles.txt).
Command:
uniq myfiles.txt
Open a file (myfiles.txt).
Command:
xdg-open myfiles.txt
Display the files in the current folder that start with the letter "m".
Command:
echo m*
Print your home folder path.
Command:
echo ~
List all the files with the file permissions, the number of links to that file, the owner of the file, the group of the file, the file size in bytes, the file's last modified datetime and the file name.
Command:
ls -al
Execute command "ls -al" and print the result to the standard output.
Command:
echo $(ls -al)
# Everyone can now read the file
chmod a+r myfiles.txt
# Everyone can now read and write the file
chmod a+rw myfiles.txt
# Others (not the owner, not in the same group of the file) cannot read, write or execute the file
chmod o-rwx myfiles.txt
Identifies whether the "cat" command is a shell built-in command, subroutine, alias, or keyword.
Command:
type cat
Find files edited more than 3 days ago.
Command:
find . -type f -mtime +3
Find files edited in the last 24 hours.
Command:
find . -type f -mtime -1
Find files that have more than 100 characters (bytes) in them.
Command:
find . -type f -size +100c
Find files bigger than 100 KB but smaller than 1 MB.
Command:
find . -type f -size +100k -size -1M
Deletes all the files edited in the last 24 hours.
Command:
find . -type f -mtime -1 -delete
List all files including hidden files.
Command:
ls -a
List Files and Directories with "/" Character at the End.
Command:
ls -F
List Files in Reverse Order.
Command:
ls -r
Sort Files by File Size.
Command:
ls -lS
List Files with an inode number.
Command:
ls -i
Check the version of the ls command.
Command:
ls --version
List files under directory /tmp.
Command:
ls -l /tmp
Display UID and GID of files and directories.
Command:
ls -n
Find all 30 MB files.
Command:
find / -size 30M
Find files with sizes between 100 - 200MB.
Command:
find / -size +100M -size -200M
List directories larger than 20 KB.
Command:
find / -type d -size +20k
Find empty files and directories.
Command:
find ./ -type f -size 0
List files modified within the last 17 hours.
Command:
find . -mtime -17 -type f
*** List directories modified within the last 10 days.***
Command:
find . -mtime -10 -type d
List all files modified between 6 and 15 days ago in the home directory.
Command:
find /home -type f -mtime +6 -mtime -15
Display files with permission 777.
Command:
find -perm 777
List files owned by a user (manju).
Command:
find /home -user manju
Find all text files owned by user "manju".
Command:
find /home -user manju -iname "*.txt"
Find and list files and directories together with their permissions.
Command:
find -name "*.conf" | ls -l
List directories only.
Command:
ls -d */
List multiple files on a single line.
Command:
ls --format=comma
View the process of a specific user "manju".
Command:
ps -u manju
Execute a previous command starting with a specific letter "c".
Command:
!c
Display BIOS information (You need elevated permissions to run this).
Command:
dmidecode -t 0
Display CPU information (You need elevated permissions to run this).
Command:
dmidecode -t 4
View all the system logs.
Command:
gnome-system-log
Identify SSH Client Version.
Command:
ssh -V
Display total connect time of users.
Command:
ac –d
Display connect time for all the users.
Command:
ac -p
Diaplay connect time report for a specific user "manju".
Command:
ac -d manju
Display the modules compiled inside Apache.
Command:
httpd -l
*** View Processes Owned by Current User.***
Command:
ps U $USER
Display the information about the filesystem Type.
Command:
df -Tha
Display Active Connections with Process ID and Program Name.
Command:
netstat -tap
Display RAW network statistics.
Command:
netstat --statistics --raw
Display all .txt files including its individual permission.
Command:
ls -al *.txt
View system defined cron jobs.
Command:
cat /etc/crontab
Check which ports are in listening in Linux Server.
Command:
netstat --listen
Check Inodes on File system.
Command:
df -i /dev/sda1
Find Inode number of File (myfiles.txt).
Command:
ls -il myfiles.txt
Check ACL (Access control list) configured on a file (myfiles.txt).
Command:
getfacl myfiles.txt
Check information of disk usage of files and directories on a machine.
Command:
du -sh /var/log/*
Display dependencies of the "cp" command.
Command:
ldd /bin/cp
Display dependencies of the "cp" command with details.
Command:
ldd -v /bin/cp
Display unused direct dependencies of the "cp" command.
Command:
ldd -u /bin/cp
Check all installed packages of ftp.
Command:
rpm –qa | grep ftp
Find files in the /home directory which were modified more than 120 days ago.
Command:
find /home -mtime +120
Find files in the /var directory that have not been accessed in the last 90 days.
Command:
find /var -atime -90
Search for core files in the entire directory tree and delete them as found without prompting for confirmation.
Command:
find / -name core -exec rm {} \;
Check current run level of a Linux server.
Command:
who –r
Display the content of file (myfiles.txt).
Command:
awk '{print}' myfiles.txt
Create hard-link to myfiles.txt.
Command:
ln myfiles.txt hardF1
Check content of the hard link - hardF1.
Command:
cat hardF1
Create Soft-link to myfiles.txt.
Command:
ln myfiles.txt softF1
Check content of the soft link - softF1.
Command:
cat softF1
Display information about the process with process ID – 13.
Command:
ps -p 13
Set the file size limit to 51,200 bytes.
Command:
ulimit -f 100
Find out what kernel modules are currently loaded.
Command:
lsmod
Install php version 7.2.
Command:
sudo yum install php
Run a PHP statement from the command line without creating a file.
Command:
php -r 'echo "Hello World\r\n";'
Start a PHP interactive shell.
Command:
php -a
- Transcendent Memory and Linux
- Understanding Linux Malware
- Frightening small children and disconcerting grown-ups: Concurrency in the Linux kernel
- Advanced Linux Security
- Linux As a Real-Time Operating System
- The Linux Scheduler: a Decade of Wasted Cores
- Understanding Fileless Attacks on Linux-based IoT Devices with HoneyCloud
- A Study of Linux File System Evolution
- A complete guide to Linux process scheduling
- An Analysis of Linux Operating System
- Introduction to Linux: A Hands on Guide
- Linux Kernel Development: How Fast it is Going, Who is Doing It, What They are Doing, and Who is Sponsoring It
- Linux: a Portable Operating System
- Linux MIPS - A soft target: past, present, and future
- An Analysis of Linux Scalability to Many Cores
- Profiling and Tracing in Linux
- Linux Graphics Drivers: an Introduction
- Optimize Your Infrastructure with Oracle Linux: Minimize Operating Expenses and Maximize Value
- Linux Questions and Answers
- Linux System Administration
- Modern Day Penetration Testing Distribution Open Source Platform [Kali Linux]
- Understanding and Hardening Linux Containers
- K-Miner: Uncovering Memory Corruption in Linux
- Security Assurance Requirements for Linux Application Container Deployments
- NixOS: A Purely Functional Linux Distribution
- On the Effectiveness of Full-ASLR on 64-bit Linux
- Proceedings of the Linux Symposium: Volume One
- SCONE: Secure Linux Containers with Intel SGX
- A Comparison of Scheduling Latency in Linux, PREEMPT RT, and LITMUS
- The real-time Linux kernel: a Survey on PREEMPT_RT
- Penetration Testing using Linux Tools: Attacks and Defense Strategies
- Transactional system calls on Linux
- Reduce Costs and Improve Business Performance with Linux
- Red Hat Enterprise Linux 7: System Administrator's Guide
- Linux Performance and Tuning Guidelines
- Analysis and Study of Security Mechanisms inside Linux Kernel
- Architectural design for a secure Linux operating system
- Secure Programming for Linux and Unix HOWTO
- Addressing Security Issues in Linux
- On the Linux Compatibility Layer in OpenBSD 5.0
- Slurm: Simple Linux Utility for Resource Management
- Taking a Proactive Approach to Linux Server Patch Management
- The Linux Command Line
- Unikernels: The Next Stage of Linux's Dominance
- Cloud on Linux Operating System
- AWS Security Best Practices
- Studying Main Differences Between Linux and Windows Operating Systems
- A Practical Guide to Linux Commands, Editors, and Shell Programming
- CentOS 7 Linux Server Cookbook
- CompTIA Linux+ Guide to Linux Certification
- Sams Teach Yourself Linux in 24 Hours
- Go Systems Programming: Master Linux and Unix system level programming with Go
- Hacking Exposed Linux: Linux Security Secrets and Solutions
- How Linux Works: What Every Superuser Should Know
- Learn CentOS Linux Network Services
- Linux Administration: A Beginner's Guide
- Linux All-in-One Desk Reference For Dummies
- Linux and Solaris Recipes for Oracle DBAs
- Linux Apache Web Server Administration
- Linux Basics for Hackers: Getting Started with Networking, Scripting, and Security in Kali
- Linux in a Nutshell
- LPI Linux Certification: Basic Level 1
- Linux Kernel Development
- Linux Malware Incident Response: A Practitioner's Guid to Forensic Collection and Examination of Volatile Data
- Linux Shell Scripting with Bash
- Learn the Basics of Linux in 2 Weeks
- Linux: Powerful Server Administration
- Linux: The Complete Reference
- Linux: The Ultimate Step by Step Guide to Quickly and Easily Learning Linux
- Linux Bible
- Linux Dictionary
- Linux Servers
- LPIC-1: Linux Professional Institute Certification Study Guide
- Mastering Kali Linux
- Operating System Concepts and Basic Linux Commands
- Python for Unix and Linux System Administration
- Step by Step Linux Guide
- The Linux Command Line: A Complete Introduction
- The Linux Programming Interface
- Linux in Action
- Understanding Linux Network Internals
- DevOps Troubleshooting: Linux Server Best Practices
- Learn Linux in a Month of Lunches
- Linux Device Drivers
- Pro Linux Embedded Systems
- Linux for Beginners: The Ultimate Guide To The Linux Operating System and Linux Commands
- Linux in the Workplace
- Linux: The Textbook
- Linux − Das Buch
- Red Hat Linux 7.2 Bible
- A Practical Guide to Ubuntu Linux
- Essential System Administration: Tools and Techniques for Linux and Unix Administration
- Linux Samba Server Administration
- LPI Linux Certification in a Nutshell
- Foundations of CentOS Linux: Enterprise Linux On the Cheap
- Linux 101 Hacks
- Advanced Linux Programming
- Mastering Modern Linux