Table of contents
"Linux commands" refer to the instructions you can input into a Linux terminal to perform specific tasks or operations. Commands are used to instruct the computer. we have to write commands on the shell (terminal). Shell forwards these commands to the kernel and the kernel forwards them to the hardware.
Some Basic Commands
View File Contents
Command:
cat filename.txt
Description: The
cat
command stands for "concatenate and display." It's primarily used to display the content of files.
Change File Permissions
Command:
chmod permissions filename
Description:
chmod
(change mode) is used to set or modify the permissions of a file or directory. Permissions determine who can read, write, or execute a file.
View Command History
Command:
history
Description: The
history
command displays the commands you've entered in your terminal session, allowing you to revisit or reuse previous commands.
Remove Directory
Command:
rmdir directoryname
Description:
rmdir
removes empty directories. If a directory has content, you would userm -r directoryname
.
Create and View a File
Command:
bashCopy codetouch fruits.txt cat fruits.txt
Description:
touch
creates an empty file. Following this withcat
allows you to view its contents, which would be empty in this case.
Add Content to a File
Command:
echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > devops.txt
Description: The
echo
command is used for outputting text. With the-e
flag, it interprets escaped characters like\n
for a new line. The>
operator writes this output to a file.
Display Top Lines of a File
Command:
head -3 devops.txt
Description:
head
displays the top lines of a file. The-3
option specifies that only the top three lines should be shown.
Display Bottom Lines of a File
Command:
tail -3 devops.txt
Description: Conversely,
tail
shows the bottom lines of a file, and the-3
option ensures only the last three lines are shown.
Add Content to Another File
Command:
echo -e "Red\nPink\nWhite\nBlack\nBlue\nOrange\nPurple\nGrey" > Colors.txt
Description: This uses the same
echo
technique as before to add content to a new file.
Some short notes:
Some notes:
The
cat
command is used for viewing the content of files.The
chmod
command is for changing file permissions.history
displays a list of commands that you've previously entered.rmdir
removes an empty directory.touch
creates a new, empty file.echo
outputs the specified text, and with the redirection>
operator, you can write that output to a file. The-e
flag allows the interpretation of escaped characters like\n
(newline).head
andtail
are used to display the top or bottom lines of a file, respectively.The
diff
command compares the contents of two files and displays the differences between them.