Table of contents
No headings in the article.
To view what's written in a file.
Use the 'cat' command to see what's written in the file
cat <filename>
To change the access permissions of files.
'chmod' is the command used to change the permissions of the file.
chmod <options permissions> <file>
Permission | Symbol | Description |
Read | r | Allows reading and viewing the contents of a file or folder. |
Write | w | Allows modifying or deleting the contents of a file or folder. |
Execute | x | Allows executing a file (for executable programs or scripts) or accessing a directory. |
To check which commands you have run till now.
history
To remove a directory/ Folder.
The Linux command to remove a directory or folder is
rm
. However, when you want to remove a directory, you need to use the-r
or-rf
option, which stands for "recursive" and allows the removal of directories and their contents.rm -r <directory>
rm
: The command for removing files and directories.-r
: The option to remove directories and their contents recursively.<directory>
: The name or path of the directory you want to remove.
To create a fruits.txt file and to view the content.
Create a new file:
touch filename.txt
Viewing the contents of the file:
cat fruits.txt
Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
Vim (Vi IMproved) is a highly configurable text editor that is available on most Linux distributions. It is an enhanced version of the original Vi editor, which is a standard text editor in Unix-like systems.
Add data to the file:
vim <filename.txt>
Click 'i' to enter the insert mode
Click 'ESC' to exit to the insert mode
Then type ':wq ' to save and exit the file editor.Show only the top three fruits from the file.
To show only the top three fruits from a file in Linux, you can use the
head
command with the-n
(number) option. Here's the command you can use:head -n 3 fruits.txt
Show only the bottom three fruits from the file.
To display only the bottom three fruits from a file in Linux, you can use the
tail
command with the-n
option.tail -n 3 fruits.txt
To create another file Colors.txt and to view the content.
Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, and Grey.
To find the difference between fruits.txt and Colors.txt files.
diff
command: Thediff
command shows the line-by-line differences between two files. Here's the syntax:diff fruits.txt colours.txt
cmp
command: Thecmp
command compares two files byte by byte and displays the first differing byte and its offset. Here's the syntax:cmp colours.txt fruits.txt
The
vimdiff
command allows you to open two files in Vim and highlights the differences between them. Here's the syntax:vimdiff fruits.txt colours.txt
To exit follow these steps: 'ESC' and then ':qa '.