Day2  and Day3:-Basic Linux Commands

Day2 and Day3:-Basic Linux Commands

Listing commands

ls:-It is used to list all the files in the directory.

ls-l:-It is used to list all the files and the directories in long-list format with extra information like permissions etc.

ls-a:-It is used to list all the hidden files in the directories.

ls *.sh-It is used to list all the files with .sh extensions

ls -d */-It is used to list only directories.

Directory commands

pwd --> print work directory. Gives the present working directory.

cd path_to_directory --> change directory to the provided path

cd ~ or just cd --> change directory to the home directory

cd - --> Go to the last working directory.

cd .. --> change directory to one step back.

cd ../.. --> Change directory to 2 levels back.

mkdir directoryName --> to make a directory in a specific location

Examples:-

mkdir newfolder:- To make a new folder

mkdir .newfolder- make a hidden directory(. is used to make hidden)

mkdir A B C D :- to make multiple directories at the same time.

mkdir /home/user/newfolder :- to make a newfolder at the specific location

mkdir -p A/B/C/D :- to make a nested folder


cat:- to view what's written in a file

chmod:- to change the access permission of the files.

history:- to check which commands you have run till now.

rm -d:- to remove a directory/folder.

To create a fruits.txt file and to view the content.

echo "Apple" >> fruits.txt && cat fruits.txt:- This will create a file fruits.txt and append the word Apple in it,after that it will view the content of the file

Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.

echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava > devops.txt

sort:- This command is used to sort the file in alphatebetical order

| :- The | symbol is a pipe symbol in Linux, and it is used to connect the output of one command to the input of another command.

head -3 :- This command is used to give the three outputs from the top.

tail -3:- This command is used to give three outputs from the bottom.

Nslookup: This stands for “Name server Lookup”. This is a tool for checking DNS hostname to Ip or Ip to Hostname. This is very helpful while troubleshooting.

Curl: Curl is a tool used for transferring data to or from a server, using various protocols, such as HTTP, HTTPS, FTP, and more. Basic example:

curl -o :-It will save downloaded files on the local machines with the name provided in the parameter

wget:- This command is used to download the files from the internet.

sudo:-The sudo command is a Linux command that allows a user to run commands with the security privileges of another user, typically the root user. It enables authorized users to execute commands as other users, including the system administrator account

apt:- (Advanced Package Tool) is a package manager used on Ubuntu and other Debian-based Linux distributions. It is used to manage the installation, removal, and updating of software packages

yum:-It is the primary package manager for the Red Hat Enterprise Linux distribution and its derivatives, including CentOS and Fedora. It is used to install, update, and manage software packages on these systems. yum downloads packages from software repositories and installs them, along with their dependencies, on the system

sudo apt update:-is a command used on Debian-based systems, including Ubuntu, to update the package lists from all repositories configured on the system. It allows the system to check if there are any available updates for the installed packages, and if so, it will provide information on the available updates

What is the difference between sudo apt update and sudo apt-get update?

Both sudo apt update and sudo apt-get update are used to update the package list on an Ubuntu system.

  • sudo apt update also checks for and updates the repository cache, while sudo apt-get update only updates the package list. So sudo apt update is a more comprehensive command that performs both tasks in one go.

  • In older versions of Ubuntu (before 16.04), sudo apt-get update was the recommended command, while sudo apt update was introduced in later versions.