Bytes: Linux is the most popular operating system for programmers. If you are a beginner who wants to get started on Linux then you should learn some basic commands first. These commands can be used on a shell (CLI on Linux) to perform the regular tasks such as creating and deleting files and folders. In this post, we will see some basic commands used in Linux OS.
Why Is Linux So Popular?
Before talking about Linux Command let us see why Linux is so popular. We interact with an interface to execute our tasks on a personal computer doesn’t matter if that is a Windows, MacOS or Linux operating system. An OS normally provides a default user interface to the user like you and me to manipulate our processes. There is a standard look for Windows, different look and feel for MacOS computers and in modern Linux distributions, we have graphical user interfaces, which is also called GUIs. Linux operating system is used by most of the programmers because of the following reasons.
- Free and open source.
- It is so cool to use and interact with a flawless interface of Linux.
- As a programmer, we spend a lot of time on the terminal of such OS therefore, the IDE contains the ability to do some graphical user-stuff like clicking and dragging.
- Commands of Linux can be used on any Unix-based operating system so convenient for those who switch their OS a lot.
- High-end security. Companies choose Linux for their servers because it is secure also due to a large community, we get excellent support. Companies like Canonical, SUSE, and Red Hat, offer commercial support as well.
- People who want to experiment with operating system principles will love this.
- Offers more flexibility and configuration options that we don’t get on windows PC.
- short and many easy commands to learn quickly.
- As it is open source so modifications suggested by its users can be added by the administrator of LINUX.
- You can use Linux Kernel to design your own custom operating systems.
- It offers millions of programs/applications to choose from, most of them are free.
Windows and MacOS also have Command Prompt/ Terminal respectively but some of the commands slightly differ. So let’s take a look at some of the Linux commands that are frequently used in day to day life of a programmer.
Basic Linux Commands
You can execute these commands for the practice on any Linux or Unix based terminal.
1. ls Command
“Ls” command gives you a readout of all the files and folders in your current directory. If you run ls without any parameters, the program will show a list of the contents of the current directory in short form.
—–> ls [option(s)] [file(s)]
2. cd Command
Another command that you will frequently be working with is (cd, lowercase c, lowercase d) which stands for change directory. This command is used to navigate between directories at the command line. If we write cd followed by name of a directory, we can get into that directory.
Note- The name of the current directory is always dot, and the name of the directory one level above is a dot, dot i.e (..) and to implement this you can write cd followed by space and then a dot.
—–> cd [options(s)] [directory]
3. pwd Command
This command is used to tell the name of the directory.
4. mkdir Command
If you like the GUI of an operating system, then you might have created a new directory by right-clicking and then, when the context menu pops up, choosing new folder but we can also create directories at the command line. (mkdir) is a short form for making a directory. If you need to create a new folder/directory then use this command on your command line.
—–> mkdir [option(s)] directoryname
5. rmdir Command
This command is used to delete a directory. it deletes the specified directory, provided it should be empty.
—–> rmdir [option(s)] directoryname
6. cp Command
cp stands for a copy. It takes two arguments, a source, the name of the file that you want to copy, and a destination, where you want to copy the file to.
Note- When you have a directory that has to other stuff inside it, the cp command doesn’t work. In that case, We need to explicitly tell Linux, the terminal, that copy the ‘A’ directory and copy every folder that exists inside of it and every file that exists inside of it. So you need to use cp followed by space and then -r i.e cp -r and then source and targetfile.
—–> cp [option(s)] sourcefile targetfile
7. rm Command
This command is used to remove the file we want to get rid of. It does a lot of double-checking, to make sure that you really want to delete the file as there is no Recycle Bin here. Once we delete a file, it’s gone so it takes care of that part for us.
- type y or yes to confirm or rm -f to skip the confirmation and rm -r is used to delete the entire directory.
- rm -rf is a command that you can use to delete all the stuff recursively and ones this is entered you might lose all the stuff from your computer,
—–> rm [option(s)] file(s)
8. mv Command
Another very useful command that you will be writing daily is mv command. (mv,) stands for move. Move Is basically equivalent to rename and it moves a file from one location to another, the source to the destination.
Note- mv -b creates a backup copy of the sourcefile before moving. mv -i waits for confirmation, if necessary before an existing targetfile is overwritten
—–> mv [option(s)] sourcefile targetfile
9. find Command
The find command allows us to search for a file in a given directory. It takes two arguments, the first argument specifies the directory in which to start the search. The option -name must be followed by a search string, this can also include the wildCards.
—–> find [option(s)]
10. kill Command
This command is used in killing a process. If there is a certain process running and causes the system to stuck or no responding position then use this command.
—–> kill pid[pid refers to process id of a program]
11. Sudo Command
sudo “superuser do”, or “switch user do” gives roots proper permissions to execute a command as another user, such as the superuser. sudo allows a permitted user to execute a command as another user.
—–> sudo [options(s)]
12. passwd Command
This command is used to change the own passwords at any time.
—–> passwd [option(s)] [username]
13. reboot Command
To avoid loss of data, use this program to shut down your system if you need to power off immediately.
—–> reboot [option(s)]
14. clear Command
Last but not the least, this command cleans up the visible area of the console. It has no options.