5 linux commands for Developers 2020 -linux cheat sheet

shape
shape
shape
shape
shape
shape
shape
shape
5 linux commands for Developers 2020 -linux cheat sheet

This guide is about useful linux commands that can be used on a terminal and can help a developer in his day to day activities. I have written this cheat sheet based on how hard it is to remember some of this commands and how it can be helpful to other developers.

Copying Files with Rsync From Server to Local Machine

There are several ways in which you can copy a file over ssh in linux, you can copy using rsync command or scp command. Rsync is faster than scp as it employs optimization algorithms. Rsync (Remote Sync) is a most commonly used command for copying and synchronizing files and directories remotely as well as locally in Linux/Unix systems

 

rsync options source destination

to copy a file from a server to current directory denoted by fullstop (.)  in linux

rsync --stats  root@192.168.0.100:/var/www/cassava.zip  .

You can also use Rsync to copy files from local machine to the server 

rsync --stats backup.tar root@192.168.0.100:/backups/

the file name is backup.tar and we are copying it to the directory /backups

 

Connect To MySQL Database From Command Line

This  section expains how to connect to mySql from terminal over 

replace username with your username,  -p prompts for password

mysql -u USERNAME -p

Suppose you want to connect to a database with a different hostname and port number

mysql --host=hostname --port=port_number-u USERNAME -p

Replace host_name, port_number and USERNAME with your environment values.

 

History Command

The GNU history command keeps a list of all the other commands that have been run from that terminal session.

Suppose you are working on a new system and you do not know where the application lies, running history command can help.

history

suppose you connected to a server via ssh and you don't want to go and find the server username and ip_address. you can search in your history file using grep.

history | grep ssh

Find Command

Find is one of the most simple and useful commands in linux. Developers use find to search for a file or directory on your file system. Using the -exec flag, files can be found and immediately executed. The syntax of the find command is 

find options starting/path expression

find . -name backup.tarFind the file whose name is backup.tar in the current working directory
find / -type d -name Cassavahub d specifies directory, finds all directories with name Cassavahub in / directory
find . -type f -name cassavahub.phpfinds file with name cassavahub.php in current directory
find / -type f -size +100M -exec rm -f {} \;To find all 100MB files and delete them using one single command.

You can view more information about find command here https://www.tecmint.com/35-practical-examples-of-linux-find-command/

Compressing files using Tar

Tar or Tap Archive is used to archive directories or to optionally compress the archive.

to compress a folder to .gz we use

tar cvzf backup.tgz /home/backups

-c creates archive

-v shows verbose

-z uses gzip compression 

-f specify name of file

to extract a gzip encode file in current directory 

tar -xvzf backup.tar.gz

to untar in a specific directory we use 

tar -xvf backup.tar.gz -C /home/public_html/backups/

 

 

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *