Giter Site home page Giter Site logo

important-linux-commands-you-should-know's Introduction

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


Linux


Description:

Display system date and time.


Command:

date

Description:

Display calendar.


Command:

cal

Description:

Display date, time and calendar.


Command:

date & cal

Description:

Display August month 2016 year calendar.


Command:

cal 8 2016

Description:

Used to clear the terminal window.


Command:

clear

Description:

Exit from the terminal window.


Command:

exit

Description:

Display free and used system memory.


Command:

free

Description:

Display free and used system memory in bytes.


Command:

free  -b

Description:

Display free and used system memory in kilobytes.


Command:

free  -k

Description:

Display free and used system memory in megabytes.


Command:

free  -m

Description:

Change user password.


Command:

passwd

Description:

Power-off the machine.


Command:

shutdown

Description:

Power-off the machine immediately.


Command:

shutdown  -h now

Description:

Power-off the machine after 10 minutes.


Command:

shutdown  -h +10

Description:

Print current working directory.


Command:

echo $PWD

Description:

Print previous working directory.


Command:

echo $OLDPWD

Description:

Executes the 11th command in command history.


Command:

!11

Description:

Reveals your command history.


Command:

history

Description:

Power off or reboot the Operating system.


Command:

sudo reboot

Description:

Display the IP address of the host.


Command:

ip address

Description:

List the size of files and directories.


Command:

ls  -s

Description:

View mounted file systems.


Command:

mount

Description:

Display the information of disk usage of files and directories.


Command:

du

Description:

Tells you how long the system has been running.


Command:

uptime

Description:

Set current date as 02 Nov 1988.


Command:

date -- set 1998-11-02

Description:

Set current time as 12:11:02 IST.


Command:

date -- set 12:11:02

Description:

View Specific Disk Partition in Linux.


Command:

fdisk -l /dev/sda

Description:

Lists all files and directories in the present working directory.


Command:

ls

Description:

Report the process information.


Command:

ps

Description:

Display disk usage.


Command:

df

Description:

Display disk usage in gigabytes, megabytes, or kilobytes.


Command:

df  -H

Description:

Delete every file and every directory.


Command:

rm  -r *

Description:

Provides a quick overview of the currently running processes.


Command:

top

Description:

The system performs an immediate reboot.


Command:

reboot

Description:

Terminate processes without having to log out or reboot.


Command:

kill

Description:

Change the current working directory.


Command:

cd

Description:

Create a new session on the system.


Command:

login

Description:

List open files.


Command:

lsof

Description:

List USB devices.


Command:

lsusb

Description:

Check the status of the network services.


Command:

service network status

Description:

Start the network service.


Command:

service network start

Description:

Stop the network service.


Command:

service network stop

Description:

Restart the network service.


Command:

service network restart

Description:

Report information about the users currently on the machine and their processes.


Command:

w

Description:

Display the current directory.


Command:

pwd

Description:

Displays CPU architecture information (such as number of CPUs, threads, cores, sockets, and more).


Command:

lscpu

Description:

Displays the number of processing units available to the current process.


Command:

nproc

Description:

The system performs an immediate reboot.


Command:

init 6

Description:

Power-off the machine.


Command:

init 0

Description:

List files by date.


Command:

ls -lrt

Description:

Report information about storage devices such as hard disks, flash drives etc.


Command:

lsblk

Description:

Show exit status of previous command.


Command:

echo $?

Description:

Lists a few useful info commands.


Command:

info

Description:

Prints current year's calendar.


Command:

cal -y 

Description:

Check the status of all the services.


Command:

service --status-all 

Description:

Display time in hh:mm:ss.


Command:

date +%T

Description:

Tells when the user last logged on and off and from where.


Command:

last  -1 username

Description:

Sort files and directories by extension name.


Command:

ls  -X

Description:

Display the manual for the pwd command.


Command:

man pwd

Description:

Displays information about running processes in the form of a tree.


Command:

pstree

Description:

Resets your terminal.


Command:

reset

Description:

Displays What date is it this Friday.


Command:

date -d fri

Description:

Displays the size of each individual file.


Command:

du  -a

Description:

Display information about the Advanced configuration and power Interface.


Command:

acpi

Description:

Takes you two folders back.


Command:

cd ../..

Description:

Takes you to the previous directory.


Command:

cd -

Description:

Displays a list of shell built-in commands.


Command:

help

Description:

Lists your last logins.


Command:

last yourusername

Description:

Create a new directory called myfiles.


Command:

mkdir myfiles

Description:

Remove the directory myfiles.


Command:

rmdir myfiles

Description:

Disable password for a specific user "root1".


Command:

passwd -d root1

Description:

Switch to user "root1".


Command:

sudo su root1

Description:

Exit from the terminal window.


Command:

logout

Description:

Creates a user "root1".


Command:

useradd "root1"

Description:

Assign password to user "root1".


Command:

passwd "root1"

Description:

Repeats the last command.


Command:

!!

Description:

Display Who you are logged in as.


Command:

whoami

Description:

Display the login name of the current user.


Command:

logname

Description:

Report the name of the kernel.


Command:

uname

Description:

Print the kernel version.


Command:

uname  -v

Description:

Print the operating system.


Command:

uname  -o

Description:

Report the machine hardware name.


Command:

uname  -m

Description:

Print version information and exit.


Command:

uname  --version

Description:

Print the kernel release.


Command:

uname  -r

Description:

Report the network node hostname.


Command:

uname  -n

Description:

Display all port connections (both TCP and UDP).


Command:

netstat  -a

Description:

Display only TCP (Transmission Control Protocol) port connections.


Command:

netstat  -at

Description:

Display only UDP (User Datagram Protocol) port connections.


Command:

netstat  -au

Description:

Display all active listening ports.


Command:

netstat  -I

Description:

Display all active listening TCP ports.


Command:

netstat  -It

Description:

Display all active listening UDP ports.


Command:

netstat  -lu

Description:

Reveal all the information about the current user (user id, username, group id, group name etc.).


Command:

id

Description:

Reveal all the information about the user "root1" (user id, username, group id, group name etc.).


Command:

id  root1

Description:

Print the machine's architecture.


Command:

arch

Description:

Display the list of available fonts.


Command:

fc-list

Description:

Create two directories (myfiles, files).


Command:

mkdir myfiles files

Description:

install apache (CentOS).


Command:

yum install httpd

Description:

install apache (Ubuntu).


Command:

apt install httpd

Description:

upgrade apache (CentOS).


Command:

yum update httpd

Description:

upgrade apache (Ubuntu).


Command:

apt update httpd

Description:

uninstall apache (CentOS).


Command:

yum remove httpd

Description:

uninstall apache (Ubuntu).


Command:

apt remove httpd

Description:

Display usage summary for the command (date).


Command:

date --help

Description:

List active connections to/from system.


Command:

ss -tup

Description:

List internet services on a system.


Command:

ss -tupl

Description:

Display all active UNIX listening ports.


Command:

netstat  -lx

Description:

Display all the active interfaces details.


Command:

ifconfig

Description:

Display information of all network interfaces.


Command:

ifconfig  -a

Description:

Compare the contents of two files (1.txt, 2.txt).


Command:

diff 1.txt 2.txt

Description:

Tells you how many lines, words, and characters there are in a file (1.txt).


Command:

wc 1.txt

Description:

Compresses file (1.txt), so that it take up much less space.


Command:

gzip 1.txt

Description:

Uncompresses file (1.txt) compressed by gzip.


Command:

gunzip 1.txt

Description:

Examine the contents of the file (1.txt).


Command:

cat 1.txt

Description:

Display calendar.


Command:

ncal

Description:

Removes the file (1.txt).


Command:

rm 1.txt

Description:

Rename a file named 1.txt to 0.txt.


Command:

mv 1.txt 0.txt

Description:

Replace the contents of 0.txt with that of 1.txt.


Command:

cp 1.txt 0.txt

Description:

Create a empty file (test.txt).


Command:

touch test.txt

Description:

Print the last 10 lines of a file (1.txt).


Command:

tail 1.txt

Description:

Print N number of lines from the file (1.txt).


Command:

tail  -n N 1.txt

Description:

Prints the number of words in a file (1.txt).


Command:

wc -w 1.txt

Description:

Prints the number of characters from a file (1.txt).


Command:

wc -m 1.txt

Description:

Prints the length of the longest line in a file (1.txt).


Command:

wc -L 1.txt

Description:

Print information about usb ports, graphics cards, network adapters etc.


Command:

lspci

Description:

View contents of a file (1.txt).


Command:

less 1.txt

Description:

Display calendar (last month, current month, and next month).


Command:

cal -3

Description:

Compare the contents of three files (1.txt, 2.txt, 3.txt) line by line.


Command:

diff3 1.txt 2.txt 3.txt

Description:

Compare two files (1.txt, 2.txt) line-by-line.


Command:

comm 1.txt 2.txt

Description:

Perform byte-by-byte comparison of two files (1.txt, 2.txt).


Command:

cmp 1.txt 2.txt

Description:

Prints the CRC checksum and byte count for the file "myfiles.txt".


Command:

cksum myfiles.txt

Description:

Append contents of files (1.txt, 2.txt) into one file (0.txt).


Command:

cat 1.txt 2.txt > 0.txt

Description:

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

Description:

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

Description:

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   | 
 

Description:

Writes contents of a file (0.txt) to output, and prepends each line with line number.


Command:

nl 0.txt

Description:

Create a empty file (test1.txt) inside a directory (test).


Command:

mkdir test 
cd test 
pwd 
touch test1.txt

Description:

Gather information about hardware components such as CPU, disks, memory, USB controllers etc.


Command:

sudo lshw

Description:

Gather information about file system partitions.


Command:

sudo fdisk -l

Description:

Displays the line (good morning) in which the string (good) is found in the file (1.txt).


Command:

grep good 1.txt

Description:

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

Description:

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*

Description:

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 | 
 

Description:

Download the file (file.txt) from url "http: //website.com/files/file.txt".


Command:

wget http://website.com/files/file.txt

Description:

Display host's numeric ID in hexadecimal format.


Command:

hostid

Description:

Display file type of the file (myfiles.txt).


Command:

file myfiles.txt

Description:

Create a file (myfiles.txt) containing a text (Hello World).


Command:

echo 'Hello World' > myfiles.txt

Description:

Create a file (myfiles.txt) containing a text (Hello World).


Command:

printf 'Hello World' > myfiles.txt

Description:

Display IP address of the hostname.


Command:

hostname  -i

Description:

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

Description:

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        | 

Description:

Check the network connectivity between host (your connection) and server (Google server).


Command:

ping google.com

Description:

Find the location of source/binary file of a command (cal).


Command:

whereis cal

Description:

List the files in the bin directory.


Command:

ls /bin

Description:

List the files in the bin directory and the etc directory.


Command:

ls /bin /etc

Description:

Moves the file test.txt to the folder newrepo.


Command:

mv test.txt ./newrepo

Description:

Deletes all the lines in the test.txt containing tue word.


Command:

sed -i "/tue/d" test.txt

Description:

Show system reboot history.


Command:

last reboot

Description:

Displays the messages from the kernel ring buffer (a data structure that records messages related to the operation of the kernel).


Command:

dmesg

Description:

Display CPU information.


Command:

cat /proc/cpuinfo

Description:

Display memory information.


Command:

cat /proc/meminfo

Description:

Display PCI (Peripheral Component Interconnect) devices.


Command:

lspci -tv

Description:

Display USB devices.


Command:

lsusb –tv

Description:

Display free and used memory (-h for human readable, -m for MB, -g for GB).


Command:

free -h

Description:

Display processor related statistics.


Command:

mpstat 1

Description:

Display virtual memory statistics.


Command:

vmstat 1

Description:

Display Input / Output statistics.


Command:

iostat 1

Description:

Execute "df -h" command, showing periodic updates.


Command:

watch df -h

Description:

Display all the currently running processes on the system.


Command:

ps –ef

Description:

Display all network interfaces and IP address.


Command:

ip a

Description:

Display DNS information for domain (wikipedia.org).


Command:

dig wikipedia.org

Description:

Display the IP address details of the specified domain (wikipedia.org).


Command:

host wikipedia.org

Description:

Display listening Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP) ports and corresponding programs.


Command:

netstat -nutlp

Description:

List all installed packages.


Command:

rpm -qa

Description:

List all installed packages (CentOS).


Command:

yum list installed

Description:

Display description and summary information about package "httpd" (CentOS).


Command:

yum info httpd

Description:

Display disk usage for all files and directories in human readable format.


Command:

du -ah

Description:

Display total disk usage off the current directory.


Command:

du -sh

Description:

Change to the /etc directory.


Command:

cd /etc

Description:

List the status of all the processes along with process id and PID.


Command:

ps -A

Description:

Displays the file name of the terminal connected to standard input.


Command:

tty

Description:

Displays the contents of myfiles.txt file in octal format.


Command:

od -b myfiles.txt

Description:

Displays the contents of myfiles.txt file in character format.


Command:

od -c myfiles.txt

Description:

Displays the contents of myfiles.txt file in character format but with no offset information.


Command:

od -An -c myfiles.txt

Description:

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

Description:

Prints a 32-character (128-bit) checksum of myfiles.txt file using the MD5 algorithm.


Command:

md5sum myfiles.txt

Description:

Displays the content of myfiles.txt file.


Command:

more myfiles.txt

Description:

Prints Secure Hash Algorithm 1 (160-bit) checksum of myfiles.txt file.


Command:

sha1sum myfiles.txt

Description:

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

Description:

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

Description:

Displays a list of system services and whether they are started (on) or stopped (off) in run levels 0−6.


Command:

chkconfig --list

Description:

Power-off the system.


Command:

halt -p

Description:

Prints the details of the last login (login-name, port and last login time).


Command:

lastlog

Description:

Displays the login information (1 day ago).


Command:

lastlog -t 1

Description:

Display lastlog information for a particular user (manju).


Command:

lastlog -u manju

Description:

List all users on Linux.


Command:

cat /etc/passwd
more /etc/passwd
less /etc/passwd
getent passwd

Description:

List last 5 users on Linux.


Command:

tail -5 /etc/passwd


Description:

List first 5 users on Linux.


Command:

head -5 /etc/passwd

Description:

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."

Description:

List the password and its related details for a user (manju).


Command:

chage -l manju

Description:

Set Password Expiry Date for an user (manju).


Command:

chage -M 10 manju

Description:

Set the Account Expiry Date for an User (manju).


Command:

chage -E "2020-07-30" manju

Description:

Force the user (manju) account to be locked after 10 inactivity days.


Command:

chage -I 10 manju

Description:

Connect to an FTP server at remote server IP address "192.168.42.77".


Command:

ftp 192.168.42.77

Description:

Lists all the peers connected at various interfaces along with their MAC Addresses and IP addresses.


Command:

arp –a

Description:

Display the system's DNS domain name.


Command:

dnsdomainname

Description:

Display the name of the domain your machine belongs to.


Command:

domainname

Description:

Encode text (Hello World!) to base64.


Command:

echo 'Hello World!' | base64
Output: SGVsbG8gV29ybGQhCg==

Description:

Decode (SGVsbG8gV29ybGQhCg==) to text (Hello World!).


Command:

echo 'SGVsbG8gV29ybGQhCg==' | base64 -d
Output: Hello World!

Description:

Build font information cache files.


Command:

fc-cache -f –v

Description:

Formats text in a single line.


Command:

cat 1.txt

Einstein
Newton
Albert

fmt 1.txt

Einstein Newton Albert

Description:

Prints the route that a packet takes to reach the Google (172.217.26.206) host from the local machine.


Command:

traceroute google.com

Description:

View the contents of zipped file.


Command:

cat 1.txt

Einstein
Newton
Albert

gzip 1.txt

zcat 1.txt.gz

Einstein
Newton
Albert




Description:

Compare the contents of two zipped files (1.txt.gz, 2.txt.gz).


Command:

zdiff 1.txt.gz 2.txt.gz

Description:

List all connections.


Command:

ss | less

Description:

Filter out TCP (Transmission Control Protocol) connections.


Command:

ss -aA tcp

Description:

Filter out UDP (User Datagram Protocol) connections.


Command:

ss -aA udp

Description:

Display only listening sockets.


Command:

ss -lnt

Description:

Print process name and PID.


Command:

ss -ltp

Description:

Print summary statistics.


Command:

ss -s

Description:

Display only IPv6 connections.


Command:

ss -tl6

Description:

Display only IPv4 socket connections.


Command:

ss -tl -f inet

Description:

Display all IPv4 TCP sockets that are in connected state.


Command:

ss -t4 state established

Description:

View the memory map of a process with Process ID (3244).


Command:

pmap 3244

Description:

Find command that removes file.


Command:

apropos -r 'remove file'

Description:

Display information about the editing programs that are available on a system.


Command:

apropos editor

Description:

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

Description:

Print out a list of all environment variables.


Command:

env

Description:

Print HOME variable value.


Command:

printenv HOME

Description:

Reverse lines of a file (1.txt).


Command:

rev 1.txt

Description:

Lists the files with .txt extension.


Command:

ls -l *.txt

Description:

Print the Default shell of user.


Command:

echo $SHELL

Description:

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

Description:

Print all files and folders − similar to ls command.


Command:

echo *

Description:

Print the process ID of the current shell ($$ is the process ID of the current shell).


Command:

ps -p $$

Description:

List shells.


Command:

cat /etc/shells

Description:

List last logins of users and what happened such as "shutdown" or "crash" etc.


Command:

last

Description:

Compresses but does not deletes the original file.


Command:

bzip2 -k phy.txt

Description:

Decompresses the compressed file (phy.txt.bz2).


Command:

bzip2 -d phy.txt.bz2

Description:

Display the contents of compressed file (phy.txt.bz2).


Command:

bzcat phy.txt.bz2

Description:

Decompresses the compressed file (phy.txt.bz2).


Command:

bunzip2 phy.txt.bz2

Description:

Display current logged-in user's crontab entries.


Command:

crontab –l

Description:

Ping google.com and send the process to the background.


Command:

nohup ping google.com &

Description:

Save the ping logs to log.txt.


Command:

nohup ping google.com > log.txt &

Description:

Display the contents of /home.


Command:

ls -la /home

Description:

Power-off the machine after 2 minutes.


Command:

sudo shutdown 2

Description:

Cancel the shutdown process.


Command:

shutdown -c

Description:

Display the contents of the file (36.txt) one page after the other.


Command:

pr 36.txt

Description:

Display all current terminal settings.


Command:

stty –a

Description:

List files one per line.


Command:

ls -1

Description:

Outputs a string (John) repeatedly until killed.


Command:

yes John

Description:

List files and directories in the current directory (one per line) with details.


Command:

vdir

Description:

Print when the system was booted.


Command:

who -b

Description:

Display a list of currently mounted file systems.


Command:

findmnt

Description:

List IP addresses and network interfaces.


Command:

ip addr show

Description:

List active (listening) ports.


Command:

netstat -pnltu

Description:

Display systemd, kernel and journal logs.


Command:

Journalctl

Description:

Display the status of network service.


Command:

sudo systemctl status network

Description:

Start the network service.


Command:

sudo systemctl start network

Description:

Stop the network service.


Command:

sudo systemctl stop network

Description:

Display the current state of Booleans.


Command:

sestatus -b

Description:

Reports whether SELinux is enforcing, permissive or disabled.


Command:

getenforce

Description:

Display the current status of the SELinux that is running on your system.


Command:

sestatus

Description:

Display full listing of processes on your system.


Command:

ps –aef

Description:

Display System Activity Report.


Command:

sar

Description:

Report the resource limit of the current user.


Command:

ulimit

Description:

Report all the resource limits for the current user.


Command:

ulimit -a

Description:

Check the maximum stack size of the current user.


Command:

ulimit –s

Description:

Check out the max scheduling priority of the current user.


Command:

ulimit –e

Description:

Display the maximum number of user processes.


Command:

ulimit –u

Description:

Check out the size of virtual memory.


Command:

ulimit –v

Description:

Check out how many file descriptors a process can have.


Command:

ulimit –n

Description:

Display the in-depth information on the limits.conf configuration file.


Command:

man limits.conf

Description:

Display the sar version.


Command:

sar -V

Description:

Report CPU details total 5 times with the interval of 2 seconds.


Command:

sar -u 2 5

Description:

Report about network interface, network speed, IPV4, TCPV4, ICMPV4 network traffic and errors.


Command:

sar -n DEV 1 3 | egrep -v lo

Description:

Report details about the process, kernel thread, i-node, and the file tables.


Command:

sar -v 1 3

Description:

Report statistics about swapping.


Command:

sar -S 1 3

Description:

Report statistics about swapping.


Command:

sar -S 1 3

Description:

Report details about I/O operations like transaction per second, read per second, write per second.


Command:

sar -b 1 3

Description:

Display the status of the firewalld.


Command:

sudo systemctl status firewalld

Description:

Start the firewalld service.


Command:

sudo systemctl start firewalld

Description:

Start the graphical firewall configuration tool.


Command:

firewall-config

Description:

List all zones.


Command:

firewall-cmd --list-all-zones

Description:

Check the currently set default zone.


Command:

firewall-cmd --get-default-zone

Description:

Display currently allowed service on your system.


Command:

firewall-cmd --list-services

Description:

List the ports that are open on your system.


Command:

firewall-cmd --list-ports

Description:

List services that are allowed for the public zone.


Command:

firewall-cmd --zone=work --list-services

Description:

Provides information about the route that Internet traffic takes between the local system and a remote host (google.com).


Command:

mtr --report google.com

Description:

Install Samba (CentOS).


Command:

sudo yum install samba

Description:

Add Samba service to firewalld.


Command:

sudo firewall-cmd --add-service samba –permanent

Description:

Create a zip file (q.zip).


Command:

zip q.zip q.txt

Description:

Unzip a zip file (q.zip).


Command:

unzip q.zip

Description:

Display the names of the files with the word (Einstein) present in it.


Command:

zgrep -l "Einstein" *

Description:

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

Description:

Test the route and connection quality of traffic to the destination host google.com.


Command:

mtr google.com

Description:

Display IP routing table of a Linux system.


Command:

route

Description:

View all your network devices.


Command:

nmcli dev status

Description:

Check network connections on your system.


Command:

nmcli con show

Description:

List all TCP ports (sockets) that are open on a server.


Command:

ss –ta

Description:

Display all active TCP connections together with their timers.


Command:

ss -to

Description:

Check Bash Aliases in Linux.


Command:

type -a alias

Description:

Print yesterday's date and time.


Command:

echo "Yesterday = $(date -d "Yesterday")"

Description:

Print Tomorrow date and time.


Command:

echo "tomorrow = $(date -d "tomorrow")"

Description:

Find what is the date and time before 10 days from now.


Command:

echo "Before 10 days = $(date -d "tomorrow -10 days")"

Description:

Find last month and next month.


Command:

echo "Last month = $(date -d "last month" "%B")"
echo "Next month = $(date -d "next month" "%B")"

Description:

Find last year and next year.


Command:

echo "Last Year = $(date -d "last year" "+%Y")"
echo "Next Year = $(date -d "next year" "+%Y")"

Description:

Get the number of inodes of files in a directory (root directory).


Command:

ls -lai /

Description:

Get the total number of inodes in the root directory.


Command:

sudo du --inode /

Description:

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 )'

Description:

List the numerical port numbers.


Command:

ss -tn src :80 or src :443

Description:

Install PuTTy on CentOS.


Command:

sudo yum install putty

Description:

Watch TCP and UDP Open Ports in Real-Time.


Command:

sudo watch netstat -tulpn

Description:

Watch TCP and UDP Open Ports in Real-Time.


Command:

sudo watch ss –tulpn

Description:

Timeout a ping command after 5 seconds.


Command:

timeout 5s ping google.com

Description:

Install curl on CentOS.


Command:

yum install curl

Description:

List all UDP Connections.


Command:

ss –ua

Description:

List all Listening UDP Connections.


Command:

ss –lu

Description:

Display the Process IDs related to socket connections.


Command:

ss -p

Description:

Display IPv4 and IPv6 Socket Connections.


Command:

ss -4

Description:

Display IPv6 connections.


Command:

ss -6

Description:

Filter Connections by Port Number.


Command:

ss -at '( dport = :22 or sport = :22 )'

Description:

Show Difference between Two Files (phy.txt and score.txt).


Command:

sdiff phy.txt score.txt

Description:

Delete or clear all the entries from bash history.


Command:

history -c

Description:

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



Description:

Displays user accounts.


Command:

lslogins –u

Description:

List all loaded services on your system (whether active; running, exited or failed).


Command:

systemctl list-units --type=service

Description:

List all loaded services on your system (whether active; running, exited or failed).


Command:

systemctl --type=service

Description:

List all loaded but active services.


Command:

systemctl list-units --type=service --state=active

Description:

List all loaded but active services.


Command:

systemctl --type=service --state=active

Description:

List all running services (i.e., all loaded and actively running services).


Command:

systemctl list-units --type=service --state=running

Description:

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



Description:

Find out your DNS Server IP address.


Command:

cat /etc/resolv.conf

Description:

Find out your DNS Server IP address.


Command:

less /etc/resolv.conf

Description:

Monitor mount, unmount, remount and move actions on a directory (i.e., on /mnt/test).


Command:

findmnt --poll --mountpoint /mnt/test

Description:

Check Linux Server Uptime.


Command:

uptime -p

Description:

Check Linux Server Starting Time.


Command:

uptime –s

Description:

Display uptime's version information.


Command:

uptime –h

Description:

Count the number of times "Justin" appears in the file (score.txt).


Command:

grep -o -i Justin score.txt | wc –l

Description:

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


Description:

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



Description:

Decompose an integer (10) into prime factors.


Command:

factor 10

Description:

Display every active process on a Linux system.


Command:

ps -e

Description:

Display User Running Processes.


Command:

ps -x

Description:

Display a user's processes by user name (manju).


Command:

ps -fU manju

Description:

Display a user's processes by real user ID (RUID).


Command:

ps -fu 1000

Description:

Display every process running with root user privileges (real and effective ID).


Command:

ps -U root -u root

Description:

Install Nix Package Manager in Linux.


Command:

sh <(curl https://nixos.org/nix/install) --daemon

Description:

View System Locale in Linux.


Command:

locale

Description:

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



Description:

Re-execute previously used command.


Command:

!sud

Description:

Re-execute previously used command.


Command:

!sudo

Description:

Generate a compact list of all Linux user accounts on the system.


Command:

cut -d: -f1 < /etc/passwd | sort | xargs

Description:

View multiple compressed files (phy.txt.gz and myfiles.txt.gz).


Command:

zcat phy.txt.gz myfiles.txt.gz

Description:

Find all php files in a directory.


Command:

find . -type f -name "*.php"

Description:

Find all the files whose permissions are 777.


Command:

find . -type f -perm 0777 -print

Description:

Find all the files without permission 777.


Command:

find / -type f ! -perm 777

Description:

Find all SGID set files.


Command:

find / -perm /g=s

Description:

Find all Read-Only files.


Command:

find / -perm /u=r

Description:

Find all Executable files.


Command:

find / -perm /a=x

Description:

Find and remove phy.txt File.


Command:

find . -type f -name "phy.txt" -exec rm -f {} \;

Description:

To find and remove multiple .txt files.


Command:

find . -type f -name "*.txt" -exec rm -f {} \;

Description:

To find and remove multiple .mp3 files.


Command:

find . -type f -name "*.mp3" -exec rm -f {} \;

Description:

Find all Empty Directories.


Command:

find /tmp -type d -empty

Description:

File all Hidden Files.


Command:

find /tmp -type f -name ".*"

Description:

Find Last 50 Days Modified Files.


Command:

find / -mtime 50

Description:

Find Last 50 Days Accessed Files.


Command:

find / -atime 50

Description:

Find Changed Files in Last 1 Hour.


Command:

find / -cmin -60

Description:

Find Modified Files in Last 1 Hour.


Command:

find / -mmin -60

Description:

Find Accessed Files in Last 1 Hour.


Command:

find / -amin -60

Description:

Find all 50 MB files.


Command:

find / -size 50M

Description:

Find and Delete 100 MB Files.


Command:

find / -type f -size +100M -exec rm -f {} \;

Description:

Find all .mp3 files with more than 10 MB and delete them.


Command:

find / -type f -name *.mp3 -size +10M -exec rm {} \;

Description:

Find Linux Open File Limit.


Command:

cat /proc/sys/fs/file-max

Description:

Check Hard Limit in Linux.


Command:

ulimit -Hn

Description:

Check Soft Limits in Linux.


Command:

ulimit -Sn

Description:

Display the current time and date on your system.


Command:

timedatectl status

Description:

View all available timezones.


Command:

timedatectl list-timezones

Description:

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.*"

Description:

Set your local timezone in Linux.


Command:

timedatectl set-timezone "Asia/Kolkata"

Description:

View a summary of swap space usage by device.


Command:

swapon --summary

Description:

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


Description:

List files and their allocated sizes in blocks.


Command:

dir -shl

Description:

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


Description:

Print all .jpeg files.


Command:

echo *.jpeg


a=$(pwd)
echo "Current working directory is : $a"

/home/manju


Description:

Break down a word (linux) into individual letters.


Command:

echo 'linux' | fold -w1

Description:

Break down a word (linux) into individual letters.


Command:

echo 'linux' | fold -w1

Description:

Output the files with respect of the user (root) owned files in the current directory.


Command:

find . -user root

Description:

Trace a command (pwd) execution.


Command:

strace pwd

Description:

Display specific User (manju) process details.


Command:

top -u manju

Description:

Find Out Linux Kernel Version.


Command:

uname –or

Description:

Print linux system information.


Command:

uname -a

Description:

Display some of your system information including the Linux kernel version.


Command:

cat /proc/version

Description:

Find Out Linux Distribution Name and Release Version.


Command:

cat /etc/centos-release

Description:

Find Out Linux Distribution Name and Release Version.


Command:

fuser .

Description:

Determine which processes are accessing your ~.bashrc file.


Command:

fuser -v -m .bashrc

Description:

Displays all the possible signals that can be used with the fuser tool.


Command:

sudo fuser --list-signals

Description:

Sends the HUP signal to all processes that have your /boot directory open.


Command:

sudo fuser -k -HUP /boot

Description:

Shutdown the system at 23:55 today.


Command:

echo "shutdown -h now" | at -m 23:55

Description:

Run updatedb at 23:55 today.


Command:

echo "updatedb" | at -m 23.55

Description:

Display the top 15 processes sorted by memory use in descending order.


Command:

top -b -o +%MEM | head -n 22

Description:

Redirect the output to a file (report.txt) for later inspection.


Command:

top -b -o +%MEM | head -n 22 > report.txt

Description:

Check Top Processes sorted by RAM or CPU Usage in Linux.


Command:

ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head

Description:

Find all files in the current directory with .sh and .txt file extensions.


Command:

find . -type f \( -name "*.sh" -o -name "*.txt" \)

Description:

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" \)

Description:

Delete repeated lines in the file (myfiles.txt).


Command:

uniq myfiles.txt

Description:

Open a file (myfiles.txt).


Command:

xdg-open myfiles.txt

Description:

Display the files in the current folder that start with the letter "m".


Command:

echo m*

Description:

Print your home folder path.


Command:

echo ~

Description:

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

Description:

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 

Description:

Identifies whether the "cat" command is a shell built-in command, subroutine, alias, or keyword.


Command:

type cat

Description:

Find files edited more than 3 days ago.


Command:

find . -type f -mtime +3

Description:

Find files edited in the last 24 hours.


Command:

find . -type f -mtime -1

Description:

Find files that have more than 100 characters (bytes) in them.


Command:

find . -type f -size +100c

Description:

Find files bigger than 100 KB but smaller than 1 MB.


Command:

find . -type f -size +100k -size -1M

Description:

Deletes all the files edited in the last 24 hours.


Command:

find . -type f -mtime -1 -delete

Description:

List all files including hidden files.


Command:

ls -a

Description:

List Files and Directories with "/" Character at the End.


Command:

ls -F

Description:

List Files in Reverse Order.


Command:

ls -r

Description:

Sort Files by File Size.


Command:

ls -lS

Description:

List Files with an inode number.


Command:

ls -i

Description:

Check the version of the ls command.


Command:

ls --version

Description:

List files under directory /tmp.


Command:

ls -l /tmp

Description:

Display UID and GID of files and directories.


Command:

ls -n

Description:

Find all 30 MB files.


Command:

find / -size 30M

Description:

Find files with sizes between 100 - 200MB.


Command:

find / -size +100M -size -200M

Description:

List directories larger than 20 KB.


Command:

find / -type d -size +20k

Description:

Find empty files and directories.


Command:

find ./ -type f -size 0

Description:

List files modified within the last 17 hours.


Command:

find . -mtime -17 -type f 

Description:

*** List directories modified within the last 10 days.***


Command:

find . -mtime -10 -type d 

Description:

List all files modified between 6 and 15 days ago in the home directory.


Command:

find /home -type f -mtime +6 -mtime -15

Description:

Display files with permission 777.


Command:

find -perm 777

Description:

List files owned by a user (manju).


Command:

find /home -user manju

Description:

Find all text files owned by user "manju".


Command:

find /home -user manju -iname "*.txt"

Description:

Find and list files and directories together with their permissions.


Command:

find -name "*.conf" | ls -l

Description:

List directories only.


Command:

ls -d */

Description:

List multiple files on a single line.


Command:

ls --format=comma

Description:

View the process of a specific user "manju".


Command:

ps -u manju

Description:

Execute a previous command starting with a specific letter "c".


Command:

!c

Description:

Display BIOS information (You need elevated permissions to run this).


Command:

dmidecode -t 0

Description:

Display CPU information (You need elevated permissions to run this).


Command:

dmidecode -t 4

Description:

View all the system logs.


Command:

gnome-system-log

Description:

Identify SSH Client Version.


Command:

ssh -V

Description:

Display total connect time of users.


Command:

ac –d

Description:

Display connect time for all the users.


Command:

ac -p

Description:

Diaplay connect time report for a specific user "manju".


Command:

ac -d manju

Description:

Display the modules compiled inside Apache.


Command:

httpd -l 

Description:

*** View Processes Owned by Current User.***


Command:

ps U $USER

Description:

Display the information about the filesystem Type.


Command:

df -Tha

Description:

Display Active Connections with Process ID and Program Name.


Command:

netstat -tap

Description:

Display RAW network statistics.


Command:

netstat --statistics --raw

Description:

Display all .txt files including its individual permission.


Command:

ls -al *.txt

Description:

View system defined cron jobs.


Command:

cat /etc/crontab

Description:

Check which ports are in listening in Linux Server.


Command:

netstat --listen

Description:

Check Inodes on File system.


Command:

df -i /dev/sda1

Description:

Find Inode number of File (myfiles.txt).


Command:

ls -il myfiles.txt

Description:

Check ACL (Access control list) configured on a file (myfiles.txt).


Command:

getfacl myfiles.txt

Description:

Check information of disk usage of files and directories on a machine.


Command:

du -sh /var/log/*

Description:

Display dependencies of the "cp" command.


Command:

ldd /bin/cp

Description:

Display dependencies of the "cp" command with details.


Command:

ldd -v /bin/cp

Description:

Display unused direct dependencies of the "cp" command.


Command:

ldd -u /bin/cp

Description:

Check all installed packages of ftp.


Command:

rpm –qa | grep ftp

Description:

Find files in the /home directory which were modified more than 120 days ago.


Command:

find /home -mtime +120

Description:

Find files in the /var directory that have not been accessed in the last 90 days.


Command:

find /var -atime -90

Description:

Search for core files in the entire directory tree and delete them as found without prompting for confirmation.


Command:

find / -name core -exec rm {} \;

Description:

Check current run level of a Linux server.


Command:

who –r

Description:

Display the content of file (myfiles.txt).


Command:

awk '{print}' myfiles.txt

Description:

Create hard-link to myfiles.txt.


Command:

ln myfiles.txt hardF1

Description:

Check content of the hard link - hardF1.


Command:

cat hardF1

Description:

Create Soft-link to myfiles.txt.


Command:

ln myfiles.txt softF1

Description:

Check content of the soft link - softF1.


Command:

cat softF1

Description:

Display information about the process with process ID – 13.


Command:

ps -p 13

Description:

Set the file size limit to 51,200 bytes.


Command:

ulimit -f 100

Description:

Find out what kernel modules are currently loaded.


Command:

lsmod

Description:

Install php version 7.2.


Command:

sudo yum install php

Description:

Run a PHP statement from the command line without creating a file.


Command:

php -r 'echo "Hello World\r\n";'

Description:

Start a PHP interactive shell.


Command:

php -a


Papers


Books:


important-linux-commands-you-should-know's People

Contributors

manjunath5496 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.