Basic Linux and Postgres Commands

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Basic Linux and PostGres Commands

R. Uday kiran

Abstract In this book, we will cover basic commands on linux, VIM, PostGres, and
Shell Scripting

1 Linux Commands

Table 1 Basic linux commands


S. No. Command Purpose
1 mkdir <dirName> create a directory
2 cd <dirName> change to directory
3 cd .. move to one directory up
4 ~ denotes home directory
5 cd ~ move to home directory
6 cat <fileName> print the file contents
7 vim <fileName> edit the file using vim editor
8 head −𝑘 <fileName> print top-𝑘 lines in a file. E.g., head -10 test.txt
9 tail −𝑘 <fileName> prints last top-𝑘 lines in a file. E.g., tail -10 test.txt
10 cp <sourceFile> <destinationFile> copies contents in sourceFile to destinationFile. E.g., cp test.txt test1.txt
11 mv <sourceFile> <destionationFile> renames sourceFile to destinationFile.
12 rm -rf <fileName> permanently deletes a file
13 history Lists the previous commands executed by a user
14 !! short cut to execute the previous command
15 !𝑛𝑢𝑚𝑏𝑒𝑟 executes the old command in history. E.g., !426
16 time 𝑐𝑚𝑑 Outputs the time taken to execute a command

R. Uday kiran
The University of Aizu, Aizu-Wakamatsu, Fukushima, Japan e-mail: [email protected]

1
2 R. Uday kiran

Table 2 Network commands


S. No. Command Purpose
1 whoami prints the username
2 hostname prints name of the machine
3 ssh userName@Server login into the server machine
4 scp fileName userName@Server:. Copies the file from local machine to home directory of remote server
5 scp userName@Server:Directory/fileName fileName copies the file from remote server to local machine
6 ifconfig prints the ipaddress of the machine
7 ping serverAddress checks the connection to remote server
8 netstat shows the network status

Table 3 Administrator commands


S. No. Command Purpose
1 su super user
2 sudo <command> execute the command as a super user
3 ps -aux Lists all process running on a machine
4 ps -aux| grep "searchWord" Lists only those process containing search word
5 kill -9 𝑝𝑖𝑑 kill a process whose pid is 𝑝𝑖𝑑
6 killall -u 𝑢𝑠𝑒𝑟 𝑁 𝑎𝑚𝑒 kills all process of a user
7 df Lists the available disk space
8 yum install 𝑝𝑎𝑐𝑘 𝑎𝑔𝑒𝑁 𝑎𝑚𝑒 installs a package
9 reboot reboots the server machine
10 top lists the running processes
11 chmod Changes the file permissions

Table 4 Vim commands


S. No. Command Purpose
1 𝑖 press 𝑖 button to type text in vim
2 𝐸 𝑆𝐶 press 𝐸 𝑆𝐶 button to execute commands
3 : to execute commands
4 :𝑤 to save
5 :𝑞 to quit
6 : 𝑤𝑞 save and quit
7 : 𝑞! quit without saving
8 \𝑠𝑒𝑎𝑟 𝑐ℎ𝑊 𝑜𝑟 𝑑 finds the search word in the file. Press 𝑛 button to move across search words
9 :< 𝑙𝑖𝑛𝑒𝑁 𝑜 > Moves cursor to the corresponding line number. E.g,. : 10 moves to line 10
10 dd deletes a line
11 control + a moves the cursor to the beginning of the line
12 W or w move forward to starting of each word
13 B or b move backward to starting of each word
14 $ move to end of the line

Table 5 NUMA commands


S. No. Command Purpose
1 numactl runs processes with a specific NUMA scheduling or memory placement policy.
2 numactl –cpunodebind=0 –membind=0 https://linux.die.net/man/8/numactl for more info
3 NUMAD
4 NUMASTAT
5 turbostat
Basic Linux and PostGres Commands 3

2 Energy Machine

Table 6 Commands
S.No. Command Text
1 yokogawa-wt1800 store-start --host=192.168.88.135 Start the server
2 yokogawa-wt1800 store-reset --host=192.168.88.135 stop the server
3 yokogawa-wt1800 fetch --host=192.168.88.135 Fetch the data
4 mv 2020* <folders/fileName.csv> Moving the fetched data into a directory
5 yokogawa-wt1800 clean --host=192.168.88.135 Delete the data in the machine
6 /opt/reboot-yokogawa.sh Reboot the machine
7 yokogawa-wt1800 Help
8 echo ":RATE?"| yokogawa-wt1800 sh --host=192.168.88.135 to find the update rate
9 echo ":RATE 50MS" | yokogawa-wt1800 sh --host=192.168.88.135 Update the rate

Commands to execute when someone kills a data mining process:


1. yokogawa-wt1800 store-reset --host=192.168.88.135
2. yokogawa-wt1800 fetch --host=192.168.88.135
3. rm -rf 2020*
4. yokogawa-wt1800 clean --host=192.168.88.135
Note: The command, mv 2020* ./ 𝑓 𝑜𝑙𝑑𝑒𝑟/i_ 𝑓 𝑜𝑙𝑑𝑒𝑟.𝑐𝑠𝑣, gives an error if there
are multiple files of 2020* in the same folder. So please delete the old ones using
‘rm -rf 2020*’.

3 PostGres and PostGIS

Additional material to learn


1. learn different data types of attributes. E.g., int, double, blob, char, and varchar.
2. Learn how to use regular expressions in where clause using like.
3. Learn the timestamp data types and how to query the attributes.
4. Learn indexes. E.g., primary key, foreign key and unique key.
5. Learn Nested queries.
Administrator commands:
1. pg_dump -U username -W -F t dbName > fileName.tar. This commands
creates the backup of dbName and saves it as fileName.tar
2. pg_dumpall -U postgres > file.sql This commands creates the backup of all
databases that exist in the postgres server.
3. Restoring a database: create database 𝑑𝑏𝑁𝑎𝑚𝑒. Next, execute the following
command: pg_restore –dbname=𝑑𝑏𝑁𝑎𝑚𝑒 –create –verbose fileName.tar
4 R. Uday kiran

S. No. Command Purpose


1 create database 𝑑𝑏 𝑁 𝑎𝑚𝑒 creates a database with name 𝑑𝑏 𝑁 𝑎𝑚𝑒
2 \c 𝑑𝑏 𝑁 𝑎𝑚𝑒 connect to the database 𝑑𝑏 𝑁 𝑎𝑚𝑒
3 \l list all the databases in the postgres
4 \d list all the tables in the 𝑑𝑏 𝑁 𝑎𝑚𝑒
5 \d 𝑡 𝑎𝑏𝑙𝑒𝑁 𝑎𝑚𝑒 lists the attributes in 𝑡 𝑎𝑏𝑙𝑒𝑁 𝑎𝑚𝑒
6 Control + X to cancel a command that is currently being executed
7 Control + C Copy the selected command
8 Control + V paste the copied command
9 Control + D to exit from the postgres database
10 create table 𝑡 𝑎𝑏𝑙𝑒𝑁 𝑎𝑚𝑒(attribute datatype constraints, · · · ) creates table 𝑡 𝑎𝑏𝑙𝑒𝑁 𝑎𝑚𝑒
11 drop database 𝑑𝑏 𝑁 𝑎𝑚𝑒 delete the database 𝑑𝑏 𝑁 𝑎𝑚𝑒
12 delete from 𝑡 𝑎𝑏𝑙𝑒𝑁 𝑎𝑚𝑒 deletes all tuples that exist in 𝑡 𝑎𝑏𝑙𝑒𝑁 𝑎𝑚𝑒
13 delete from 𝑡 𝑎𝑏𝑙𝑒𝑁 𝑎𝑚𝑒 where 𝑎𝑡𝑡𝑟 𝑖𝑏𝑢𝑡𝑒 =???? deletes all tuples whose attribute = ???
11 select * from 𝑡 𝑎𝑏𝑙𝑒𝑁 𝑎𝑚𝑒 where · · · selects the data from table.
12 alter table 𝑡 𝑎𝑏𝑙𝑒𝑁 𝑎𝑚𝑒 add/delete · · · alter the tables
13 update table 𝑡 𝑎𝑏𝑙𝑒𝑁 𝑎𝑚𝑒 · · · updates the values of tuples in 𝑡 𝑎𝑏𝑙𝑒𝑁 𝑎𝑚𝑒

You might also like