Subscribe To Our Newsletter
You will receive our latest post and tutorial.
Thank you for subscribing!

required
required


Linux Zip

Zip

Zip is a compression tool. Zip files have the .zip extension. zip is very useful when you are on a limited bandwidth and need to send a big file over the internet.

zip {options} {zipFilename} {files…}

zip zipfile.zip test.txt test1.txt

unzip {zipFilename}

unzip myfile.zip

 

Gzip

gzip command compresses files. Each single file is compressed into a single file. The compressed file consists of a GNU zip header and deflated data.

If given a file as an argument, gzip compresses the file, adds a “.gz” suffix, and deletes the original file. With no arguments, gzip compresses the standard input and writes the compressed file to standard output.

 

gzip {options} {files…}

gzip test.txt test1.txt

gunzip {gzipFile}

gunzip test.gz

 

 

 

 

March 6, 2020

Linux Vi Editor

vi stands for visual editor and comes as one of default applications in every Linux/Unix system. The vi editor has two modes.

  • Command Mode: In command mode, actions are taken on the file. The vi editor starts in command mode. Here, the typed words will act as commands in vi editor. To pass a command, you need to be in command mode.
  • Insert Mode: In insert mode, entered text will be inserted into the file. The Esc key will take you to the command mode from insert mode.

If you are not sure which mode you are in, press Esc key twice and you’ll be in command mode.

 

Create a file with vi {filename}

vi test.txt
~                                                                                                                                                                                                     
~                                                                                                                                                                                                     
~                                                                                                                                                                                                     
~                                                                                                                                                                                                     
~                                                                                                                                                                                                     

 

Save file

// save and quit
:wq

// save
:w

// quit
:q

// save as filename
:w fname

// save and quit
ZZ

// quit and disregard work
:q!

// quit and save qork
:wq!

 

How to delete on command mode

// delete current character
x

// Replace the current character
r

// Switch two characters
xp

// Delete the current line
dd

// Delete the current line from current character to the end of the line
D

// delete from the current line to the end of the file
dG

 

Repeat and undo

// Undo the last command
u

// repeat the last command
.

 

Copy, Cut, and Paste

// Delete a line
dd

// (yank yank) copy a line
yy

// Paste after the current line
P

// Paste before the current line
p

// Delete the specified n number of lines
{n}dd

// Copy the specified n number of lines
{n}yy


 

Search string

// Forward search for given string
/{string}

// Backward search for given string
?{string}

// Forward search string at beginning of a line
/^{string}

// Forward search string at end of a line
/{string}$

// Go to next occurrence of searched string
n

// Search for the word he (and not for there, here, etc.)
/\<he\>

// Search for place, plbce, and plcce
/pl[abc]ce

 

Replace all

:{startLine,endLine} s/{oldString}/{newString}/g

// Replace forward with backward from first line to the last line
:1,$ s/readable/changed/

 

  

 

 

March 6, 2020

Linux System Admin

A system administrator manages configuration, upkeep and reliable operations of computer operations. Sysadmin handles servers, has to manage system performance and security without exceeding the budget to meet users need.

A system administrator only deals with terminal interface and hence it is very important to learn and become master in commands to operate from terminal.

Uptime

The uptime command tells us how long a system has been running.

folaukaveinga@Folaus-MacBook-Pro-3 sidecar-api-partner % uptime
18:34  up 19:47, 4 users, load averages: 3.05 2.49 2.30

From the left, it shows,

  • currrent system time
  • duration for which system has been running (system is running since 18 minutes)
  • number of users logged in (2 users are logged in)
  • system load average CPU load for past 1, 5 and 15 minutes.

 

WGET

wget is used to download files onto the current directory.

wget {url}

folaukaveinga@Folaus-MacBook-Pro-3 Downloads % wget google.com  
--2020-11-09 21:31:28--  http://google.com/
Resolving google.com (google.com)... 2607:f8b0:400f:805::200e, 172.217.11.238
Connecting to google.com (google.com)|2607:f8b0:400f:805::200e|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.google.com/ [following]
--2020-11-09 21:31:28--  http://www.google.com/
Resolving www.google.com (www.google.com)... 172.217.2.4, 2607:f8b0:400f:800::2004
Connecting to www.google.com (www.google.com)|172.217.2.4|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html.1’

index.html.1                                          [ <=>                                                                                                        ]  12.62K  --.-KB/s    in 0s      

2020-11-09 21:31:30 (88.6 MB/s) - ‘index.html.1’ saved [12918]

 

wget -o {filename} {url}

 To save file with a different name option O can be used.

wget -o google.html google.com

Download a whole website for local use

wget --mirror -p --convert-links -P {path} {url}

// example. 
wget --mirror -p --convert-links -P ./yourtimer https://yourtimer.io

–mirror – it enables the options suitable for mirroring

-p – download all files which are necessary to display html page

–convert-links – after downloading, convert links into documents for local viewing

-P ./ local dir ? save whole website in the specified local directory.

 

wget –tries={number} {url}

By default, wget command tries 20 times to downlod a file. This problem generally come when a large file is getting downloaded and internet connection is weak.

Here, you can set number of attempts which wget should make to download a file.

wget -O yourtimer.html --tries=10 https://yourtimer.io

 

SFTP

SFTP to a server with ssh key.

sftp -o IdentityFile={ssh-private-key} user@host

 

folaukaveinga@Folaus-MacBook-Pro-3 ~ % sftp -o IdentityFile=~/.ssh/testa/server_ssh_key ubuntu@qa.testa.com 
Connected to qa.testa.com.
sftp> ls
testa.sql
sftp>

// use quit or ! to exit

 

sftp upload

PUT {filename}

sftp> PUT test.txt

// upload multiple tiles
sftp> MPUT *.txt

 

 

sftp download

GET -p  {remoteFile} {localFilename}

sftp> GET -p bin-deploy.sh bin.sh

// download multiple files
sftp> MGET -p *.txt

 

 

March 6, 2020

Linux Networking

Netstat

Netstat stands for network statistics. Network sockets can either be connected or waiting for a connection. The connections use networking protocols like  Transport Control Protocol (TCP) or User Datagram Protocol UDP. They use Internet Protocol addresses and network ports to establish connections.

Sockets have two main states: They are either connected and facilitating an ongoing network communication, or they are waiting for an incoming connection to connect to them.  There are other states, such as the state when a socket is midway through establishing a connection on a remote device, but putting transient states aside, you can think of a socket as either being connected or waiting (which is often called listening).

The listening socket is called the server, and the socket that requests a connection with the listening socket is called a client. These names have nothing to do with hardware or computer roles. They simply define the role of each socket at each end of the connection.

The netstat command lets you discover which sockets are connected and which sockets are listening. Meaning, it tells you which ports are in use and which processes are using them. It can show you routing tables and statistics about your network interfaces and multicast connections.

The functionality of netstat has been replicated over time in different Linux utilities, such as ip and ss. It’s still worth knowing this granddaddy of all network analysis commands, because it is available on all Linux and Unix-like operating systems, and even on Windows and Mac.

netstat -a 

The ‘-a’ option is used to display all the existing connections.

netstat- a

netstat -at

To display only the TCP connection, execute the command with the ‘t’

netstat- at

netstat -au

To display only UDP connection, execute it with ‘u’ option 

netstat -au

 

netstat -tnl  

The listening connections are such connections that are available for connection requests. Any network process keeps an open port for the listening incoming connection requests.

netstat -tnl

 

netstat -rn  

The ‘r’ option is used to display the kernel routing information. It will display the same output as route command.

netstat -rn

 

netstat -i 

We can also display information about the network interfaces by using the netstat command. To display the network interfaces, execute the command with ‘i’ option

netstat -i

 

netstat -ct 

To display the netstat output continuously, execute the command with the ‘c’ option

netstat -ct

 

nslookup

This command is also used to find DNS related query.

nslookup {domainName}

 

 

host

host command displays domain name for given IP address or vice-versa. It also performs DNS lookups related to the DNS query.

host {hostname}

host -t ns

The ‘ns’ option with ‘-t’ arguments are used to display the domain name servers.

host -t ns {hostname}

 

Curl

curl is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction.

curl {option} {url}

 

 

March 6, 2020

Linux Users

 

su

The su command allows you to run a shell as another user.

su {username}

su root

 

useradd

useradd commands you can add a user.

useradd -m -d /home/<userName> -c “<userName>” <userName>

useradd -m -d /home/lisa -c "lisa" lisa

 

userdel

To delete a user account userdel command is used. By using userdel -r option, you can delete home directory along with user account.

userdel -r {username}

userdel -r lisa

 

usermod

The command usermod is used to modify the properties of an existing user.

usermod -c <‘newName’> <oldName>  

usermod -c 'lisa' lisak

 

You can change the shell mode with usermod command for a user.

usermod -s <newShell> <userName>  

usermod -s /bin/bash lisak

 

passwd

A user can set the password with the command passwd. Old password has to be typed twice before entering the new one.

passwd {username}

// change current user password
passwd

// change another user password
passwd {username}

 

 

whoami

It tells you about the system’s username.

whoami

 

who

The who command gives the information about the users logged on to the system.

who

 

w

This command tells about the users who are logged in and what are they doing.

w

 

Groups

Users can be listed in different groups. Group allow us to set permission on the group level instead of setting the permission on individual level.

 

groupadd

The groupadd command creates or add a group in our system.

// create a group named developers
groupadd developers

 

group

The group command tells about the group where current user belongs to.

 

groupmod

With the help of groupmod command you can change the name of an already existing group.

groupmod -n <oldGroup> <newGroup>  

groupmod -n developers devs

groupdel

The command groupdel will delete a group permanently from the system.

groupdel developers

 

 

March 6, 2020