Table of contents
- Installation
- Linux Commands:
- "ls"
- "ls -l"
- "mkdir"
- "cd"
- "ls -a "
- "touch"
- "echo abcdef > xyz.txt"
- "cat"
- "pwd"
- "ls -R"
- "man"
- "cp"
- "mv"
- "rm"
- "cp -R"
- "rm -R"
- "sudo"
- "df"
- "head"
- "tail"
- "diff"
- "find"
- "sudo chown"
- "grep"
- "grep -i"
- "grep -n"
- "grep -wirl"
- "history"
- "history | grep "ls"
- "sort"
- "sort -r"
- "ping"
- "wget"
- Commands Related to OS:
- "uname"
- "name -o"
- "name -m"
- "uname -r"
- "lscpu"
Installation
- Before we start with the Linux commands we need to set up our windows systems.
- To begin with, we will need two things:
- Windows PowerShell: https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701#activetab=pivot:overviewtab
- Install WSL(Windows Subsystem for Linux): https://docs.microsoft.com/en-us/windows/wsl/install
Linux Commands:
"ls"
ls
:This command allows you to view all the items in the current folder
"ls -l"
ls -l
:This command allows you to view in details about all the items in the current folder
"mkdir"
mkdir linuxtutorial
:Create new folder linuxtutorial
"cd"
cd linuxtutorial
:Change directory ---> means entering into a folder named linuxtutorial
"ls -a "
ls -a
: Shows all the files including hidden files as well in that directory
"touch"
touch ex1.txt
:It created a new file ex1.txt
"echo abcdef > xyz.txt"
echo "helloworld" > ex1.txt
: helloworld will be printed in ex1.txt file
"cat"
cat ex1.txt
:To display contents inside a file named ex1.txt
"pwd"
pwd
:It basically shows in which directory you are in right now
"ls -R"
ls -R
:It will show all the files present in the sub-directory
"man"
man echo
:To get information about a particular command "echo"
"cp"
cp ex1.txt copy_ex1.txt
:To copy file,in this example ex1.txt was copied as copy_ex1.txt
"mv"
mv ex1.txt file1
:To move file/folder, in this example ex1.txt was moved into file1- "mv" can also be used to rename files
mv ex1.txt ex2.txt
:In above example ex1.txt was renamed to ex2.txt
- "mv" can also be used to rename files
"rm"
rm ey.txt
:To remove files(Be careful while using this command ,it permanently deletes the content)
"cp -R"
cp -R file1 copy_file1
:To copy a complete directory(folder)
"rm -R"
rm -R copy_file1
:To delete a complete directory(folder)
"sudo"
sudo -h
:You can execute the command as an administrator
"df"
df
:To check out system's disk space usage
"head"
head ex.txt
:To view the first few lines of any file
"tail"
tail ex.txt
:To view the last few lines of any file
"diff"
diff ex.txt ex2.txt
:Compare two files ,line by line and gives o/p which doesn't matches view the last few lines of any file
"find"
find .
:Find in current directoryfind file2
:Find in file2 directoryfind . -type d
:Find in current directory of type "directory"find . -type f
:Find in current directory of type "file"find . -type f -mmin -20
:In current directory find all files modified less than 20 min agofind . -type f -mmin +15
:In current directory find all files modified more than 15 min agofind . -size +1k
:Find in current directory of size greater than 1kbfind . -empty
:Find in current directory in which all files are empty
"sudo chown"
sudo chown root upper.txt
: To change the owner who can access a particular file or directory. In the above example owner "root" can access upper.txt
"grep"
grep "devops" ex1.txt
: It allows us to search some text inside files and it is case sensitive. In the above example search "devops" in ex1.txt
"grep -i"
grep -i "devops" ex1.txt
: It allows us to search some text inside files and because of "-i" it becomes case insensitive. In the above example search "devops" in ex1.txt
"grep -n"
grep -n "devops" ex1.txt
: It gives us the line number of the required text inside files. In the above example, it gives the line no. of "devops" in ex1.txt
"grep -wirl"
grep -wirl "devops" .
: It searches the file's location in which "devops" is present in current directory
"history"
history
: It shows all commands we have used in past
"history | grep "ls"
( Here '|' is known as piping)history | grep "ls"
: Shows all the commands where "ls" was used
"sort"
sort ex1.txt
: Sorts the content in right order inside a file
"sort -r"
sort -r ex1.txt
: Sorts the content in reverse order inside a file
"ping"
ping google.com
: To check connectivity status
"wget"
"**wget**"
: You can download files from internet using this command
Commands Related to OS:
"uname"
uname
: It shows which kernel we are using (Linux)
"name -o"
uname -o
: To check the type(GNU/Linux)
"name -m"
uname -m
: To check the architecture
"uname -r"
uname -r
: To check the kernel version
"lscpu"
lscpu
: To get all the details of CPU