Linux Beginner Commands

Linux Beginner Commands

⭐ Day 02 of #90DaysofDevOps

Hi Everyone, welcome to Day 02 of the #90DaysofDevops learning journey. In this session, we will cover Basic Linux commands.

Linux is a free and open-source operating system based on the Unix-like kernel. It is widely used in servers, supercomputers, and embedded systems, and is also popular among developers due to its flexibility and customizability.

A tool of the Linux operating system is the Linux command.

By running commands, you can complete all simple and complex activities. The Linux terminal is used to run the commands. Similar to the command prompt in Windows OS, the terminal is a command-line interface for interacting with the system. Linux commands are case-sensitive.

🚀 Basics Linux command🖥🖥

🔸 pwd Command

The pwd command is used to display the location of the current working directory.

syntax: pwd

pwd

🔸 mkdir Command

The mkdir command is used to create a new directory under any directory.

syntax: mkdir <directory name>

mkdir demo1
  • mkdir.NewFolder --> Make a hidden directory (also . before a file to make it hidden)

      mkdir .MyWorkData
    
  • mkdir P Q R S --> Make multiple directories at the same time.

  •           mkdir P Q R S
    

    mkdir ./demo1/demo2 --> make a new folder in a specific location

mkdir ./demo1/demo2
  • mkdir -p A/B/C/D/E --> Make a nested directory

  •         mkdir -p A/B/C/D/E
    
  • with the help of the tree command its easy to display all directories

  •         tree
    

🔸 cd Command

The cd command is used to change the current directory.

syntax: cd <directory name>

cd demo1

To check the current location now use the pwd command.

🔸 touch Command

The touch command is used to create empty files. We can create multiple empty files by executing it once.

syntax: touch <filename.ext> // single file creation

touch <file1.txt> <file2.txt> // multiple file creation

touch file1.txt

touch file1.txt file2.txt

🔸 cat Command

The cat command is a multi-purpose utility in the Linux system. It can be used to create a file, display the content of the file, copy the content of one file to another file, and more.

i. Display A File With cat Command

To view file content. cat <filename.ext>

cat file1.txt

ii. Create A File With cat Command

we can create also a file with the help of the cat command.

syntax: cat > <filename.ext

-----content of file ctrl+D

 cat > <filename.ext>
-----
-----
content of file
----
<control+D>

You need to press [CTRL] + [D] i.e. hold the control key down.

iii. Viewing A Large File With cat Command And Shell Pipes

If the file is too large to fit on the computer screen, the text will scroll down at high speed. You will be not able to read. To solve this problem pass the cat command output to the more or less command as follows:

syntax: cat <filename.ext> | more

cat <filename.ext> | less

cat bigfile_data.txt|more

cat bigfile_data.txt|less

iv. How To Combine Two Or More Files Using cat Command

You can combine two files and creates a new file called all_data.txt

syntax: cat filename1.ext filename2.ext > new_filename.ext

cat file1.txt file2.txt >all_data.txt

cat all_data.txt

v. How To Append Data To A Text File

To append (add data to existing) data to a file called all_data.txt

cat >>all_data.txt
----
----
This is the final data report.
<control+D>

vi. Count the number of All Output Lines in a specific file.

cat -n filename1.txt
cat --number filename1.txt

🔸 ls Command

The ls command is used to display a list of the content of a directory.

syntax: ls

i. Displaying the ls command help page

To view more options and what you can do with ls simply run ls --help

ls --help

ii. Accessing ls man pages

Alternatively, you can view the manpages to find out more about its usage by running man ls

man ls

iii. Listing file and directory permissions with the -l option

using the -l flag, you can list the permissions of the files and directories as well as other attributes such as folder names, file and directory sizes, and modified date and time.

Syntax: ls -l

ls -l

iv. Viewing Hidden files

You can view hidden files by appending the -a flag. Hidden files are usually system files that begin with a full stop or a period.

syntax: ls -a

ls -a

v. Listing files in reverse order

To list files in reverse order, append the -r flag as shown

Syntax: ls -r

ls -r

🔸 cp Command

The cp command is used to copy a file or directory.

syntax: cp <existing file name> <new file name>

cp file1.txt file_copydemo1.txt

🔸 mv Command

The mv command is used to move a file or a directory from one location to another location.

syntax: mv <file name> <directory path>

🔸 rmdir Command

The rmdir command is used to delete a directory.

syntax: rmdir <directory name>

rmdir demo2

🔸 clear command

The clear command is used to clear the terminal screen.

clear

🔸 help command

The help command is used to display information about commands//c

Syntax: help [-d | -m | -s] [Command_name]

Option: -d

Description: Display a short description for each topic.

help -d pwd

Option: -m

Description: Display usage in pseudo-manpage format.

help -m pwd

Option: -s

Description: Display a short usage synopsis for each topic matching.

help -s pwd

Example:

🔸 List all the files or directories including hidden files.

🔸 exit command

The exit command is used to exit the shell.

🎉 Task Done👍 Day 02 of #90daysofdevops 💯

In this article, we have covered the Day 02 task of how to check the present working directory and how to list all Hidden files or directories created nested directory A/B/C/D/E. As well as covered basic Linux commands used for DevOps

If you enjoyed this article please like it and share it with your friends and colleagues!

Thank you for reading🤓