Showing posts with label command line. Show all posts
Showing posts with label command line. Show all posts

Friday, May 24, 2024

HTTPX Man Pages

 httpx <URL> [OPTIONS]

Description

HTTPX 🦋

-m,  --method METHOD

Request method, such as GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD. [Default: GET, or POST if a request body is included]

-p,  --params <NAME VALUE> ...

Query parameters to include in the request URL.

-c,  --content TEXT

Byte content to include in the request body.

-d,  --data <NAME VALUE> ...

Form data to include in the request body.

-f, --files <NAME FILENAME> ... Form files to include in the request body.

-j,  --json TEXT

JSON data to include in the request body.

-h,  --headers <NAME VALUE> ...

Include additional HTTP headers in the request.

--cookies <NAME VALUE> ...

Cookies to include in the request.

--auth <USER PASS>

Username and password to include in the request. Specify '-' for the password to use a password prompt. Note that using --verbose/-v will expose the Authorization header, including the password encoding in a trivially reversible format.

--proxy URL

Send the request via a proxy. Should be the URL giving the proxy address.

--timeout FLOAT

Timeout value to use for network operations, such as establishing the connection, reading some data, etc... [Default: 5.0]

--follow-redirects

Automatically follow redirects.

--no-verify

Disable SSL verification.

--http2

Send the request using HTTP/2, if the remote server supports it.

--download FILE

Save the response content as a file, rather than displaying it.

-v,  --verbose

Verbose output. Show request as well as response.

--help

Show this message and exit.

Friday, November 20, 2020

Create permanent BASH aliases in Linux

When creating an alias, for example
alias la="ls -la"
it exists until the terminal session is killed. When starting a new terminal window, the alias does not exist any more. The question is, how to create a "permanent" alias, one that exists in every terminal session?
Such aliases can be stored in the ~/.bash_aliases file.
 
That file is loaded by ~/.bashrc. The following lines need to be uncommented or added to enable the use of the ~/.bash_aliases file:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

 
The aliased command will be available on any new terminal. To have the aliased command on any existing terminal one need to source ~/.bashrc from that terminal:
source ~/.bashrc

A one liner would be:
echo "alias la='ls-la'" >> ~/.bash_aliases && source ~/.bash_aliases
 
Another option would be to add the alias line into ~/.bashrc or into ~/.profile / ~/.bash_profile for remote logins. If the command should be executed for all users, put it into /etc/bash.bashrc.
 
The function below can be added to the .bashrc file.
function permalias () 
{ 
  alias "$*";
  echo alias "$*" >> ~/.bash_aliases
}
Then open a new terminal or run source ~/.bashrc in your current terminal. You can now create permanent aliases by using the permalias command, for example permalias cls=clear.

~/.bashrc is run every time you open a new terminal, whereas ~/.bash_profile is not.

In order to update the file, run . ~/.bashrc or source ~/.bashrc

Function from askubuntu.com:

# -----------------------------------
#  Create a new permanent bash alias
#
#  @param $1 - NAME
#  @param $2 - DEFINITION
# -----------------------------------
new-alias () { 
  if [ -z "$1" ]; then
    echo "alias name:" && read NAME
  else
    NAME=$1
  fi

  if alias $NAME 2 > /dev/null > /dev/null; then
    echo "alias $NAME already exists - continue [y/n]?" && read YN
    case $YN in
      [Yy]* ) echo "okay, let's proceed.";;
      [Nn]* ) return;;
      * ) echo "invalid response." && return;;
    esac
  fi

  if [ -z "$2" ]; then
    echo "alias definition:" && read DEFINITION
  else
    DEFINITION="$2"
  fi

  if [ -f ~/.bash_aliases ]; then
    echo "alias $NAME=\"$DEFINITION\"" >> ~/.bash_aliases
  else
    echo "alias $NAME=\"$DEFINITION\"" >> ~/.bashrc
  fi

  alias $NAME="$DEFINITION"
}

Frequently Used Linux Commands

 

File Viewing

Command Function
cat Display the contents of file
less Page through files
head show the top portion of a file
more display screenfuls of a file
tail display bottom portion of a file
nl count the number of lines in a file
wc count the number of lines, words and characters in a file
od View a binary file
tee display output on stdout and write it to a file simultaneously

File Management

Command Function
ls display file attributes
stat display file attributes
wc count the number of lines, words and characters in a file
file identify file types
touch set the time stamp of a file or directory
chgrp change the group of a file
chmod change the permissions (mode) of a file
chown change the owner of a file
chattr change advanced file attributes
lsattr display advanced file attributes

File Manipulation

Command Function
awk pattern-matching, programming language
csplit split a file
cut display columns of a file
paste append columns in a file
dircmp compare two directories
find find files and directories
perl scripting language
sed Stream Editor
sort sort a file
tr translate chracters in a file
uniq find unique or repeated lines in a file
xargs process multiple arguements


File Editing

Command Function
vi text editor
emacs text editor
sed Stream Editor

Locate Files

Command Function
find find files and directories
which locate commands within your search path
whereis locate standard files

File Compression and Archiving

Command Function
gzip compress a file using GNU Zip
gunzip uncompress a file using GNU Zip
compress compress a file using UNIX compress
uncompress uncompress a file using UNIX compress
bzip2 compress a file using block-sorting file compressor
bunzip2 uncompress a file using block-sorting file compressor
zip compress a file using Windows/DOS zip
unzip uncompress a file using Windows/DOS zip
tar read/write (tape) archives
cpio copy files to and from archives
dump dump a disk to tape
restore restore a dump
mt tape control programm

File Comparison

Command Function
diff find differences in two files
cmp compare two files
comm compare sorted files
md5sum compute the MD5 checksum of a file
sum compute the checksum of a file

Disks and File Systems

Command Function
df display free space
du display disk usage
mount mount a filesystem
fsck check aand repair a filesystem
sync Flush disk caches


Printing

Command Function
lpr print files
lpq view the print queue
lprm Remove print jobs
lpc line printer control program


Process Management

Command Function
ps list processes
w list users’ processes
uptime view the system load, amount of time it has been running, etc.
top monitor processes
free display free memory
kill send signals to processes
killall kill processes by name
nice set a processes nice value
renice set the nice value of a running process.
at run a job at a specific time
crontab schedule repeated jobs
batch run a job as the system load premits
watch run a programm at specific intervals
sleep wiat for a specified interval of time

Host Information

Command Function
uname Print system information
hostname Print the system’s hostname
ifconfig Display or set network interface configuration
host lookup DNS information
nslookup lookup DNS information (deprecated)
whois Lookup domain registrants
ping Test reachability of a host
traceroute Display network path to a host
Character based web-browser

Networking Tools

Command Function
ssh Secure remote access
telnet Log into remote hosts
scp Securely copy files between hosts
ftp Copy files between hosts
wget Recursively download files from a remote host
lynx

File and Directory Basics

Command Function
cd change directory
cp copy files
file determine a file’s contents
ls list files or directories
ln make a link to a file
mkdir make a directory
mv move (rename) a file
rm remove a file
rmdir remove a directory
http://www.linux-tutorial.info

Friday, September 11, 2020

Soffice from Command Line - MAN Pages

 

Name

libreoffice - LibreOffice office suite

SYNOPSIS

libreoffice [--accept=accept-string] [--base] [--calc] [--convert-to output_file_extension[:output_filter_name] [--outdir output_dir] file]... [--display display] [--draw] [--global] [--headless] [--help|-h|-?] [--impress] [--invisible] [--infilter="<filter>"] [--math] [--minimized] [-n file]... [--nodefault] [--nolockcheck] [--nologo] [--norestore] [-o file]... [-p file...] [--print-to-file [--printer-name printer_name] [--outdir output_dir] file]... [--pt printername file...] [--show Impress file]... [--unaccept=accept-string] [--terminate_after_init] [--view file]... [--web] [--writer] [file...]
lobase
localc
lodraw
lofromtemplate
loimpress
lomath
loweb
lowriter

DESCRIPTION

LibreOffice (LO for short) is a multi-platform office productivity suite. It was derived from OpenOffice.org 3.3 Beta on September 28, 2010.

libreoffice is a shell script that sets up the environment and passes the command line arguments to the soffice.bin binary.

Alternatively, the following helper scripts start the respective module:

sbase, scalc, sdraw, simpress, smath, sofficerc, swriter

OPTIONS

--accept=accept-string
Specify a UNO connect-string to create a UNO acceptor through which other programs can connect to access the API.
--base
Starts the wizard for a new Base document.
--calc
Starts with a new Calc document.
--convert-to output_file_extension[:output_filter_name] [--outdir output_dir] file...
Batch converts files. If --outdir is not specified then the current working directory is used as the output directory for the converted files. It implies --headless.

Examples:

--convert-to pdf *.doc

Converts all .doc files to PDFs.

--convert-to pdf:writer_pdf_Export --outdir /home/user *.doc

Converts all .doc files to PDFs using the settings in the Writer PDF export dialog and saving them in /home/user.

--display display
This option specifies the X server to use; see X(7)
--draw
Starts with a new Draw document.
--global
Starts with a new Global document.
--headless
Starts in "headless mode", which allows using the application without user a interface.

This special mode can be used when the application is controlled by external clients via the API.

It implies --invisible and strictly ignores any GUI environment. --quickstart does not work with this parameter.

--help|-h|-?
Lists LibreOffice command line parameters.
--impress
Starts with a new Impress document.
--invisible
Starts in invisible mode.

Neither the start-up logo nor the initial program window will be visible. LO can be controlled and documents and dialogs can be opened via the API.

When started with this parameter, it can only be quit using the taskmanager (Windows) or the kill command (UNIX based systems).

--quickstart does not work with this parameter.

--infilter="<filter>"
Force an input filter type if possible. For example --infilter="Calc Office Open XML" only
--math
Starts with a new Math document.
--minimized
Keeps the splash screen minimized.
-n template...
Creates the a new document from the given templates.
--nodefault
Starts LO without creating a new document. The next time you start LO, the welcome screen is shown.

It's used together with --nologo by quick starters. Note that --quickstart has no longer been supported since OpenOffice.org 2.0.0.

--nolockcheck
Disables the check for remote instances using the installation.
--nologo
Disables the splash screen at program start.
--norestore
Disables restart and file recovery after a system crash. It is possible that LO will try to restore a file it keeps crashing on, if that happens --norestore is the only way to start LO.
--nosplash
Disables the splash screen at program start.
-o file...
Opens the given files for editing, even templates.

Without -o a template file would create a new document derived from that template.

-p file...
Prints the given files to the default printer and ends. The splash screen does not appear.

If the file name contains spaces, then it must be enclosed in quotation marks.

--print-to-file [--printer-name printer_name] [--outdir output_dir] file...
Batch print files to file. If --printer-name is not specified the default printer is used. If --outdir is not specified then the current working directory is used as the output directory for the converted files.

Examples:

--print-to-file *.doc

Prints all .doc files to the current working directory using the default printer.

--print-to-file --printer-name nasty_lowres_printer --outdir /home/user *.doc

Prints all .doc files to /home/user directory using the nasty_lowres_printer.

--pt printername file...
Prints the given files to the printer printername and ends. The splash screen does not appear.

If a file name contains spaces, then it must be enclosed in quotation marks.

--quickstart --quickstart=no
Starts LO with it's quick starter. --quickstart disable the quick starter.

Does not work with --invisible or --headless.

--show Impress file...
Opens the given Impress files, starts the presentation and quits after they have finished.
--unaccept=accept-string
Closes an acceptor that was created with --accept option.

Use --unaccept=all to close all open acceptors.

--terminate_after_init
Starts LO and terminates after it registers some UNO services. Doesn't show the splash during startup.
--view file...
Opens the given files read-only creating a temporary copy of them at $TMPDIR.
--web
Starts with a new HTML document.
--writer
Starts with a new Writer document.

Tuesday, August 28, 2018

7-zip command line examples

Start. Download the 7-Zip command line executable: 7za.exe. This is the exe you will use to run commands on archives. Please go to 7-zip.org and get the command line version. Tip: For convenience and so you don't need to change environment paths, put the 7za.exe file in your user directory.
Next: Open the Windows console and test the 7za.exe program out with a few commands. Type in the exe name 7za and this will display.
Grammar: We see the grammar we need to use with 7za.exe. The "command" is the main verb.
Switches: Then you specify optional switches, the archive name (source or destination) and files. My user directory is "C:\Users\Sam\".
7-Zip default output

7-Zip (A)  4.60 beta  Copyright (c) 1999-2008 Igor Pavlov
    2008-08-19

Usage: 7za <command> [<switches>...] <archive_name>
       [<file_names>...]
       [<@listfiles...>]
Command a. You can use the "a" command with the single letter a. This command stands for "archive" or "add." Use it to put files in an archive. Arguments: You have to specify the destination archive, and the source files (in that order).
Note: On the test system, "C:\Users\Sam" contains two files (file1.txt and file2.txt). The command puts those two files in an archive.
Tip: To open your archive, right click on it and select 7-Zip -> Open archive. The screenshot shows the files compressed in files.7z.
Example command line 1

C:\Users\Sam>7za a -t7z files.7z *.txt

7-Zip (A)  4.60 beta  Copyright (c) 1999-2008 Igor Pavlov  2008-08-19
Scanning

Creating archive files.7z

Compressing  file1.txt
Compressing  file2.txt

Everything is Ok

C:\Users\Sam>
Command d. We use the "d" command in 7-Zip command lines. This stands for delete. It allows you to remove a certain file (or set of files) from inside an archive. Note: You will need this if you use huge archives and need to save time. This is from the manual.
Tip: You can also remove a single file from an archive with "d". This is more useful when you do not have a solid archive.
Example d command line

7z d archive.zip *.bak -r

7z:          use executable
d:           delete files
archive.zip: delete from this archive
*.bak:       only match bak files
-r:          traverse all subdirectories
Command e. The "e" stands for extract, and it means to unzip or expand an archive. You must specify the source archive always, and may also specify a destination. Info: The "e" command extracts everything to a specified directory. Another command "x" can preserve directory structures in archives.
Overwrite prompts: 7-Zip will always prompt you if there is a file it needs to overwrite to extract the new file.
However: This can be problematic if you are scripting or embedding 7za.exe. In that case, see the -y switch.
Example e command line

7z e archive.zip

7z:          executable
e:           use extract command
archive.zip: source archive you want to expand
Command l. The lowercase L is used to list the contents of archives. You probably will not need to use it often. I thought I would test it and show an example. Next: This shows the listing of a solid archive. The originals are 27216 bytes and 3888 bytes. They compress down to 1030 bytes.
Example l command line

C:\Users\Sam>7za l files.7z

7-Zip (A)  4.60 beta  Copyright (c) 1999-2008 Igor Pavlov  2008-08-19

Listing archive: files.7z

Method = LZMA
Solid = +
Blocks = 1
Physical Size = 1202
Headers Size = 172

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2008-10-02 15:48:01 ....A        27216         1030  file1.txt
2008-10-02 15:47:45 ....A         3888               file2.txt
------------------- ----- ------------ ------------  ------------------------
                                 31104         1030  2 files, 0 folders
Command t. Here we use the "t" command in the 7z program. This command allows you to test the integrity of archives. It stands for 'test' and is much less useful than the "-t" switch. Warning: Don't confuse the two. This one is used for diagnostics. We usually want the hyphen "-t."
Example t command line

7z t archive.zip *.doc -r

7z:          use this executable
t:           test the specified archive
archive.zip: the archive you want to test
*.doc:       test all these files in the archive
-r:          recurse all child directories
Command u. This stands for update. This command replaces old files in your archive with newer files. This prevents needing to decompress and recompress the entire archive. Warning: The "u" command doesn't work with solid archives. A solid archive is one where all the files are compressed together.
So: You cannot update specific files in solid archives with the "u" command. Solid archives are limited.
Example u command line

7z u archive.zip *.doc

7z:          executable name
u:           update command
archive.zip: archive you want to update files in
*.doc:       only update these files (Word documents)
Switch m. We can change the optimization settings in 7-Zip on the command line. This is the most important and useful option you can use. Tip: It specifies the method of compression. Here I will show a bunch of options, and also some examples.
Compression levels:

Switch -mx0: Don't compress at all.
             This is called "copy mode."

Switch -mx1: Low compression.
             This is called "fastest" mode.

Switch -mx3: Fast compression mode.
             Will automatically set various parameters.

Switch -mx5: Same as above, but "normal."

Switch -mx7: This means "maximum" compression.

Switch -mx9: This means "ultra" compression.
             You probably want to use this.
Switch m, advanced. Here are advanced compression method (-m) switches. The first three are usually of limited use. My experience is that manual optimizations doesn't produce big benefits. Switch -mfb: Specifies number of fast bytes. Sometimes helps with "sparse" files. Don't bother.
Switch -mpass: Number of passes for deflate compression. Don't bother with this. Automatically set with levels.
Switch -md: This specifies dictionary size. It is automatically set, so don't bother.
Switch -mmt: Enable multithreading. Use if you have quad-core and a huge archive. Specify "on" or "off".
Command x. This command is like "e" except it preserves the full paths. If you have an elaborate or important directory structure, use this option. This would be most useful for backups.
Example x command line

7z x archive.zip

7z:          executable name
x:           use the extract command
archive.zip: the archive you want to extract all the files from
Switch t type. Here I show how to specify the archive type. Note that you can specify any file name you want for any type. But some extensions are recommended—they are standard.
Type switches

          Switch: -t7z
          Format: 7Z
Example filename: archive.7z (default option)

          Switch: -tgzip
          Format: GZIP
Example filename: archive.gzip, archive.gz

          Switch: -tzip
          Format: ZIP
Example filename: archive.zip (compatible)

          Switch: -tbzip2
          Format: BZIP2
Example filename: archive.bzip2

          Switch: -ttar
          Format: TAR
Example filename: tarball.tar (UNIX and Linux)

          Switch: -tiso
          Format: ISO
Example filename: image.iso (may not be supported)

          Switch: -tudf
          Format: UDF
Example filename: disk.udf
Type switch examples. The 7-Zip manual shows the -tiso and -tudf switches. These are not the most common. Almost all of the examples in this document use -t switches.
Example a command lines

7z a -tiso archive.iso
7z a -tudf archive.udf

7z:                         executable name
a:                          add to archive
-tiso or -tudf:             format of archive to create
archive.iso or archive.udf: name of archive to create
Solid archives. 7z is the only file format in 7-Zip that you can specify whether the archive is solid or not. Solid makes it impossible to use the "u" command to update individual files. Switch -ms=on: Enable solid mode. This is the default so you won't often need to specify it.
Switch -ms=off: Disable solid mode. Useful when you need to update individual files. Will reduce compression ratios normally.
7z archives. Some things you can change are dictionary sizes, FastBytes values, MatchFinder values, and filters. Normally you don't need to deal with these.
PPMd. With the 7z format, you can specify the algorithm. PPMd is good for compressing plain text files. It is ideal for Word documents. PPMd does not perform as well on binary data. PPMd switch -mmem=24b, -mmem=24k, -mmem=24m: These control the amount of memory you use. They are useful and higher is normally better.
PPMd switch -mo=2, -mo=32: These specify the model order in PPMd. They are not normally useful.
Tip: You should use PPMd when you have a large corpus (body) of text. This could include HTML. It can improve ratios by around 30%.
Example commands. Here I show the example compression commands from the 7-Zip manual. I demonstrated simple ones at the start of this document. These are more complex.
Example a command line 2

7z a -tzip archive.zip *.jpg -mx0

7z:          name of executable
a:           add to archive command
-tzip:       specify a ZIP archive (useful for compatibility)
archive.zip: destination archive
*.jpg:       only add jpg files to archive
-mx0:        don't compress, just copy
             useful for already-compressed files
Example of 7z format. This next command line shows how to create a solid 7z archive of program files (executables). It uses multithreading mode, which means it will be fast.
Example ms command line

7z a -t7z archive.7z *.exe *.dll -ms -mmt

7z:         name of executable
a:          archive command specified
-t7z:       use 7z file type (less compatible and smaller results)
archive.7z: destination archive file
*.exe:      include all *.exe files in directory in new archive
*.dll:      include all *.dll files in new archive
-ms:        create solid archive (default)
-mmt:       multithread the operation (faster)
Create PPMd archive. PPMd is an extraordinary algorithm for compressing text. Here I show a command in the 7-Zip manual that compresses all the text files in the working directory. Tip: The command is useful because you will normally want to compress only text files with PPMd.
PPMd Compression
Example PPMd command line

7z a -t7z archive.7z *.txt -m0=PPMd

7z:         executable name/path
a:          add command specified
-t7z:       use the 7z format (needed for PPMd)
archive.7z: destination archive file
*.txt:      select all text files
-mo=PPMd:   compress with this algorithm
Switch o. Sometimes you do not want to extract to the current directory. This is where -o can come in handy. Use this to set the destination directory.
Example o command line

7z x archive.zip -oC:\Doc

7z:          executable name
x:           extract archive with paths intact
archive.zip: archive to extract files from
-oC:\Doc:    extract all files to the Doc folder on the C: drive
Switch p. We can use the "-p" switch, which refers to the word "password". This is really helpful when security and encryption is involved. You can specify a password on the command line.
Example p command line

7za a pw.7z *.txt -pSECRET

7za:      name and path of 7-Zip executable
a:        add to archive
pw.7z:    name of destination archive
*.txt:    add all text files to destination archive
-pSECRET: specify the password "SECRET"
Opening password-protected archives. This next console output shows what happens when you try to open the password-protected archive. The password here is SECRET. I am so clever. Header encryption: Add -mhe to encrypt headers. The password command will automatically deal with encrypted headers.
Tip: Remember, encrypted headers will hide the names of the files in your archive.
Example x command line 2

C:\Users\Sam>7za x pw.7z

7-Zip (A)  4.60 beta  Copyright (c) 1999-2008 Igor Pavlov  2008-08-19

Processing archive: pw.7z

Enter password:
More switches. Here we take a closer look at more switches that are of limited use. They are sometimes useful to know. Usually you can do better just by using the defaults. Switch -ssc: Specify case-sensitive mode. The default is -ssc- on Windows (insensitive). The default is -scc on Linux (sensitive).
Switch -ssw: Compress locked files. You can try this if you have problems opening files.
Switch -w: Set working directory. You can use this when you want to specify temp folders.
Case-sensitive. We can use case-insensitive file names. For cross-platform stuff, the case-sensitive option is useful. I will show my own example here with some explanation.
Example ssc command line

7za.exe a archive.7z Z*.* -ssc

7za.exe:    7-Zip command-line executable path and name
a:          archive command
archive.7z: add files to this target archive
Z*.*:       select only files whose first letter is a capital Z
-ssc:       case-insensitive matching
Switch v. In data compression, a volume is a segment of a data set that is a certain number of bytes long. The volume switch specifies the exact size in bytes, kilobytes or megabytes. Also: You can specify sequential volumes with the "v" switch on the 7za.exe command line.
Switch ao. The "ao" switch allows you to specify whether you want to overwrite old files. Be careful—you cannot restore an overwritten file normally. This switch takes another argument. Switch -aoa: This switch overwrites all destination files. Use it when the new versions are preferred.
Switch -aos: Skip over existing files without overwriting. Use this for files where the earliest version is most important.
Switch -aou: Avoid name collisions. New files extracted will have a number appending to their names. You will have to deal with them later.
Switch -aot: Rename existing files. This will not rename the new files, just the old ones already there.
Examples:

7z x test.zip -aoa

7z:       use the 7-zip executable
x:        use the extract command
test.zip: extract files from this archive
-aoa:     overwrite all existing files
Multiple files. To add many files to one archive, please use the "a" command and the wildcard * symbol. Specify the name of the destination archive file and the source files afterwards.
How do I add many files with a specific extension? Use the "a" command and the wildcard * symbol, but specify the extension after the wildcard. Example: For example, *.txt means all text files. You can use the wildcard anywhere.
How can I add many files from an entire subdirectory? Specify just the directory name. You do not need to use a wildcard. This command specifies an entire directory called "subdir".
Example subdirectory command line

7z a -tzip archive.zip subdir\

7z:          use executable
a:           add to archive
-tzip:       use zip compression
archive.zip: create this archive
subdir\:     source directory
How do I use BZip2? You can use BZip2 by specifying the "-tbzip2" switch. This can be combined with any compression level. The modes in 7-Zip automatically use many different settings.
How do I use 7z format? Specify the "-t7z" switch for type. Or you can simply omit the type switch and that will default to 7z. This format offers the greatest compression ratios.
Prompts. You can stop 7-Zip from displaying prompts. Please use the -y switch. This will assume a yes answer to all prompts. Use this only when you are confident.
Why can't I update my archive? It is probably a solid archive. 7z archives are by default solid archives—all the files are compressed together. Tip: Change the archive not to be solid if you want to update it. Search this page for "solid".
Can I specify the output directory? Use the "e" command and combine it with the -o switch. The syntax with -o is a bit funny. This is the example from the 7-Zip help file.
Example output directory command line

7z e archive.zip -oC:\soft *.cpp -r

7z:          executable
e:           use extract command
archive.zip: source archive you want to extract from
-oC:\soft:   the destination folder
             (-o is the switch and C:\soft is the argument)
*.cpp:       only extract cpp files (C++)
-r:          traverse all subdirectories
How can I see what's inside an archive? Use the "l" command. You might want to use "l" in a utility that you run from a command line to make sure your batch archiving properly works.
How can I exclude certain files? Sometimes you want to manually exclude certain files. Use the -x switch, followed immediately with an exclamation mark and then the filename. So: If you want to exclude "file1.txt", use the switch "-x!file1.txt". Please include the hyphen and exclamation.
How can I replace files? By using the -ao switch, described above. There are other options, and it is usually a better idea to use one of the renaming options (-aou or -aot).
Can I ignore extracting files already on disk? Yes—specify the -aos option, which means "skip overwriting files." This will cause 7za.exe to not copy the newer files out of the archive. Note: Use -aos if your files don't change over time and overwriting would just be a waste.
Embed. You can embed 7-Zip in a Windows .NET program. This yields the same great compression but in your own GUI. The link shows some compression ratios. 7-Zip Executable
Internal settings. You can change internal settings. You do not need to do this normally. I recommend just using the mx=0 (and 3, 5, 7, 9) settings. An in-depth study would be fascinating. Filters: You can change compression filters, which change behaviors on executable files such as *.exe and *.dll.
And: You can enable header compression and encryption (-mhc=on and -mhe=on). Header compression is by default enabled.
Zopfli. If you are reading this page, you probably want even better compression. I have found that Zopfli can create gzip archives a few bytes smaller than 7-Zip can. It is slow to run. Zopfli: github.com
AdvanceCOMP. You can use AdvanceCOMP to improve compression ratios. The improvement is often small, less than 1%. AdvanceCOMP has more options and is more fine-grained. AdvanceMAME: github.com 
Source: https://www.dotnetperls.com