Today let’s focus on a Linux command list that will be useful to a newbie who is just starting off with Linux. It doesn’t matter whether you are a web developer or software engineer if you are going to use Linux you have to learn these. These commands are used day to day to get done work.
I don’t want to talk about the typical command list that is on the internet rather I would like to go beyond that and introduce couple of useful Linux commands. For the below commands you can find tons of tutorials.
So let’s move on.
Linux Command List
1. Remote Login
- ssh – OpenSSH SSH client
ssh also known as Secure Shell is a Linux command that can used to access a remote instance securly. It uses an encripted channel to provide a text-based shell session on the remote instance. So you will be able to run commands without being physically present near the remote machine.
2. Remote Copy
- rsync – remote (and local) file-copying tool
- scp – secure copy files
Both rsync Linux command and scp Linux command can be used as file transfer programs. They allow you to copy files to a remote instance. If we compare rsync and scp, scp provides a secure way to copy files over a given network by encrypting traffic. In other way rsync is much faster due to it’s algorithm and mechanism that is used to copy data. If your data are not sensitive use rsync since it’s faster as well as it can be used for file synchronisation.
rsync -azhP local_files_path username@remote_host_ip:remote_path
rsync -azhP /var/www email@example.com:/var/www/
- a – archive mode
- z – compress file data during the transfer
- h – output numbers in a human-readable format
- P – show progress
Now let’s focus on the scp Linux command.
scp -r local_files_path username@remote_host_ip:remote_path
scp -r /var/www firstname.lastname@example.org:/var/www/
- r – recursively copy entire directories.
If you are interested in getting more information on rsync you can refer this article.
3. Network Tools
Let’s focus on a Linux command list that are used to debug and monitor network activity. So netstat is a Linux command that print network connections on particular instance.
- n – show numerical addresses instead of trying to determine symbolic host, port or user names.
- p – show the PID and name of the program to which each socket belongs.
- l – show only listening sockets
- t/u – tcp/udp
Moving on ping is a Linux command that is used to test connectivity between two nodes.
ping google.com ping 192.168.1.1
Last but not least dig is a Linux command that is used as a DNS lookup utility.
4. service – Run a System V init script
In simple terms service is a Linux command that is used to start or stop a particular service in Linux. So you might be wondering why use the service command in linux? Answer is here.
service service_name start|stop|restart
service apache2 restart service mysql start
5. tail – Output The Last Part of Files
- tail -f
If you want to moniter what’s happening with a log file there is a Linux command for that. Usually we use tail command to monitor a output from a log file that is continuously growing. You can get a realtime update about the file as the file grows. Here tail -f and the tailf offer the same functionality.
tailf filename tail -f filename
tailf /var/log/apache2/error.log tail -f /var/log/apache2/error.log
- f – output appended data as the file grows
6. Text Editor/Reader
vi is a text editor and vim is an improved text editor based on vi with loads of features. You can read this article as an introduction to vim.
vim filename vi filename
vim /etc/apache2/apache2.conf vi /etc/apache2/apache2.conf
less is a file reader and the speciality of less is it does not have to read the entire input file before starting. If you are opening a large file it’s better to use less rather than using vi or vim.
7. Search Files & Folders
In Linux there are couple of ways to search for what you want. Let’s focus on couple of Linux commands to get the searching done. One of the most common and easiest way to search for a file is locate Linux command. It allows to find the file by name.
The Linux command locate does not search for recently created file. If that case you have to use updatedb Linux command. updatedb creates or updates a database used by locate. Once you run the updatedb command database will be updated. Moving on to find which will search for files in a directories.
find /path/to/search -iname file_name
find /etc -iname apache2.conf
Future more you can specify whether you want to search for a file or directory by using -type.
find /etc -type f -iname apache2.conf find /etc -type d -iname apache2.conf
8. screen – Multiplexes a Physical Console
One of the most useful but lesser known Linux command would be screen. In simple terms the screen program allows you to use multiple windows in Unix. In other words the screen command lets you detach from a terminal session and then attach it back at a later time.
I have a seperate article written on this topic starting from what’s screen to usage to real world examples. Please refer this link for more information.
9. grep – Pattern Search
grep Linux command allows you to print lines matching a pattern. In other words grep allows you to search for a pattern in your output. You can use the grep command inconjuction with other commands as below.
history | grep ssh less /etc/apache2/apache2.conf | grep -n Include
- n – output the line numbers with the output
Even more grep can be also used as a search tool.
grep -nir search_term /path/to/search
grep -nir apache2 /etc/
- n -output the line numbers with the output
- i – ignore case
- r – read all files under each directory, recursively
Above command will search for apache2 search term inside the etc directory recursively including all files and directories..
10. Process viewer
One last Linux command before we wind up the article that is used to monitor your processes. It’s important have an idea about the processes that are currently being executed in your instance. For that you can use the top Linux command. I know the output of the top command is confusing but this tutorial will help you to understand top command very easily.
Moving on htop is a similar command as top but more informative and easy to understand. It’s an interactive process viewer. You will have to install the htop to start using it.
apt-get install htop
Then just type
Tips & Tricks
Let me give you a way to get more information about any given Linux command that you prefer without going through a much of a hassle. For that you can use the man or info Linux commands. man and info are reference manuals that are integrated to Linux.
man command_name info command_name
man scp info scp
So that’s it about Linux commands. If you have any questions let me know in the comments below. Your feedback is highly appreciated(happy-face).