Skip to main content

basic commands in ubuntu console and ec2 instances

Chinese (Simplified)Chinese (Traditional)CzechDanishDutchEnglishFrenchGermanHindiIndonesianItalianKoreanPolishPortugueseRussianSerbianSlovakSpanishThaiBengaliGujaratiMarathiNepaliPunjabiTamilTelugu

Introduction:

For the last couple of days, I have started working in ec2 instances and I have been noticing the fact that there is not a good question answering place for the ec2 instances. So in this blog I will try to notedown some of the common but useful commands you can use in ec2 instances while working in aws cloud machines.

Ubuntu specific normal commands:

1. ls
ls is used to see the lists of file inside a specific directory.
with providing ls -lh parameter, you will get the size, and histories of creation of the files too.
Also, for seeing specific types of files list, you can use * and then extension i.e.
ls -lh *.csv to see csv files.
This specific extension pattern can be used pretty well to see and find out necessary files or so on.
2.cd <DIR>
this command is used to get inside a sub-directory of the current directory; or if you mention a file path inside that, then you can reach to the end of that path.
3.cd .. 
this command is used to get out from a directory and reach its parent directory. i.e. if you have a structure like:
real_files > small files
               >  big files
               > insanely big files
and then you are currently inside small_files; and want to go back to real_files, then you can write
cd ..
and bam! you will reach to real_files.
4. df
df is used to see the memory place left in the machine cluster's storage. Sometimes, if your machine has multiple users, you will not have good understanding of how much memory in total has been consumed. Now, even if you use a 256 GB machine, if your original cluster have no space left, the programs you are running there will get stuck. Therefore, it is always important to keep a check on the total consumed memory and a good practice related is to store the bigger files created to a s3 bucket once processing related them is done.

5.mv <file_name> <file_changed_name>
mv is used to change the name of a specific file or change a file's position from one folder to another folder. For example if you want to move the file example.csv from dir1 under home to dir2 under home, then this following command will do:
mv /home/user_name/dir1/example.csv /home/user_name/dir2/example.csv

6.htop
htop command is used to monitor cpu usage, performance and also which programs are running and which are not. So when you type htop a monitor like this will open in your screen:
where all the cores of your cpu is shown, green to red in terms of that cores usage is also shown. You can press the quit option in the right bottom corner to quit this monitoring screen.

7. vi file_name
for opening, viewing/editing a file, you have to use this command. In case of python files, vi opens the file in vim editor. This opens the data or the script in a new window; which you can just close by writing Esc + :q! or save and close by writing Esc+ :wq
To edit the file, you need to get to --insert-- mode; which needs ctrl + I to be pressed.

Aws and s3 specific:

8. aws s3 cp <provided_file> <received_file>
this format is used to copy data from either s3 to aws or aws to s3. It is always awesome to use aws and s3 bucket combination as the network bandwith is much faster than local to aws or local to s3 bandwith, which is the same with your office or home's network services. Between aws and s3, network is as fast as several 100MBPS.
Anyway, in this format, provided_file is the name of the file you are going to get. and the received_file is the name of the file you are going to name once that file is received in that another place.
So for example, you have a file named example.csv, inside the path /home/user_name/dir1/dir2 in your ec2 instance. Now, you want to send it to s3/bucket_1/bucket2 and you want to rename it as reward_policy_2017.csv.
So then your above format will look like:

aws s3 cp /home/user_name/dir1/dir2/example.csv s3://bucket_1(special format)/bucket2/reward_policy_2017.csv

the special format of the first bucket is according to internal rules of aws buckets so that the path is perceived as a valid url by the internal program. We will describe that details later in another post.

9.tmux sessions
Not all programs start and end within a minute, specially if you are going to cloud to solve it. Now the issue with running programs on cloud is that, if your screen goes off and the console turns off, or you are disconnected from internet, then the program also shuts down. The irritating message : broken pipe: <ip address>.. sort of messages come, informing you that your machine is disconnected from the local machine.
Now the thing is that, you run important programs, but most of them run for hours. So you need to turn your screen and console, or heck, even the local machine off. So there comes tmux.
tmux can be also used in local machines, but it is a life saver in ec2 instances. What you need to do is that, you have to open a tmux session, which is nothing but another console, which can be run in background of the current console; and the main advantage of tmux is that, even if you turn off the local machine, tmux session runs and completes the operation. The basic commands related to tmux are the following:
(1) to open a new tmux session:
$ tmux new -s session_name
(2) to open a already created tmux session:
$ tmux attach -t session_name
(3) to close a tmux session screen but not the session itself:
press [ctrl] + [B] together; then d for detaching it
(4) to exit a tmux session altogether:
write exit and the window will close.

These are some of the very basic things I use on a regular basis to work on the ec2 instances. Comment below if you want to know something specific or want me to include some specific commands.

Comments

Popular posts from this blog

Tinder bio generation with OpenAI GPT-3 API

Introduction: Recently I got access to OpenAI API beta. After a few simple experiments, I set on creating a simple test project. In this project, I will try to create good tinder bio for a specific person.  The abc of openai API playground: In the OpenAI API playground, you get a prompt, and then you can write instructions or specific text to trigger a response from the gpt-3 models. There are also a number of preset templates which loads a specific kind of prompt and let's you generate pre-prepared results. What are the models available? There are 4 models which are stable. These are: (1) curie (2) babbage (3) ada (4) da-vinci da-vinci is the strongest of them all and can perform all downstream tasks which other models can do. There are 2 other new models which openai introduced this year (2021) named da-vinci-instruct-beta and curie-instruct-beta. These instruction models are specifically built for taking in instructions. As OpenAI blog explains and also you will see in our

Can we write codes automatically with GPT-3?

 Introduction: OpenAI created and released the first versions of GPT-3 back in 2021 beginning. We wrote a few text generation articles that time and tested how to create tinder bio using GPT-3 . If you are interested to know more on what is GPT-3 or what is openai, how the server look, then read the tinder bio article. In this article, we will explore Code generation with OpenAI models.  It has been noted already in multiple blogs and exploration work, that GPT-3 can even solve leetcode problems. We will try to explore how good the OpenAI model can "code" and whether prompt tuning will improve or change those performances. Basic coding: We will try to see a few data structure coding performance by GPT-3. (a) Merge sort with python:  First with 200 words limit, it couldn't complete the Write sample code for merge sort in python.   def merge(arr, l, m, r):     n1 = m - l + 1     n2 = r- m       # create temp arrays     L = [0] * (n1)     R = [0] * (n

What is Bort?

 Introduction: Bort, is the new and more optimized version of BERT; which came out this october from amazon science. I came to know about it today while parsing amazon science's news on facebook about bort. So Bort is the newest addition to the long list of great LM models with extra-ordinary achievements.  Why is Bort important? Bort, is a model of 5.5% effective and 16% total size of the original BERT model; and is 20x faster than BERT, while being able to surpass the BERT model in 20 out of 23 tasks; to quote the abstract of the paper,  ' it obtains performance improvements of between 0 . 3% and 31%, absolute, with respect to BERT-large, on multiple public natural language understanding (NLU) benchmarks. ' So what made this achievement possible? The main idea behind creation of Bort is to go beyond the shallow depth of weight pruning, connection deletion or merely factoring the NN into different matrix factorizations and thus distilling it. While methods like knowle