We have listed the important 20 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.
ls- List/Display Directory Listings.
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.
-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
This command is used to change the current working directory of a user.
#command used to switch to home directory
#command used to switch to previous working directory
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 folder from one location to another.This command will copy the folder and contents inside it recursively to anothe 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 folder from 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 consits of folder with same 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 ##
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.
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 delete a particular file in linux#
[email protected]:~# rm filename
#command used to delete the files and contents inside a directory recursively
[email protected]:~# 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 working directory#
[email protected]:~# 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
[email protected]:~# 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 a entire files and folder’s inside a directory ##
[email protected]:~# du -sch ./*
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
[email protected]:~# find / -name filename.txt
#command to find a partiuclar folder inside the / directory #
[email protected]:~# 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 partiuclar word inside the current working directory.This command will search all the files and return the matching files contains the string.#
grep -irl ‘dbname=mysql’
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 an output to an 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 #
[email protected]:~# chmod 644 filename
#command used to chnage 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 Linux system.
##command used to change the ownership of group and owner to root:root of a file ##
[email protected]:~# 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 ##
[email protected]:~# chown -R root:root directory name
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 #
[email protected]:~# top
# command used to display only the running process of a specific user in the system #
top -u username
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 #
[email protected]:~# w
# command used to exclude the header #
~# w -h
This command is log into remote machine and execute commands.It uses ssh protocol which allows to provide secure encrypted communications between two untrusted hosts over an insecure network.This commad will prompt to enter the password of the remote machine.
#Command used to log into a remote network whoes username is root with default port 22#
#Command used to log into a remote network whoes username is root with custom port 5522 #
ssh root@<ipaddress> -p 5522
su – switch user
This command is used to switch user in linux system
#command used to switch user #
[email protected]:~# su <username>
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 1, 5, and 15 minutes intervals.
[email protected]:~# 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.
[email protected]:~# 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.