How to Unzip and Zip folder via SSH

Step 1.
Open Putty or Terminal then login to your server via SSH

Step 2.
Once you are logged into your server via SSH, now navigate to the directory where the .zip file you wish to unzip is located there.

 

Step 3.
Then type following command to try unzipping

unzip [filename].zip

example

unzip screenshot.zip

you may be successful but you may not.

error message:
– bash: unzip: command not found

In this case you have to install it first.

Step 4.
Use following command:

for Debian and Ubuntu:

apt-get install unzip

for Red Hat Linux/Fedora/CentOS users:

yum install unzip

Step 5.
That’s it. Now you can try unzipping it again using command in step 3 above.

example-zip-4-sukses-uznip

 

How to zip / compress file?

Step 1.
Open Putty or Terminal then login to your server via SSH

Step 2.
Once you are logged into your server via SSH, now navigate to the directory where the files and folders you wish to zip / compress are located there.

Step 3.
Use following command:

zip [zip file name] [file 1] [file 2] [file 3] [file and so on]example:

zip example.zip 1.txt 2.txt 3.txt

In this example we’ll compress files 1.txt, 2.txt and 3.txt into a single example.zip file

example zip

you may be successful but you may not.

error message:
– bash: zip: command not found

In this case you have to install it first.

Step 4.
Use following command to install zip function:

for Debian and Ubuntu:

apt-get install zip

for Red Hat Linux/Fedora/CentOS users:

yum install zip

install zip

Step 5.
That’s it. Now you can try zipping it again using command in step 3 above.

How to delete files and folders via SSH

File upload and unzip command for SSH::

++++++++++++++++++++++++++++++++++

 

Sometimes you would need to remove a file or a folder from the system. To do so using SSH, you would need to execute the appropriate command – rm.

The command in its simplest form looks like:

rm myFile*.txt

This will match all files starting with ‘myFile’ and ending in ‘.txt’ and delete them.

To delete a whole folder and its content recursively, you can use:

rm rf foldername/

To delete all files/folders in the current directory, without deleting the directory itself, you would need to use:

rm rf *

Linux Command mostly used in Software development [SSH]

Software Engineer have remembered some command which are mostly used for software development to make quick and easy manner if server system is Lenux based.

You have various choices for getting Secure Socket Shell SSH.

What is SSH?

SSH is widely used by network administrators for managing systems and applications remotely, allowing them to log in to another computer over a network, execute commands and move files from one computer to another.

You also get understand for navigate and work with files and database in SHH or Linux terminal.

 

ls Show directory contents (list the names of files).

Example:

you should list directory and file in this location.

prakash@pkbhandari.com [~]# ls

public_html  etc  tmp  logs

 

1: List Specified path files:

Example: ls <path/inner_path>

prakash@pkbhandari.com [~/public_html/sites/pk]# ls test_p
./  ../
prakash@pkbhandari.com [~/public_html/sites/pk]# ls pkb_files
./  ../  in_1/  new/  pkb_files/  pkb_files.txt  pk_zip.zip
prakash@pkbhandari.com [~/public_html/sites/pk]#

 

2. List all with hidden files:

Example: ls -a

3. List all with .dot files and hidden files:

Example: ls -all

 

4. See file and List all folder and files permission

@pkbhandari.com [~/public_html/sites/pk]# ls -lt
total 0
drwxr-xr-x  4 prakash group 54 Feb 10 13:13 ./
-rw-rw-r–  1 prakash group 0 Feb 10 13:13 pkb_file.txt
drwxrwxr-x  2 prakash group 6 Feb 10 12:55 test_p/
drwxr-xr-x  5 prakash group 80 Feb 10 12:31 pkb_files/
drwxr-xr-x. 6 prakash group 77 Feb 10 12:31 ../

folders : test_p,pkb_files

Files : pkb_file.txt

The bits we are interested in are drwxr-xr-x prakash and group

The d tells us that test is a directory. if without d it is file (pkb_file.txt).

The first three characters after the d are the owner permissions for the directory specified by the owner’s name.

  • r stands for read
  • w stands for write
  • x stands for execute (which in this case means you can access the folder)

 

Change Permission

To change the permissions for a file or folder you can use the chmod command. The chmod command lets you specify 3 numbers which set the permissions.
read permissions = 4
write permissions = 2
execute permissions = 1

To get a mixture of permissions you add the numbers together. For example to get read and execute permissions the number you need is 5, to get read and write permissions the number is 6 and to get write and execute permissions the number is 3.

Remember you need to specify 3 numbers as part of the chmod command. The first number is for the owner permissions, the second number is for the group permissions and the last number is for everyone else.

For example to get full permissions on the owner, read and execute permissions on the group and no permissions for anyone else type the following:

     chmod 750 test_p

 

 

cd Change Directory.

Example:

you should navigate the direction with folder name.

prakash@pkbhandari.com [~]# cd public_html

It will enter you in public_html folder.

 

mkdir Create a new folder (directory).

Syntax: mkdir <foldername>

Example:

prakash@pkbhandari.com [~/public_html/sites/pk]#mkdir pkb_test

it will create directory pkb_test in inside pk folder.

 

touch Create a new file.

 

rm Remove a file.
cat Show contents of a file.
pwd Show current directory (full path to where you are right now).
cp Copy file/folder.
mv Move file/folder.
grep Search for a specific phrase in file/lines.
find Search files and directories.
vi/nano Text editors.
history Show last 50 used commands.
clear Clear the terminal screen.
tar Create & Unpack compressed archives.
wget Download files from the internet.
du Get file size.

Create and Edit file using Vim editor

‘vim’ includes many features to edit files, Here i have share simplest way to create and edit file in vim editor in linux shell environment.
Using ‘vim’ to create and edit a file

#1  Log into your server via SSH.
#2 Navigate to the directory location you wish to create the file, or edit an existing file.

#3 Type in vim followed by the name of the file. For example, if you wish to create (or edit) a new file named test.html, run the following:

[server]$ vim test.txt

The 'vim' editor will appear but we must change file mode to insert text. 
[ confusing at first because you cannot type into the file yet:]


Click the letter 'i' on your keyboard to enter INSERT mode in 'vim'.
It now shows -- INSERT -- on the bottom left:

 

Now we  can add edit into file.

 

#4 When finished editing the file, click the ESC key.

This takes you out of INSERT mode and — INSERT — disappears from the bottom left of your terminal.

 

 

#5 To save the file, type in a colon followed by wq. For example:

:wq

 

#6 Click ‘Enter’ to save.