Table of contents
What is a Linux Command:
A Linux command is a program or utility that runs on the command line.
A command line is an interface that accepts lines of text and processes them into instructions for your computer.
Any graphical user interface is just an abstraction of command-line programs.
A flag is a way we can pass options to the command we run.
An argument is a value that we pass to a command to modify its behavior or provide it with additional information.
Basic Linux Commands:
ls - The most frequently used command in Linux to list directories
pwd - Print working directory
cd - to navigate through directories
mkdir - used to create directories in Linux
mv - Move or rename files
cp - Similar usage as mv but for copying files in Linux
rm - Delete files or directories
touch - Create blank/empty files
ln - Create symbolic links (shortcuts) to other files
cat - Display file contents on the terminal
clear - Clear the terminal display
echo - Print any text that follows the command
man - Access manual pages for all Linux commands
whoami - Get the active username
sudo - Command to escalate privileges in Linux
Tasks:
1. To view what's written in a file.
\>> Use the cat command.
Syntax: cat <file name>
2. To change the access permissions of files.
\>> Use chmod command -
Syntax: chmod <permission> <file name>
The basic permissions a file can have are:
r (read) - 4
w (write) - 2
x (execute) - 1
Which are defined for Owner(u), group(g), and other users(o).
Ex1. Adding execute permissions to owner and group. And write permissions to other users.
Ex2. Removing execute permission for owner. (Another way)
3. To check which commands you have run till now.
\>>Use the history command.
4. To remove a directory/ Folder.
\>>Use the rm command.
Syntax: rm <filename>
\>>If you want to delete an empty directory, you can use the recursive (-r) flag:
Syntax: rm -r <dirname>
\>>To remove a directory with content inside of it, you need to use the force (-f) and recursive flags:
Syntax: rm -rf <dirname>
5. To create a fruits.txt file and view the content.
6. Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
7. Show only the top three fruits from the file.
\>>Use the Head command with the -n flag.
Syntax: head -n <filename>
8. Show only the bottom three fruits from the file.
\>>Use the tail command with the -n flag.
Syntax: tail -n <filename>
9. To create another file Colors.txt and to view the content.
\>> touch Colors.txt and cat Colors.txt
10. Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, and Grey.
\>>echo -e "Red \nPing \nWhite \nBlack \nBlue \nOrange \nPurple \nGrey"
11. To find the difference between fruits.txt and Colors.txt files.
\>>Use the diff command.
Syntax: diff <filename1> <filename2>
Thank you for reading!😀