Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • cp <source> [<source>...] <destination> copies the file(s) <source> [<source>...] to the directory or file  <destination>.
    • using . (period) as the destination means "here, with the same name"
    • -p option says to preserve file modification timestamps
    • cp -r <dirname>/ <destination>/ will recursively copy the directory <dirname>/ and all its contents to the directory <destination>/.
    • cp -t <dirname>/ <file> [<file>...] copies one or more specified files to the target directory.
  • scp <user>@<host>:<remote_source_path> <local_destination_path>
    • Works just like cp but copies <remote_source_path> from the remote host machine to the <local_destination_path>
    • -p (preserve file times) and -r (recursive) options work the same as cp
    • scp <local_source_path>... <user>@<host>:<remote_destination_path> is similar, but copies the one or more <local_source_path> to the <remote_destination_path> on the remote host machine.
    • A nice scp syntax resource is located here.
  • wget <url> fetches a file from a valid URL (e.g. http, https, ftp).
    • -O <file> specifies the name for the local file (defaults to the last component of the URL)
  • rsync -arvW <source_directory>/ <target_directory>/
    rsync -ptlrvP <source_directory>/ <target_directory>/
    • Recursively copies <source<source_directory> contents to <target_directory>, but only if <source_directory> files are newer or don't yet exist in <target_directory>
    • Remote path syntax (<user>@<host>:<absolute_or_home-relative_path>) can be used for either source or target (but not both).

    • Always include a trailing slash ( / ) after the source and target directory names!
    • -a means "archive" mode (equivalent to -ptl and some other options)
    • -r means recursively copy sub-directories
    • -v means verbose
    • -W means Whole file only
      • Normally the rsync algorithm compares the contents of files that need to be copied and only transfers the different portions. This option disables file content comparisons, which are not appropriate for large and/or binary files.
    • -p means preserve file permissions
    • -t means preserve file times
    • -l means copy symbolic links as links (vs -L which means dereference the link and copy the file it refers to)
    • -P means show transfer Progress (useful when large files are being transferred)
    • see https://manpages.ubuntu.com/manpages/trusty/man1/rsync.1.html

Miscellaneous commands

  • echo <text> prints the specified text on standard output
    • evaluation of metacharacters (special characters) inside the text may be performed first
    • -e says to enable interpretation of backslash escapes such as \t (tab) and \n newline
    • -n says not to output the trailing newline
  • wc -l  reports the number of lines (-l) in its input
    • wc -c reports the number of characters (-c) in its input
    • wc -w reports the number of words (-w) in its input
  • history lists your command history to the terminal
    • redirect to a file to save a history of the commands executed in a shell session
    • pipe to grep to search for a particular command
  • which <pgm> searches all $PATH directories to find <pgm> and reports its full pathname
  • du <file_or_directory..file_or_directory>
    • shows the disk usage (size) of the specified files/directories
    • -h says report the size in human-readable form (e.g. 12M instead of 12201749)
    • -s says summarize the directory size for directories
    • -c says print a grand total when multiple items are specified
  • groups - lists the Unix groups you belong to

...