Important and must known commands in Linux-Updated

We have listed the important Linux commands and their use cases in this blog. As we all know there are nearly 1000 other commands in Linux you can check further details of commands using the official documentation or the man page in Linux.

As this blog covers commands for beginners I recommended you test all these commands in your terminal and get the relevant output.

This command is used to display a list of files in a human-readable format. we need to provide the -l flag in order to provide a long list format.

ls -l

-rwxr-xr– 1 root root 0 Feb 28 21:56 file
drwxr-xr-x 2 root root 4096 Mar 31 12:49 folder

#command to see all the hidden files in a directory#

ls -lad .*

drwxr-xr-x 27 root root 4096 Apr 6 23:50 .
-rw——- 1 root root 53589 Apr 6 23:50 .bash_history
-rw-r–r– 1 root root 220 Jan 13 15:26 .bash_logout

cd-Change Directories.

This command is used to change the current working directory of a user.
#command used to switch to the home directory

cd /home

#command used to switch to the previous working directory

cd ..

cp -Copies a file or directory

This command is used to copy files and directories
#Command to copy files from one location to another cp file name followed by destination location

cp filename.txt /home/linuxlearninghub/Downloads

#Command to copy contents inside the folder from one location to another. This command will copy the folder and contents inside it recursively to another location

cp -R foldername /home/linuxlearninghub/Downloads

mv -move files/folders

This command is used to move the contents from one location to another.
#command to move files and folders from one location to another. commonly used to move folders from their current location to Downloads#

mv foldername /home/linuxlearninghub/Downloads

#pass a -i flag along mv command . Enters interactive mode; CLI asks before overwriting files if the destination consists of the folder with the same.

mv -i foldername /home/linuxlearninghub/Downloads

pwd – present working directory

This command is used to view the current working directory in Linux.
## pwd command used to view the current working directory ##

pwd
/home/linuxlearninghub/Downloads/folder

cat – Display the Contents of a File to the Terminal Output.

This command is used to read, modify or concatenate text files. It also displays file contents.

cat sample.txt
This is a test file

#command to copy the contents of file1 to file 2#

cat fie1.txt > file2.txt

rm -remove a file/folder

This command is used to delete the files and folders in Linux.
#command used to delete a particular file in Linux #

root@ubundu:~# rm filename

#command used to delete the files and contents inside a directory recursively

root@ubundu:~# rm -rf foldername

mkdir -create a directory

This command is used to make a directory in Linux.
#Command to make a directory in the current working directory#

root@ubundu:~# mkdir directoryname

df- view free disk information

This command is used to see the current free disk space in the Linux system.
#command to view the free disk space in human-readable format

root@ubundu:~# df -h

du – view disk usage

This command is used to view the disk usage of a file or folder in Linux.
command used to see the disk usage of a specific folder in Linux

du -sh /home/linuxlearninghub/Downloads

11 G /home/linuxlearninghub/Downloads

command used to see the disk usage of entire files and folder’s inside a directory

root@ubundu:~# du -sch ./*

find command

This command is used to find a particular file or folder inside the Linux file system.
command used to find the particular file inside the whole /directory -name is used

root@ubundu:~# find / -name filename.txt

command to find a partiuclar folder inside the / directory #

root@ubundu:~# find / type -d -name Downloads

grep- Search Files and Directories for Strings or Regular Expressions.

This command is used to search for a particular string/ word in a text file. This command is used to find a particular file or folder inside the linux file system.grep searches for PATTERNS in each FILE. PATTERNS is one or more patterns separated by newline characters, and grep prints each line that matches a pattern. Typically PATTERNS should be quoted when grep is used in a shell command

#command used to grep a particular string inside an error log#

grep ‘stringname’ /var/log/error.log

command to grep a particular word inside the current working directory. This command will search all the files and return the matching files containing the string.#

grep -irl ‘dbname=mysql’

echo command

This command is used to display a line of text
echo command to prints a line of text#

echo ‘This is linuxlearninghub.com’
This is linuxlearninghub.com

Command used to redirect output to a sample txt file

echo ‘This is linuxlearninghub.com’ > sample.txt

chmod- Change Access Controls for Files and Directories.

This command is used to change the permission of files and directories in Linux.
command used to change the file permission to 644

root@ubundu:~# chmod 644 filename

command used to change the permssion of entire files and folders in a directory in Linux

chmod -R 655 directoryname

chown -change ownership

This command is used to change the ownership of files and folders in the Linux system.

##command used to change the ownership of group and owner to root:root of a file ##

root@ubundu:~# chown root: root filename

command used to change the ownership of group and owner to root:root of entire files and folders inside a directory

root@ubundu:~# chown -R root:root directory name

top command

This command is used to display the current Linux process The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel.

# command used to view the entire running process in the system #

root@ubundu:~# top

command used to display only the running process of a specific user in the system

top -u username

w command

This command is used Show who is logged on and what they are doing it displays information about the users currently on the machine, and their processes. The header shows, in this order, the current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.

#command used to display the who is logged in and what they are doing #

root@ubundu:~# w

Command used to exclude the header


~# w -h

ssh command

This command is to log into the remote machine and execute commands. It uses ssh protocol which allows it to provide secure encrypted communications between two untrusted hosts over an insecure network. This command will prompt you to enter the password of the remote machine.

#Command used to log into a remote network whoes username is root with default port 22#

ssh root@<ipaddress>

Command used to log into a remote network whose username is root with custom port 5522

ssh root@<ipaddress> -p 5522

su – switch user

This command is used to switch users in Linux system.

#command used to switch user #

root@ubundu:~# su <username>

uptime command

This command is used to show how long your system is running and the number of users who are currently logged in and also displays the load average on the system for 15, and 15 minutes intervals.

root@ubundu:~# uptime

08:24:54 up 712 days, 17:20, 5 users, load average: 0.20, 1.00, 0.70

ps: Displays information about running processes

The “ps” command is used to display information about running processes on a Linux system. When you run the “ps” command without any arguments, it will display a list of the processes that are currently running under your user account.

root@ubuntu:~# ps

You can use the “-e” option to show all processes running on the system, or the “-u” option to show the processes owned by a specific user. You can also use the “-f” option to show the full command line that was used to start the process, rather than just the command name.

Systemctl: Control system services

systemctl is a command used to control system services in Linux. It can start, stop, restart, enable, or disable services. For example, “systemctl start apache2” starts the Apache web server.

systemctl start apache2 or systemctl stop apache2

Ifconfig command

ifconfig is a command-line tool used to configure network interfaces in Linux. It allows you to manage IP addresses, set up network parameters, and control network interfaces.

ifconfig eth0 up: This command brings up the network interface “eth0”, enabling it to send and receive network traffic. It activates the interface, allowing it to communicate with other devices on the network.

ifconfig eth0 down: Conversely, this command shuts down the “eth0” network interface, disabling its ability to send or receive network traffic.

usermod: Modify user account properties.

usermod is a command for modifying user account properties in Linux. The example “usermod -aG sudo newuser” adds “newuser” to the “sudo” group, granting them administrative privileges

usermod -aG sudo newuser

ping: Test network connectivity.

ping is a command-line utility to test network connectivity. It sends packets to a specific address, like “ping google.com,” and measures the response time to check if the target is reachable and the network connection is functional.

ping google.com

kill: Terminate processes.

kill is a command used to terminate processes in Linux. By specifying the process ID (PID) as in “kill PID,” it sends a signal to the process, instructing it to stop execution gracefully or forcefully if needed.

kill PID

Summary:
We have listed the basic 26 commands in Linux in this blog