The Missing Linux Commands Cheatsheet for Noob DevOps

The Missing Linux Commands Cheatsheet for Noob DevOps

ยท

4 min read

Featured on Hashnode

Before we start I want to mention that this is not a tutorial. Treat the article as a reference.

Ok, you just ssh into a remote pc or VPS. Now what? Where do you even start ๐Ÿค”? In fact, where are you? Here comes to rescue this following command...

lost

$ pwd /* shows the current directory path you are in */

pwd stands for print working directory.

Disclaimer: "$" sign in front of all the commands are not necessary for you to type as well. Ignore it. ๐Ÿ˜Š

System Information

Okeyโ€ฆ cool. Now... a little bit of system information would be nice. For that, run:

$ uname -a
# option "a" is for all
# Sample output: 
Linux alihayder 5.4.0-51-generic #56-Ubuntu SMP Mon Oct 5 14:28:49 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Before going further I want to mention a super-duper dope command is called man. It stands for manual. You can see the nice and understandable description for any command using man like the following:

$ man pwd /* it shows the manual for pwd command */

Another important command related to the system information is the following:

$ hostname /* shows the domain name of the server */
$ hostname -d /* shows the domain extension like .com */
$ hostname -i /* shows IP address*/

Don't ignore to read the comments.

This is for showing the current username who logged in.

$ whoami /* outputs the username */

Yet another interesting bonus command is whereis:

$ whereis php /* here php is just an example */
/* essentially this command can find the path of a program. In this example, it is for php */

At this point, you have some idea where you actually are. Now you need to move. Do some stuffs. So, here I am putting the most common and famous commands to enrich this article ๐Ÿ™‚. I am not going to show the usages of these.

$ cd /* change directory */
$ ls /* list all file and folders */
$ ls -la /* list all file and folders with more meta data */
$ mkdir /* create new directory */
$ touch /* create new file */
$ rm /* remove file or folder */
$ cp /* copy files or folders */
$ mv /* move or rename a file or folder*/
$ chmod /* change permission of file and folders */

Most of the Linux OS have nano text editor by default.

$ nano myfile.txt /* open the file in edit mode */
/* following command shows the line number too */
$ nano -c myfile.txt

Friendly TIPS: To search something inside nano press CRTL + W

Error Investigation

Now, consider that something is not working. Maybe the problem resides in Apache, Nginx, or MySQL. So, you hop into the error log folder. It would be nice if you can see the errors in realtime. Here comes the tail command.

$ tail -f error.log /* it is same but additionally, it will watch and update the last 10 lines when new error logs added */
$ tail error.log /* it just shows the last 10 lines of the error.log file */

In your DevOps career if you feel something is wrong with the server hardware capabilities, then you can run this awesome dope command.

$ htop /* run the command and see the magic */

The dope output of the htop command:

Linux htop command sample output

Here you can see the CPU cores usage, RAM usage, process information etc. etc.

Finally, I want to show you two very useful command to see disk usage.

$ df /* it stands for disk free */ 
$ du /* it stands for disk usage */

You can use -h option for both of these commands to print sizes in human-readable format(e.g., 1K 234M 2G)

Bonus

Before I finish here is the last command I want to mention. scp it stands for secure copy. Essentially it's a command for uploading or downloading files from a remote pc to your pc.

Upload the file "exmaple.txt" from a remote pc to your pc

$ scp your_username@remotehost.com:example.txt /some/local/directory

Copy the file "exmple.txt" from your pc to server

$ scp exmple.txt your_username@remotehost.com:/some/remote/directory

Okey bye ๐Ÿ™ƒ. And please don't forget to share the commands that I missed here.