Linux is a Unix like, open source and community developed operating system for computers, servers, mainframe computers and embedded devices. It is supported on almost every major computer platform which makes it one of the most widely supported operating systems.
Most of people think Linux is very complicated operating system in general use or it's only for programmers, because people are afraid of command line arguments (CLI).
In general use a command-line interface is more powerful and effective. Tasks that require a multi-step process through GUI can be done in a matter of seconds by typing commands into the CLI.
Anyone is thinking about using Linux or any other Linux distribution like Ubuntu, CentOS, Fedora. They must know some basic or command commands of linux which help them to perform daily operations. Below are basic commands and their use :
pwd command is built-in command which prints full path of working directory from root. PWD stands for Print Working Directory. i.e. /home/username
pwd command has 2 flags :
The ls command is used to view the contents of a directory. By default, it will use current working directory. You can also pass other directory path as parameter. The ls command is slimier to Dir command in windows.
There are few variation for ls command :
The cd command is used to navigate through directories and files in CLI. This command requires pass as parameter which can be full path or directory name based on your working directory.
There are some shortcuts to help you to use cd command effectively :
The cat (concatenate) is one of the most conmanly used commands. It is used to list the contents of a file on the standard output. It's also used to create new file.
This command require file name with it's extension as parameter. i.e. cat file.txt.
To create new file with cat command you can use this example : cat > file.txt.
It can also used for join two files. i.e. cat filename1 filename2>filename3
The cp command used to copy files from one directory to another. For example, the command cp text.txt /home/username/myfiles will copy file to myfiles directory.
The mv command is used to move files from one directory to another. We can also use mv command to rename files.
The use of mv command is similar to cp command. For example mv file.txt /home/username. To use mv command to rename file, we need to pass new file name as second flag like this : mv file.txt file1.txt.
Find text in a file. The grep command searches through many files at a time to find a piece of text you are looking for. i.e. grep 'search_term' file.txt. It will search file and returns details about search result.
Sometimes there is need to specif rights to perform some actions like installing application you need to System Administrator rights. When you give any commands with sudo command then it will perform that task with high priority and as super admin.
For example you have logged in from general user who don't have right to perform application installation. But with sudo command you can perform that task.
sudo apt-get install package_name
As per name shutdown command suggest to power off system. But with shutdown command you can perform delay into shutdown or reboot system as per your requirements.
Below are some examples of shutdown command :
shutdown now
//Shutdown at specific time
shutdown 15:44
//cancel previous shutdown
shutdown -c
//To reboot system
sudo shutdown -r now
While working with files, sometimes we need to create directories. you can create directory/folder using mkdir command. mkdir stands for make directory.
Here we just need to pass directory name as parameter like below example :
mkdir test
The rm command is used for removing files and directories from our system. You need to be careful while using this command, because it’s very difficult to recover files deleted this way.
Below are some examples of rm command :
rm test.txt
//remove directory
rm -r test/
//remove directory with it's content forcefully
rm -rf test/
The man command displays manual information about another command like help with that command. To see the manual information about any command you need to pass command name as parameter like below:
man man
//or
man rm
The touch command allows you to create a blank new file through the Linux command line. The touch command also used for updating timestamp information of file.
touch text.txt
//or
touch -m text.txt
The chmod command allows you to change file permissions. It has lots of sub options available but basic permissions are read, write and execute.
One of the most common use of chmod is to make a file executable by the user. To do that you need to use +x flag.
chmod +x text
The exit command works as per name, it will end shell session of your terminal and automatically closes current terminal.
The locate command works just like window's search command. It will search files on system. By default it's case-sensitive but you can pass -i to make it case-insensitive. i.e. locate -i test will search file with test in it's name.
This command will help you to unzip files with zip format. This package is not pre-installed so make sure you have installed it before using it.
Below is example command to unzip file :
unzip test.zip
In Linux package managers are used to install or uninstall packages. So at some point of work, you need to use those package manage. Generally package managers are based on Linux distribution.
Debian-based systems like ubuntu or linux-mint uses apt by default. Where in Fedora or CentOS, yum is used for installation. while in Arch-based systems like Arco linux or Manjaro use pacman as their package manager.
Below are some examples of installing gimp on different Linux distribution :
sudo apt install gimp
sudo yum install gimp
sudo pacman -S gimp
The echo command prints text into terminal. Primary use of echo is to print environment variables but we can use it as per our requirement like showing some information while shell script is running.
Generally using system with low configuration some programs become in-responsive and can not be closed by GUI. Then we can forcefully close it's process with kill command.
In simple words kill command send specific program close request to system. Here we can use PID (process ID) or program's binary name.
The ping is the most popular networking terminal utility used to test network connectivity. ping has a ton of options, but in most cases, you’ll use it to request a domain or IP address.
The ping command accpt either IP address or domain name of particular server or website. like below example
ping google.com
ping 142.250.199.142
As per name suggest diff stands for difference. The diff command is used for check difference between two file. Here it will take two full name of file as parameter. i.e. diff text1.txt text2.txt.
The diff command will compare both files line by line and prints lines that do not match.
In Linux, all files are owned by a specific user. The chown command enables you to change or transfer the ownership of a file to the specified username. For example chown user_name text.txt will transfer text file ownership to given user.
If you are downloading lots of content from internet then wget command is very useful. The wget command take url as parameter and download content from that user. Generally it's used to download softwares.
The whoami command displays the username currently in use.
Linux is multi-user system and sometimes more than one person is using same system. With useradd and userdel command user access become simplier.
The useradd command used for adding user to system. While userdel command used for deleting existing user from system.The both commands useradd and userdel need user name as parameter.
Ask anything about this examples