Table of contents
- π§π οΈ What Are Linux Commands? ππ»
- π To View What's Written in a File π§
- π To Change the Access Permissions of Filesπ
- ππ To check which commands you have run till nowπ»:
- ποΈπ To remove a directory/folder in Linux π§π»:
- To create a πfruits.txt file and to viewπ the contentπ
- Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
- π Show Top Three Fruits from the File π
- π Show the Bottom Three Fruits from the File π
- π¨π Create Colors.txt and π View the Content π¨π
- ππ Finding Differences between fruits.txt and Colors.txt ππ
π§π οΈ What Are Linux Commands? ππ»
π§π§ The term "Linux command" refers to the various commands that can be used in the Linux operating system's terminal (also known as the shell or command-line interface) to perform specific tasks, manage files, manipulate data, and control the system. π»π οΈ
Linux commands are usually typed in the terminal, and they follow a general syntax: command [options] [arguments]
. The basic structure is as follows:
π command
: The name of the Linux command you want to execute.
π options
: Optional flags or switches that modify the behavior of the command.
π arguments
: Input data or parameters required by the command. π₯
π To View What's Written in a File π§
π View File Contents with cat
Command π±
With the cat
command in Linux, you can easily display the contents of a file directly on the terminal. It's as simple as π± and allows you to see what's inside at a glance!π Let's assume we have a file named example.txt
with the following content: "This is an example file. Hello, world!"
To view the content of the example.txt
file, you can use the cat
command like this:
cat example.txt
Output:
This is an example file.
Hello, world!
π To Change the Access Permissions of Filesπ
π Changing File Permissions with chmod
Command π‘οΈ
In Linux, the chmod
command is used to change file permissions. It controls who can π read(r), βοΈ write (w), and π execute(x) the file.
Let's say we have a file named example.txt
Default permissions: -rw-r--r--
(Owner can read and write, Group and Others can only read)
To give full control to the owner, group, and others (equivalent to 777
), you can use the chmod
command as follows:
chmod 777 example.txt
Updated permissions: -rwxrwxrwx
The permission 777
grants full read, write and execute access to the file for the owner (root), group, and other users.
ππ To check which commands you have run till nowπ»:
You can use the history
command to display a list of previously executed commands in the terminal.
history
ποΈπ To remove a directory/folder in Linux π§π»:
To remove an empty directory using
rmdir
:rmdir directory_name
To remove a directory and its contents recursively using
rm
:rm -r directory_name
To remove a file using
rm:
rm filename.txt
To create a πfruits.txt file and to viewπ the contentπ
- To create the
fruits.txt
file:
echo -e "Apple\nBanana\nOrange\nGrapes" > fruits.txt
- To view the content of the
fruits.txt
file, you can usecat
:
cat fruits.txt
Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
To add the content into a file named devops.txt
with each item on a new line, you can use the following command:
echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > devops.txt
This command uses the echo
command with the -e
option to enable interpretation of escape characters like \n
(newline). It then redirects the output of echo
to the devops.txt
file, effectively creating the file with the specified content, with each item on a new line.
π Show Top Three Fruits from the File π
To show only the top three fruits from the file devops.txt
, you can use the head
command
head -n 3 devops.txt
π Show the Bottom Three Fruits from the File π
To show only the bottom three fruits from this file, you can use the following command
tail -n 3 devops.txt
π¨π Create Colors.txt and π View the Content π¨π
To create a new file named Colors.txt
and view its content, you can use the following commands:
- To create the
Colors.txt
file:
echo -e "Red\nGreen\nBlue\nYellow\nOrange\nPurple\nPink" > Colors.txt
- To view the content of the
Colors.txt
usingcat
:
cat Colors.txt
ππ Finding Differences between fruits.txt and Colors.txt ππ
To find the difference between the fruits.txt
and Colors.txt
files, you can use the diff
command. The diff
command compares two files line by line and shows the lines that are different. Here's how you can do it:
diff fruits.txt Colors.txt
Mastering Linux commands unlocks endless possibilities! ππ» From managing systems to manipulating data, these tools empower you to take full control. Embrace the command line and venture forth with confidence into the world of Linux! π§πͺ Happy exploring! π