If you’re new to Linux, using the terminal can be a little tedious. Newer Linux distros like Linux Mint have a great graphical interface, but the Linux kernel is the kernel, which means using the command line.
Even if you’re a Windows user, you’ve probably had to open a command prompt window at some point in your life to complete a task. On the latest version of Windows, Windows 10, you can even install the Ubuntu Bash shell on Windows and run Linux commands directly from Windows!
In this article, I’m going to go over some of the really basic Linux commands that are common to almost all Linux distributions. Since bash is the most popular shell I also use, I will use this syntax for all commands. Also, I will mention some of the more useful arguments for each command, but there are others that can be found in the man pages.
1.ls (contents of the list)
In my opinion, the first command you should know is the ls command. This command displays the contents of the current working directory. If you just type ls and hit Enter, you get a very simple list of files and folders in the current directory.
Most Linux distributions will highlight directories in a different color, such as green. Files usually have a standard shell prompt color, which is gray in my case. Without any arguments, ls is boring. If you use -a with ls, you should be able to see all hidden files.
– /
Anything that starts with a dot is a hidden file or directory. All hidden directories are dark blue which is difficult to see. Another useful argument is the -l option, as shown below.
This gives you a long list of files and folders with much more information like permissions, links, user, group, size, and last modified date. If you don’t know how to interpret permissions, be sure to read my post on Linux permissions.
2. cd (change directory)
Once you can list the contents of a directory, it is helpful to know how to switch to a different directory. By default, when you open a bash shell, you always start your home directory. This is indicated by the tilde character (~) at a shell prompt.
The cd command is how you change directories in Linux. There really isn’t a whole lot to learn with CD, but there are a few acronyms. One good option is to just type cd and hit Enter. This will always take you back to your home directory wherever you are.
Alternatively, you can use an absolute path if you want to get into a directory that is not accessible by a relative path. In the example below, I have to use an absolute path starting at root (/) to navigate to etc / ssh.
3.man (help pages)
The man command is probably one of the most useful commands in Linux. Even experienced Linux users cannot remember all the arguments of a Linux command. The man pages provide detailed information on all command arguments.
The syntax is also very simple. It’s just a person followed by the command you want to know about. In the screenshot above, I did man ls to learn more about the ls command. One of the useful arguments to man is -k, which will allow you to search for all commands using the keyword.
Above, I searched for the zip keyword and got back all commands that have the word zip in their names or descriptions. It’s a handy way to find commands that you might never have known about.
Along with man, you can use another command called info to get more examples of how to use the command. Just enter the command info to open the information page for that command.
4. Touch (Create File).
If you want to quickly create a new file, the easiest way is to use touch command. Actually the touch command is used to change the time stamp in a file, but another use is to create a new file.
There are many ways to create files in Linux, and later on you will probably never use touch to create a file, but it’s very convenient in the beginning.
If the file already exists when using the touch command, it simply updates the last accessed and last modified timestamps for the file as shown above.
5.cat (Concatenate Files and Print)
Another useful command is cat. The main function of cat is to concatenate multiple files, but it can also be used to output the contents of a file to standard output (that is, to the screen).
You can use the -n argument to add line numbers to the output. If you use the -b option, it will only add line numbers to those lines that are not empty. If you use cat on a file that is longer than the height of your terminal window, only the bottom of the file will be displayed. You can pipe the output of cat to less or the more to view the contents of the file page by page.
6.mkdir (create directory)
At some point you will want to create directories to better organize your data, and this is where the mkdir command comes in. You can use relative or absolute paths to create directories with this command.
In the example above, I created two directories in my home directory using a relative path and an absolute path. If you need to create multiple hierarchical directories at the same time, you need to use the -p argument.
In the example above, I used the -p argument to create the Aseem, Data and Pictures directories at the same time, although none existed.
7.RM (remove)
The rm command is a powerful command that can be used to remove files and directories. The rm command can delete directories that contain files and directories.
To delete a file, just enter the file name. If you need to remove a directory that is not empty, you need to use the -r argument. It’s also a good idea to use the -i and -v arguments when using rm as it will ask you before removing anything.
So, these are seven really simple yet common commands that you need to know in Linux to get started. There are many more, and soon I will be posting new articles for beginners about other commands and how to use them. If you have any questions, please leave a comment. Enjoy!
–