Linux is one of the most widely used operating systems that is being used for different requirements and developments. Most of us might have used it for some time in our development career. While working on Linux knowing the right command saves a lot of time and headache. I generally refer to the below article to find commands that I use most frequently.
Linux Commands Cheat Sheet | Tips and Tricks
The Linux commands that every software developer should know.
medium.com
1. ifconfig
ifconfig
— Interface configurator.
This command is used to display the route and the network interface. It is also used for initializing an interface, configuring it with an IP address, and enabling or disabling it.
Syntax : ifconfig
2. traceroute
traceroute
— Used for troubleshooting the network. It detects the delay and determines the pathway to the specified target.
- It provides the names and identifies every device on the path.
- It follows the route to the destination
- It determines where the network latency comes from and reports it.
Syntax : traceroute
Note : If you don’t have the traceroute service installed in your system, you can install it using the following command:
curl //www.google.com
0
Command:
curl //www.google.com
1The output of the above command will have the following information: the specified hostname, size of the packets, the maximum number of hops required, the IP address.
Note: To avoid the reverse DNS lookup, add -n in the command syntax.
Command:
curl //www.google.com
2The output indicates the network delays. The asterisks shown in the output indicate a potential problem in reaching that host. They indicate the packet loss during communication to the network.
Generally, the traceroute command sends UDP packets. It can as well send TCP or ICMP packets.
- To specifically send in ICMP, use this,
Command:
curl //www.google.com
3- To send a variant of TCP, use this,
Command:
curl //www.google.com
43. tracepath
curl //www.google.com
5 — similar to the traceroute command.It is used to detect network delays. However, it doesn’t require root privileges and is installed in Ubuntu by default.
It traces the route to the specified destination and identifies each hop in it. If your network is weak, it recognizes the point where the network is weak.
Syntax:
curl //www.google.com
6Example:
curl //www.google.com
74. ping
Linux ping is one of the most used network troubleshooting commands. It checks for the network connectivity between two nodes.
curl //www.google.com
8 stands for Packet INternet Groper.The ping command sends the ICMP echo request to check the network connectivity. It keeps executing until it is interrupted. We can use the ctrl+c key to interrupt the execution.
Syntax :
curl //www.google.com
9Example :
curl //example.{one, two, three}.com
0We can also use the IP address to ping directly. We can limit the number of packets by including “-c” in the ping command.
Syntax :
curl //example.{one, two, three}.com
15. netstat
Linux netstat command refers to the network statistics.
It provides statistical figures about different interfaces which include open sockets, routing tables, and connection information.
Syntax:
curl //example.{one, two, three}.com
2Output:
vikram@100200300 ~ % netstat
Active Internet connections
Proto Recv-Q Send-Q Local Address Foreign Address [state]
tcp4 0 0 1.2.3.4.5865 4.3.2.1.https ESTABLISHED
tcp4 0 0 1.100.1.3.542 1.40.1.17.18903 SYN_SENT
Observe the output displaying all the open sockets.
Variations in netstat command:
Below are a few variations of the netstat command used.
- To display the programs, use below
Syntax:
curl //example.{one, two, three}.com
3- To get the details of the ports, use below
Syntax:
curl //example.{one, two, three}.com
4This gives detailed statistics of all the ports.
- To get the information of the routing table, use below
Syntax:
curl //example.{one, two, three}.com
5This gives information related to the routing table.
6. hostname
Linux hostname is the simple command used to view and set the hostname of a system.
Syntax:
curl //example.{one, two, three}.com
6To set the hostname —
Use the syntax below to set the hostname.
Syntax:
curl //example.{one, two, three}.com
7The hostname set through this command is not permanent. It will be reset to the name in the hostname file back when the system reboots.
To permanently set a hostname, you have to re-write the hostname in the hostname file, present on the server. Once set, you have to reboot the box.
- In Ubuntu, /etc/hostname file is used.
- In RHEL, /etc/sysconfig/network is used.
7. curl
curl is a command-line tool to transfer data to or from a server, using any of the supported protocols [HTTP, FTP, IMAP, POP3, SCP, SFTP, SMTP, TFTP, TELNET, LDAP, or FILE].
curl:
Syntax:
curl //example.{one, two, three}.com
8Example:
The most basic use of
curl //example.{one, two, three}.com
9 is typing the command followed by the URL.curl //www.google.com
This displays the content of the URL on the terminal. The URL syntax is protocol dependent and multiple URLs can be written as sets like:
curl //example.{one, two, three}.com
URLs with numeric sequence series can be written as:
curl ftp://ftp.example.com/file[1-20].jpeg
Below Options can be used with the curl command:
- o: using this flag we can save the downloaded file on the local machine with the name provided as the parameters.
Syntax:
curl -o [file_name] [URL...]
Example:
curl -o curl_file.html //www.google.com
8. wget
curl ftp://ftp.example.com/file[1-20].jpeg
0 is a command-line utility for downloading files from the web.- With
curl ftp://ftp.example.com/file[1-20].jpeg
1, you can download files usingcurl ftp://ftp.example.com/file[1-20].jpeg
2,curl ftp://ftp.example.com/file[1-20].jpeg
3, andcurl ftp://ftp.example.com/file[1-20].jpeg
4 protocols. curl ftp://ftp.example.com/file[1-20].jpeg
1 provides several options allowing you to download multiple files, resume downloads, limit the bandwidth, recursive downloads, download in the background, mirror a website, and much more.
Syntax :
curl ftp://ftp.example.com/file[1-20].jpeg
6Let’s see some examples:
- To simply download a webpage:
curl ftp://ftp.example.com/file[1-20].jpeg
7- To download the file in the background:
curl ftp://ftp.example.com/file[1-20].jpeg
8- To overwrite the log while downloading the file using the
curl ftp://ftp.example.com/file[1-20].jpeg
1 command:
curl -o [file_name] [URL...]
0- Resume a partially downloaded file:
curl -o [file_name] [URL...]
1- To try a given number of times:
curl -o [file_name] [URL...]
29. whois
Linux whois command is used to fetch all the information related to a website. You can get all the information about a website including the registration and the owner information.
Syntax:
curl -o [file_name] [URL...]
3Example:
curl -o [file_name] [URL...]
410. scp
SCP [secure copy] is a command-line utility that allows you to securely copy files and directories between two locations.
With
curl -o [file_name] [URL...]
5, you can copy a file or directory:- From your local system to a remote system.
- From a remote system to your local system.
- Between two remote systems from your local system.
When transferring data with scp, both the files and password are encrypted so that anyone snooping on the traffic doesn’t get anything sensitive.
SCP Command Syntax:
Let’s review the basic syntax of the
curl -o [file_name] [URL...]
5 command.curl -o [file_name] [URL...]
7curl -o [file_name] [URL...]
8 - scp options such as cipher, ssh configuration, ssh port, limit, recursive copy, etc.
Local files should be specified using an absolute or relative path, while remote file names should include a user and host specification.
curl -o [file_name] [URL...]
5 provides several options that control every aspect of its behavior. The most widely used options are:curl -o curl_file.html //www.google.com
0 — Identity_file
Selects the file from which the identity [private key] for public-key authentication is read. This option is directly passed to ssh[1].curl -o curl_file.html //www.google.com
1 - This option tellscurl -o [file_name] [URL...]
5 to copy directories recursively.
11. ssh
curl -o curl_file.html //www.google.com
3 stands for Secure Shell. It is a protocol used to securely connect to a remote server/system. curl -o curl_file.html //www.google.com
3 is secure in the sense that it transfers the data in encrypted form between the host and the client. It transfers inputs from the client to the host and relays back the output. curl -o curl_file.html //www.google.com
5 runs at curl -o curl_file.html //www.google.com
6Syntax:
curl -o curl_file.html //www.google.com
7Example:
curl -o curl_file.html //www.google.com
8The
curl -o curl_file.html //www.google.com
9 flag — To use a private key for a specified hostname and not the default ssh key that is located in ifconfig
0You can consider following me to get notified whenever I publish such helpful articles.
That’s all for this article. Thank you for reading it. I hope I have made the above commands very clear. I write on multiple topics that include Java Programming, Data structure, and Big O, SQL, GIT, Linux, Software development, etc.