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
To capture the packets of current network interface. For more tcpdump commands, Click Here. Below is the Syntax to capture packets from current network:
apt install tcpdump #to install tcpdump sudo tcpdump #to run tcpdump
The
traceroute
command is a network diagnostic tool used to trace the route taken by packets from a source to a destination over an IP network. It provides valuable insights into the network path, including the number of hops (routers) between the source and destination, and the round-trip time (RTT) for each hop.traceroute [options] destination
Difference Between tcpdump and traceroute:
tcpdump
andtraceroute
are both network diagnostic tools but serve different purposes.tcpdump captures and analyzes network packets in real-time, allowing you to inspect the data traveling over a network. It helps in debugging network issues by providing detailed packet-level information (IP addresses, ports, flags, etc.).
traceroute traces the path that packets take from one device to another over a network, showing each hop between routers. It’s useful for identifying network routing issues and delays at various points in the path.
Tool that allows you to view information about the processes running on your Linux system.
ps
Difference between top and ps and other similar command.
top
andps
are both used to monitor system processes, but they serve different purposes:top
provides a real-time, dynamic view of system performance, showing CPU, memory usage, and a constantly updated list of running processes. It's useful for ongoing monitoring of system resource consumption.ps
displays a snapshot of currently running processes at the moment it is run. It shows detailed process information (PID, memory, CPU usage, etc.) but does not update in real-time.
Other similar commands:
htop
(liketop
but more interactive).vmstat
shows system resource statistics like memory, processes, and I/O.
Command to Download
wget <url> (and) curl <url>
curl
andwget
are both command-line tools used for downloading content from the web, but they have key differences:curl
is a versatile tool that supports many protocols (HTTP, FTP, SMTP, etc.), and is often used for making API requests, sending data, and handling complex network interactions. It downloads content to stdout by default.wget
is primarily designed for downloading files from the web and supports recursive downloading, making it ideal for mirroring websites or downloading large sets of files. It automatically saves files to disk.
Command to encode and decode something in base64
# Encode echo <Type someting you want to encode> | base64 eg. echo myencode | base64 #input Output- bXllbmNvZGUK #Encoded Output # Decode echo <Enter base64 encoded value> | base64 --decode eg. echo bXllbmNvZGUK | base64 --decode #input Output- myencode #Decoded Output