Linux Commands I Always Forget
Published
in Programming
Last updated
Now I can find them right away instead of having to google constantly!
Archiving
How to create a .tar.gz
archive
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
-c: Create an archive.
-z: Compress the archive with gzip.
-v: Display progress in the terminal while creating the archive, also known as “verbose” mode. The v is always optional in these commands, but it’s helpful.
-f: Allows you to specify the filename of the archive.
How to extract that archive
tar -xzvf archive.tar.gz
Moving Files Between Computers
Using SCP
Copy file from a remote host to local host SCP example:
scp username@from_host:file.txt /local/directory/
Copy file from localhost to a remote host SCP example:
scp file.txt username@to_host:/remote/directory/
Copy directory from a remote host to local host SCP example:
scp -r username@from_host:/remote/directory/ /local/directory/
Copy directory from localhost to a remote hos SCP example:
scp -r /local/directory/ username@to_host:/remote/directory/
Copy file from remote host to remote host SCP example:
scp username@fromhost:/remote/directory/file.txt username@tohost:/remote/directory/
SCP options:
–r Recursively copy entire directories. Note that this follows symbolic links encountered in the tree traversal.
-C Compression enable. Passes the -C flag to ssh to enable compression.
-l limit – Limits the used bandwidth, specified in Kbit/s.
-o sshoption – Can be used to pass options to ssh in the format used in sshconfig.
-P port – Specifies the port to connect to on the remote host. Note that this option is written with a capital ‘P’.
-p Preserves modification times, access times, and modes from the original file.
-q Quiet mode: disables the progress meter as well as warning and diagnostic messages from ssh.
-v Verbose mode. Print debugging messages about progress. This is helpful in debugging connection, authentication, and configuration problems.
SSH Tricks
Run Remote Commands Over SSH
ssh user@host -p 22 “cd ~/ && ls -l”