Monday 2 February 2015

Useful linux command lines

      These examples are run using putty. Know more about putty here
You can find the download links at the end of this page.

Once installed Putty, Add the putty path to the System path so that it becomes easy to access the executable.
To add variables to System path refer to Setting up Environment variable section .

File Transfer

Window to Linux

1. Open command prompt or run Ctrl+R, Type cmd to open the Command prompt.

  
2. In command prompt type in the following commands.
pscp source <filename> <user>@<host>:<destinationpath>
pscp source c:\test\test.txt test@example:/home/test/Desktop
 The console ‘ll prompt for password, enter the password and press enter.
The file transfer ll start copying the files.

Linux to Windows

3. In command prompt type in the following commands.
pscp <user>@<host>:<source path> <destination path>
The console ll ask for password, enter the host password and press enter.

Moving files

sudo mv <source> <destination>
sudo mv /home/test/test.txt /var/www/test.txt

Renaming Files

 Simple rename command
sudo mv <oldfilename> <newfilename>
Sudo mv test1.txt test.txt

Zipping and Unzipping a file

Zipping a file

zip <zipfilename> <filename>;
zip test.zip test.txt

Unzipping a file.

unzip <zipfilename>; // unzips to the current directory.
unzip <zipfilname> -d <foldername> // unzips to the particular directory.
// If the folder is not present folder is created 

Extracting a tar.gz file

           tar -xvzf <Tarfilename>;  // extracts to the current directory.            
           tar -xvzf <Tarfilename> -C <directory name>;  // extracts to the specified directory.
           tar -xvzf <Tarfilename> --directory <directory name>;  // extracts to the specified directory.

Restart Apache service 

sudo /etc/init.d/apache2 restart // older version of ubuntu
sudo service apache2.restart //newer version of ubuntu 

References

1. Download all Putty executables under one zip here
2. Download the Putty installer from here