Commands-
To view what's written in a file.
$ cat altos.txt
cat -b:
This adds line numbers to non-blank linescat -n:
This adds line numbers to all linescat -s:
This squeezes blank lines into one linecat –E:
This shows $ at the end of the line
To run any bash script written in editors like nano,vim etc.
./altos.txt
./
- Allow you to run the bash script
To see all the permissions of files.
ls -la
ls
- List files and directories-l
- List files and directories with permission-a
- List all files and directories, even hidden files and directories with permission
To change the access permissions of files.
chmod 777 altos.txt
or
chmod o+wx testfile ls -l testfile -rwxrwxrwx 1 amrood users 1024 Nov 2 00:10 testfile chmod u-x testfile ls -l testfile -rw-rwxrwx 1 amrood users 1024 Nov 2 00:10 testfile chmod g = rx testfile ls -l testfile -rw-r-xrwx 1 amrood users 1024 Nov 2 00:10 testfile
Understanding Security Permissions
First, you need to think of the nine signs as three groups of three signs (see box below). Each of the three "rwx" icons represents a different action you can perform on the file.--- --- --- rwx rwx rwx user group other
r = “read” the file’s contents
w = “write”, or modify, the file’s contents
x = “execute” the file
- = "No permission"
To check which commands you have run till now.
history
To make a file.
touch file1.txt
To remove a file.
rm file1.txt
To make a directory/folder.
mkdir myfolder
To remove a directory/folder.
mkdir -r myfolder
To create a fruits.txt file and to view the content.
touch fruits.txt echo "here is the watermelon" > fruits.txt | cat fruits.txt
or
touch fruits.txt vim fruits.txt cat fruits.txt
Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
vim fruits.txt
vim
- It is a text editor and after saving the edited file it'll automatically create the file without givingtouch
command.Below are the commands to use vim editor,
Entering and Exiting Vim:
vim
: Open a file in Vim.vim filename
: Open a specific file in Vim.:q
: Quit Vim.:q!
: Force quit Vim without saving changes.:wq
or:x
: Save changes and exit Vim.:w
: Save changes to the current file.:w filename
: Save the file with a new name.:wq
or:x
: Save changes and exit Vim.Apple Mango Banana Cherry Kiwi Orange Guava # press "ESC + :wq + ENTER" to save and exit the file
To Show only top three fruits from the file.
The
head
command in Linux is used to display the first few lines of a text file. By default, it displays the first 10 lines of a file, but you can specify a different number of lines using the-n
option. Here's the basic syntax of thehead
command:head [OPTIONS] [FILE]
a)
OPTIONS
are optional flags that modify the behavior of thehead
command.b)
FILE
is the name of the file you want to view. If not specified,head
reads from standard input.To display the first 3 fruits from fruits.txt file,
head -n 3 fruits.txt
To Show only the bottom three fruits from the file.
The
tail
command in Linux is used to display the last few lines of a text file. It is particularly useful for monitoring log files or any other text files where you want to see the most recent entries. Here's the basic syntax of thetail
command:tail [OPTIONS] [FILE]
a)
OPTIONS
are optional flags that modify the behavior of thetail
command.b)
FILE
is the name of the file you want to display. If not specified,tail
reads from standard input.To display the last 3 fruits from fruits.txt file,
tail -n 5 fruits.txt
To create another file colors.txt and to view the content.
touch colors.txt
Add content in colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.
Red Pink White Black Blue Orange Purple Grey # Press "ESC + :wq + ENTER" to save and exit the file
To find the difference between fruits.txt and Colors.txt file.
The
diff
command compares two files line by line and highlights the differences. Here's the basic syntax:diff fruits.txt colors.txt
or
vimdiff fruits.txt colors.txt #display the difference with visuals