Table of contents
- π§ LINUX COMMAND π»
- π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π
- πTo create a fruits.txt file and to view the contentπ
- πAdd content in fruit.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava β
- ππ To Show only the top three fruits from the file π
- πTo Show only the bottom three fruits from the fileπ
- πTo create another file Colors.txt and to view the contentπ
π§ LINUX COMMAND π»
π Navigate through Directories:
cd
: Change directory, to move to a different folder.ls
: List files and directories in the current folder.
π Work with Files:
touch
: Create an empty file.cp
: Copy files or directories.mv
: Move or rename files or directories.rm
: Remove files or directories.
ποΈ Manage Directories:
mkdir
: Create a new directory.rmdir
: Remove an empty directory.
π Search for Information:
grep
: Search for a specific pattern in files.find
: Search for files and directories based on various criteria.
π Check System Information:
uname
: Display system information.df
: Show disk space usage.free
: Display memory usage.
βοΈ Manage Processes:
ps
: List running processes.kill
: Terminate a running process.
π Compress and Archive Files:
tar
: Create or extract tar archives.gzip
: Compress files using gzip compression.
π Control System Services:
systemctl
: Control system services, like starting or stopping them.
π Network-related Commands:
ping
: Check network connectivity to a specific host.ifconfig
orip
: Display network interface information.
π§ Administrative Tasks:
sudo
: Execute commands with administrative privileges.
πTo view what's written in a file π
- You can read the text or data stored inside a file by viewing its contents. This can be helpful for reading documents, notes, configuration files, or any other text-based data.
π Follow these steps to view what's written in a file:
π₯οΈ Open a Terminal:
- On Ubuntu, Fedora, or other Linux distributions, you can open the Terminal from the Applications or System Tools menu.
π Use the "cat" Command:
- In the Terminal, type the command
cat
followed by a space.
- In the Terminal, type the command
π Specify the File Name:
- After the
cat
command, type the name of the file you want to view (e.g.,myfile.txt
).
- After the
β¨οΈ Press Enter:
- Press the Enter key to execute the
cat
command and view the contents of the file.
- Press the Enter key to execute the
ππ» You will see the complete text or data written in the file displayed directly in the terminal window.
πTo change the access permissions of files π»
- Each file in Linux has access permissions that specify who is allowed to read(ποΈ), write(π), and execute(βΆοΈ) the file. For sensitive data to remain secure and under control, certain permissions are crucial.
- βοΈ Understanding Access Permissions:
There are three types of permissions for each file: read (ποΈ)7, write (π)7, and execute (βΆοΈ)7.
Permissions are set for three categories of users: the file owner (π), the group the file belongs to (π₯), and others (π).
- π’ Representation of Permissions:
Read (ποΈ) is represented by
r
=7
.Write (π) is represented by
w
=7
.Execute (βΆοΈ) is represented by
x
=7
.A dash
-
indicates that a specific permission is not granted.
π§ Changing Access Permissions Using chmod
:
chmod 777
command is used to modify access permissions.After granting permissions using
chmod
, you can use this command to view your file as well.
./<your filename.txt>
- To check if the permission was granted, you can use
ls
and notice that your file will appear in green color, indicating that it has been permissioned.
π Examples of Changing Access Permissions:
Note:-This will learn detail on day 6 of the Task click on this to see
πTo check which commands you have run till nowπ
- With Linux, it's simple to see a history of the commands you've run in the terminal. This history feature makes it simple to remember and reuse prior commands for routine operations.
- π§ Using History Command:
- The
history
command displays a list of recently executed commands along with their line numbers.
π‘ Examples of Checking Command History:
Remember, the command history feature is a useful tool for recalling and reusing commands, saving time and effort in the Linux terminal. It allows you to be more productive and efficient in your command-line tasks! πππ§
ποΈTo remove a directory/ Folderπ
- The
rmdir
orrm
command in Linux can be used to eliminate directories or folders from your file system. When executing these commands, though, it's important to exercise caution because erased data cannot be easily retrieved.
- π§ Using the
rmdir
Command:
- The
rmdir
command is used to remove an empty directory.
π‘ Example of Removing an Empty Directory: To remove an empty directory named new-folder
- π§ Using the
rm
Command:
- The
rm
command is used to remove directories and their contents recursively.
π‘ Example of Removing a Directory and Its Contents: To remove a directory named my-demo.txt
and all its contents:
πTo create a fruits.txt file and to view the contentπ
- Different text editors are available in Linux for creating new files and viewing their contents. Here, we'll create the file using the
touch
command and then open it with thecat
command to see what's inside.
- π§ Using the
touch
Command to Create fruits.txt File:
- The
touch
command creates an empty file if it does not exist. If the file already exists, it updates the file's modification timestamp.
π‘ Example of Creating the fruits.txt File: To create the fruits.txt
file, simply run the following command:
touch fruit.txt
- π§ Using the
cat
Command to View File Content:
- The
cat
command is used to concatenate and display the content of a file.
π‘ Example of Viewing the fruits.txt File's Content: To view the content of the fruits.txt file, use the cat
command as follows:
cat fruit.txt
πAdd content in fruit.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava β
- To add content to the
fruits.txt
file, you can use a text editor likenano
orvim
. For a non-IT audience,vim
is more user-friendly.
- π§ Using the
vim
Text Editor and pressi
to Add Content:
- Open the
fruits.txt
file in thevim
text editor:
vim fruit.txt
- Add the desired content (e.g., list of fruits) to the file.
Apple
Mango
Banana
Cherry
Kiwi
Orange
Guava
- Save what you wrote using
Esc:wq
and then pressEnter
.
Viewing the fruits.txt
File's Updated Content Use the cat
command to view the changed content after adding content to the fruits.txt
file.
I'm done now! The fruits.txt
file was successfully created, its contents were added using vim
, and its contents were seen using the cat
program. You can now maintain a list of your preferred fruits or any other text data in the file. πππ
ππ To Show only the top three fruits from the file π
- With the
head
command in Linux, you can only see the top (first) few lines of a file. We'll use the head command, in this case, to just display the first three fruits from thefruits.txt
file.
- π§ Using the
head
Command:
- The
head
command is used to display the beginning (top) lines of a file.
π‘ Example of Showing the Top Three Fruits from fruits.txt
Suppose the fruits.txt
file contains the following content:
- To display only the top three fruits from the file, use the
head
command with the-n
option, specifying the number of lines you want to display (in this case, three):
head -3 fruit.txt
π Explanation: The head -3
command displays the first three lines from the fruits.txt
file, which are the names of the top three fruits.
Now you can easily view the top three fruits from the file without having to go through the entire content. ππππ
πTo Show only the bottom three fruits from the fileπ
- The
tail
command in Linux allows you to just see the final few lines of a file. We'll use thetail
command in this case to only display the bottom three fruits from thefruits.txt
file.
- π§ Using the
tail
Command:
- The
tail
command is used to display the ending (bottom) lines of a file.
π‘ Example of Showing the Bottom Three Fruits from fruits.txt
Suppose the fruits.txt
file contains the following content
- To display only the bottom three fruits from the file, use the tail command with the option, specifying the number of lines you want to display (in this case, three):
π Explanation: The tail -3
command displays the last three lines from the fruits.txt
file, which are the names of the bottom three fruits.
Now you can quickly view the bottom three fruits from the file without having to go through the entire content. ππππ
πTo create another file Colors.txt and to view the contentπ
Different text editors are available in Linux for creating new files and viewing their contents. Here, we'll create the file using the
touch
command and then open it with thecat
command to see what's inside.To create a file named
Colors.txt
and view its content in Linux, you can use commands liketouch
to create the file and a text editor likevim
to add content.
Here's an example:
touch Colors.txt
vim Colors.txt
After running these commands, you'll be in the
vim
text editor where you can type or paste the desired content into the file. To save and exit, pressEsc
, then confirm with:wq
to save changes and pressEnter
.If you want to view the content of the file directly in the terminal, you can use the
cat
command:
cat Colors.txt
π Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey π
- To add content to the
colour.txt
file, you can use a text editor likenano
orvim
. For a non-IT audience,vim
is more user-friendly.
- π§ Using the
vim
Text Editor and pressi
to Add Content:
- Open the
colour.txt
file in thevim
text editor:
vim colour.txt
- Add the desired content (e.g., list of fruits) to the file.
Red
Pink
White
Black
Blue
Orange
Purple
Grey
- Save what you wrote using
Esc:wq
and then pressEnter
.
Viewing the colour.txt
File's Updated Content Use the cat
command to view the changed content after adding content to the colour.txt
file.
I'm done now! The colour.txt
file was successfully created, its contents were added using vim
, and its contents were seen using the cat
program. You can now maintain a list of your preferred fruits or any other text data in the file. πππ
πTo find the difference between fruits.txt and Colors.txt file π
- To compare the contents of two text files and identify discrepancies, use the
diff
command in Linux. Here, we'll compare the contents of theColors.txt
andFruits.txt
files to see if there are any differences.
- π§ Using the
diff
Command:
- The
diff
command is used to compare text files line by line.
π‘ Example of Finding the Difference Between fruits.txt
and Colors.txt
Suppose the fruits.txt
& colour.txt
file contains the following content:
To find the difference between the two files, use the diff
command as follows:
Happy Learning
Thanks For Reading! :)
-SriParthuππ₯