Linux is the major choice of operating system for most of the computers worldwide, particularly in servers. This is for many reasons, the most important one being free and open-source. Because this is open-source, communities can add features and logic on top of Linux, according to their taste and choice, while leaving the main Linux Kernel undisturbed.
Linux a shell, a Command Line Interface, known mostly as BASH(Bourne Again SHell). Although people have created many alternatives to this shell, the main language under the hood is mostly the same. The BASH accepts commands as user input and then executes it. Because, Linux is very common in cloud servers and work stations, it is essential to learn and practice important commands of BASH, in order to operate a task in Linux, in the most efficient manner as possible. In Linux, directories are the same as folders.
In Linux, the general syntax for a command is case-sensitive and as follows:
command [-flag(s)] [-option(s) [value]] [argument(s)]
Relative paths begin with no slashes but absolute paths begin with "/"
"." represents current directory, ".." represents one level above the current directory, "- represents the previous directory
View current working directory
pwd
e.g. pwdChange working directory
cd folder_name
e.g. cd folder_2Change to one level above the current directory
cd ..
e.g. cd ..List down the contents of a directory
ls
e.g. lsList down the contents of a directory in compact form
ls -l
e.g. ls -lList down the contents of a directory, sorted by size
ls -s
Output text on terminal
echo text_here
e.g. echo Hello World!Create a directory
mkdir folder_name
e.g. mkdir folder 2Create a file
touch file_name
e.g. touch file.txtCopy file to a directory
cp file_name folder_name
e.g. cp hello.word folder2Delete a file from a directory
rm file_name
e.g. rm hello.txtDelete a directory (be careful when removing directories recursively, as it may potentially destroy the operating system)
rm -r folder_name e.g. rm -r folder1
Move a file to a directory
mv file_name folder_name
e.g. mv hello.txt folder2Rename a file
mv file_name new_file_name
e.g. mv hello.txt hello.wordView content of a file
more file_name
e.g. more hello.wordView the file tree of a directory
find folder_name
e.g. find folder3Change to two levels above the current directory
cd ../..
Change to a directory within another directory
cd folder_name/other_folder_name
e.g. cd folder1/folder2View path of a file within a directory
find -name file_name
e.g. find -name hello.wordView path of a directory within a directory
find -name file_name
e.g. find -name folder2Remove an empty directory
rmdir folder_name
e.g. rmdir folder3Append output of echo command to a file
echo Hello World! >> file_name
e.g. echo Hello! >> hello.txt