INFORMATICS

The Best

list of the most commonly used Linux commands

Звезда не активнаЗвезда не активнаЗвезда не активнаЗвезда не активнаЗвезда не активна
 

This article provides a list of the most commonly used Linux commands with their examples for easy learning.

It's important to note that some commands are "distribution-based" - they can only be found on certain distributions.

Content:

adduser agetty alias anacron apropos apt apt-get aptitude arch arp
at atq atrm awk batch basename bc bg bzip2 cal
cat chgrp chmod chown cksum clear cmp comm cp date
dd df diff dir dmidecode du echo eject env exit
expr factor find free grep groups gzip gunzip head history
hostname hostnamectl hwclock hwinfo id ifconfig ionice iostat ip iptables
iw iwlist kill killall kmod last ln locate login ls
lshw lscpu lsof lsusb man md5sum mkdir more mv nano
nc netstat nice nmap nproc openssl passwd pidof ping ps
pstree pwd rdiff-backup reboot rename rm rmdir scp pstree pwd
rdiff-backup reboot rename rm rmdir scp shutdown sleep sort split
ssh stat su sudo sum tac tail talk tar tee
time top touch tr uname uniq uptime user vi w
wall watch wc wget whatis which who whereis xargs yes
zdiff zip zz

 

 

adduser/addgroup command
The adduser and addgroup commands are used to add a user and group to the system according to the default configuration specified in the /etc/adduser.conf file.

adduser username
addgroup group_name

 

agetty command
A program that manages physical or virtual terminals. As soon as it detects a connection, it opens the tty port, asks for a username, and invokes the /bin/login command.

Agetty is a Linux getty replacement:

agetty -L 9600 ttyS1 vt100

 

alias command
Built-in command shell to create aliases (shortcuts) for the Linux command on the system. This is useful for creating new custom commands from existing Shell/Linux commands (including options):

alias home = 'cd /home/user'

the command will create an alias called home for the /home/user directory, so when you type home at the terminal prompt it puts you in the /home/user directory

 

anacron command
A Linux tool used to run commands periodically at a frequency defined in days, weeks, and months.

Unlike the cron command, it assumes that the system will not run continuously, so if a scheduled task is to run when the system is turned off, it will run after the device is turned on.

 

apropos command
Used to find and display a short help page for a command or program

apropos adduser

 

apt command
Relatively new higher level package manager for Debian/Ubuntu systems

apt update

 

apt-get command
Package manager for Debian/Ubuntu. Used to install, remove and update both software packages and the system as a whole

apt-get update

 

aptitude command
A powerful interface to the Debian/Linux package management system. Like apt-get and apt, it can be used to install, remove, and update both software packages and the system as a whole.

 

arch command
A simple command to display the machine's architecture or hardware name (similar to uname -m ).

 

arp command
A protocol that displays the IP and MAC addresses of neighbor nodes in an IPv4 network.

arp-scan --interface=eth0 --localnet

 

at command
The command is used to schedule tasks to be performed in the future. This is an alternative to cron and anacron, however it runs a task once in a certain future without editing any configuration files:

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

 

atq command
The atq command is used to view jobs in the command queue.

 

atrm command
Used to withdraw/delete jobs (indicated by their job number) from the command queue.

atrm 2

 

awk command
A powerful programming language designed for word processing and commonly used as a data mining and reporting tool

awk '// {print}' /etc/hosts

 

batch command
Used to schedule tasks to run in the future, similar to the at command.

 

basename command
Prints the filename without preceding directory names.

 

bc command
CLI calculator.

echo 11.05 + 17.02 | bc

 

bg command
Used to send a process to the background.

 

bzip2 command
Used to compress or decompress files.

bzip2 -z filename #Compress
bzip2 -d filename.bz2 #Decompress

 

cal command
Displays a calendar

 

cat command
Used to view the contents of a file or concatenate files or data.

cat file.txt

 

chgrp command
Used to change group ownership of a file. Specify the new group name as the first argument and the file name as the second argument.

chgrp www-data-users.txt

 

chmod command
The chmod command is used to change or update the permissions of a file.

chmod +x file.txt

 

chown command
Changes or updates user and group permissions on a file or directory.

chmod -R www-data: www-data /var/www/html

 

cksum command
Used to display the CRC checksum and number of bytes of a file

cksum file.txt

 

clear command
Allows you to clear the terminal screen.

 

cmp command
Performs a byte-by-byte comparison of two files.

cmp file1 file2

 

comm command
Used to compare two sorted files in turn.

comm file1 file2

 

cp command
Used to copy files and directories from one location to another.

cp /home/folder1/file1 /home/folder2/

 

date command
Displays or sets the system date and time.

date
date --set="9 Dec 2017 21:00:00"


dd command
Used to copy files, convert and format them according to the flags specified on the command line. It can strip headers, extract parts of binary files, and so on.

dd if=/home/folder1/file.txt of=/dev/sdc1 bs=512M; sync

 

df command
Used to display the used file system space.

df-h

 

diff command
Used to compare two files line by line. Can also be used to determine the difference between two directories

diff file1 file2

 

dir command
Works like the ls command, it lists the contents of a directory.

 

dmidecode command
A tool to extract information about the hardware of any Linux system. It displays the contents of the computer's DMI table (SMBIOS) in an easy-to-read format for easy retrieval.

 

du command
Used to display the disk space of files in a directory.

du /home/

 

echo command
Displays the specified text.

 

eject command
Used to eject removable media.

 

env command
Displays environment variables.

 

exit command
Used to exit the shell.

 

expr command
Used to evaluate an expression.

expr 20 + 30

 

factor command
Used to display prime coefficients of a number.

 

find command
Allows you to search for files in a directory, as well as in its subdirectories.

 

free command
Shows system RAM and SWAP usage

 

grep command
Searches files for the given pattern.

grep 'text' file.txt

 

groups command
Displays the names of the groups the user is a part of.

 

gzip command
Allows you to compress files into .gz format

gzip file.txt
cat file1 file2 | gzip > file.gz

 

gunzip command
Recovers files compressed with the gzip command.

 

head command
Used to display the first lines (10 lines by default) of the specified file.

head /home/file.txt

 

history command
Used to display previously used commands or to get information about a command the user is executing.

 

hostname command
Used to display or set the Linux system hostname.

 

hostnamectl command
Manages the system host name under systemd and is used to display or change the system host name and any related settings.

hostnamectl set-hostname NAME

 

hwclock command
A tool to manage the system hardware clock.

hwclock --set --date 07/27/2017

 

hwininfo command
Used to test hardware present by Linux.

 

command id
Displays user or group information for the current or specified username.

 

ifconfig command
The ifconfig command is used to configure how to view and manage the network interfaces of Linux systems.

sudo ifconfig eth0 up
sudo ifconfig eth0 down
sudo ifconfig eth0 192.168.1.1

 

ionice command
Used to specify or view the scheduled class and process priority.

 

iostat command
Used to display CPU and IO statistics for devices and partitions.

 

ip command
Used to display, manage routing, devices, policy routing, and tunnels. Replacing ifconfig.

ip addr add 192.168.1.1 dev eth0

 

iptables command
Terminal-based firewall to control incoming and outgoing traffic through a set of custom table rules.

iptables -A INPUT -s xxx.xxx.xxx.xxx -j DROP

 

iw command
Used to manage wireless devices and their configuration.

 

iwlist command
Displays detailed wireless information from the wireless interface.

 

kill command
Used to kill a process using its PID.

 

killall command
Used to kill a process by its name.

 

kmod command
Used to manage Linux kernel modules.

 

command last
Displays a list of the most recently registered users.

 

ln command
Used to create a symbolic link.

ln -s /usr/bin/lscpu cpuinfo

 

locate command
Used to search for a file by name.

 

login command
Used to create a new session with the system. You will be prompted for a username and password to log in.

 

ls command
Used to display the contents of a directory. analog dir.

 

lsw command
It is a tool for obtaining detailed information about the hardware configuration of a machine.

 

lscpu command
Displays information about the CPU architecture.


lsof command
Displays files opened by processes. To view files opened by a specific user's processes:

lsof -u username

lsusb command
Shows information about the USB buses in the system and the devices connected to them.

 

man command
Used to display help for a command or program.

 

md5sum command
Calculates the MD5 of the specified file

 

mkdir command
Used to create one or more directories.

 

more command
Allows you to view long text files one screen at a time.

 

mv command
Used to rename or move files or directories.

 

nano command
Small, free and handy text editor for Linux.

 

nc/netcat command
Used to perform an operation related to TCP, UDP sockets, such as opening TCP connections, sending UDP packets, listening or port scanning. The below command will help us to know if port 22 is open on host 192.168.1.1.

nc -zv 192.168.1.1 22

 

netstat command
Displays information about the network subsystem (network connections, routing tables, interface statistics, masquerade connections, and multicast memberships).

 

nice command
Used to display or change the nice priority value. Executes a command with a changed priority. The nice priority (integer) of the process is used by the OS kernel process scheduler when allocating processor time between processes. The following command starts the tar process by setting the nice value to 10:

nice -10 tar -czf home.tar.bz2 /home/*

 

nmap command
A powerful tool for open scanning and security checks. Designed for quick scanning of both large networks and individual nodes. The following example will check open ports on all hosts on the specified network:

nmap -sV 192.168.1.0/24

 

nproc command
Shows the number of processor cores used to process the process. The output may show less than what is available in the system.

 

openssl command
Command line tool for using various cryptographic operations of the OpenSSL library. The example below will create an archive of all files in the current directory and encrypt the contents of the archive file:

tar-czf-* | openssl enc -e -aes256 -out backup.tar.gz

 

passwd command
Used to create or update passwords for user accounts.

 

pidof command
Displays the process ID of the running program or command.

 

ping command
Used to determine connectivity between network nodes.

 

ps command
Shows information about active processes running on the system. The example below will show the top 10 processes consuming the most RAM and CPU.

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

 

pstree command
Displays running processes in a tree view.

 

pwd command
Displays the name of the current/working directory.

 

rdiff backup command
Local and remote incremental backup script written in Python.

rdiff-backup /home/server.backup


reboot command
Used to stop, shutdown, or reboot a node.

 

rename command
Used to rename one or more files. The above example renames all txt files in a folder to html.

rename 's/\.txt$/\.html/' *.txt

 

rm command
Used to delete files or directories.

rm file1
rm -rf my-files

 

rmdir command
Allows you to remove empty directories.

 

scp command
Allows you to securely copy files between nodes on a network.

scp ~/names.txt Этот адрес электронной почты защищён от спам-ботов. У вас должен быть включен JavaScript для просмотра..1.1:/root/names.txt

 

shutdown command
Sets the time during which the system will be turned off.

 

sleep command
Used to delay or pause a command for a specified amount of time.

check.sh; sleep5; sudo apt update

 

sort command
Used to sort lines of text in specified files.

 

split command
Used to split a large file into smaller pieces.

 

ssh command
An application for remote access and execution of commands on a remote computer.

ssh Этот адрес электронной почты защищён от спам-ботов. У вас должен быть включен JavaScript для просмотра..1.1

 

stat command
Used to display the status of a file or file system.

 

su command
Used to switch user or superuser.

 

sudo command
Allows a system user to run a command as root.

 

sum command
Used to display the checksum and number of blocks for each specified file on the command line.

 

tac command
Merges and displays files in reverse order.

 

tail command
Used to display the last 10 lines of a file.

 

talk command
Used to communicate with another user of the system or network. To talk to a user on the same computer, use your login name to talk to a user on another computer using user@host.

 

tar command
Utility for archiving and unzipping files.

tar -xvzf filename.tar.gz

 

tee command
Writes the output of a command to a file.

 

time command
Starts programs and summarizes system resource usage.

time wc /etc/hosts

 

top command
Displays all processes on the system with RAM and CPU usage and provides a dynamic real-time view.

 

touch command
Changes the timestamps of a file. It can also be used to create a file.

touch file.txt

 

tr command
Used to change or remove characters from stdin and write the result to stdout.

 

uname command
Displays system information such as operating system, host kernel name, version and release, etc.

 

uniq command
Displays or skips duplicate lines from input or output. To specify the number of occurrences of a string, use the -c option.

 

uptime command
Displays how long the system has been running, the number of registered users and the average system load.

 

user command
Shows the usernames of the users who are currently logged in.

 

vim/vi command
Text editor for Unix-like operating systems.

 

w command
Displays system uptime, loads averages and information about users currently on the machine and their processes.

 

wall command
Used to display a message to all system users.

 

watch command
Runs the program repeatedly while its output is displayed in full screen mode. It can also be used to view changes to a file or directory. The following example shows how to view the contents of a directory:

watch -d ls -l

 

wc command
Used to display newline, word, and byte for each specified file, and the total for many files.

 

wget command
A utility used to download files from the Internet in non-interactive mode.

 

whatis command
Performs searches and displays quick or online command guides.

 

which command
Displays the absolute path(s) of files (or possibly links) that will be executed in the current environment.

 

who command
Shows information about users who are currently logged in.

 

whereis command
Helps us find binary, source files for commands.

 

xargs command
A utility for reading elements from standard input separated by spaces (protected by double or single quotes or backslashes) or other characters, and executes the entered command.

 

command yes
Used to display a line multiple times until it is terminated or killed with Ctrl+C.

 

zcmp / zdiff command
Utilities used to compare compressed files.

 

zip command
Utility for archiving and unzipping files.

 

command zz
It is an alias for the fasd command line tool, which provides fast file and directory access on Linux. It is used to quickly and interactively enter cd into a previously accessible directory.

Search