Handy Linux Commands

Tar

Archive a directory and compress it with zip.
This command create a file containing a compressed version of the target directory and all of that directories contents.

tar -czf my-archive.tar.gz source_directory

Explode a zipped archive to a directory.
The archive will be exploded into your current directory

tar -xzf my-archive.tar.gz

SSH

SSH to a remote server. SSH creates a shell on a remote server and logs into it as the give user.

remote-server in the example is either a DNS name such as www.example.com or an ip address such as 192.168.0.127

ssh remoteuser@remote-server

SSH to a target server with a tunnel that forwards local port 8080 to the remote server's port 3000

ssh user@target.example.com -L 8080:target.example.com:3000

SCP

SCP stands for secure copy protocol. It is a tool that can copy files to and from a remote server over an encrypted connection.

Copy a local file to a remote server. Note that the trailing : on the remote server indicates the destination on the remote server. By default the file will be copied into the home directory of the remote user. You can specify a target directory or file explicitly like: ruser@remote-server:/path/to/destination/target_file

scp local_file.zip remoteuser@remote-server:

Zip

List the contents of a zip file

unzip -l zip_file.zip

How can I see the contents of a zip file without extracting it from a zip file?

unzip -p zip_file.zip file_i_want_to_see.txt

Screen

Screen is a great little utility when you need to leave something running and don't want it terminate when you stop your shell session.

Install the screen app (apt install screen or equivalent for your distro)

Use a screen with: screen

To get out of a screen type: ctrl+a then ctrl+d

To re-attach to a running screen run the command: screen -r

If you have multiple screens running you will need to specify the screen. Do this running screen -r which lists the running screens. They will be prefixed with a number. To re-attach to a running screen run the command: screen -r 1234 where 1234 matches the first 4 numbers of the screen prefix for which you want to attach.