Tag: Command

  • Shortcut to run previous shell command as superuser

    Old Procedure

    1. Most of the time when we execute a permission required command but we forget to add sudo at the start of the command then terminal throws the error permission denied
    2. So what we will do enter up arrow (navigation key) and enter home or continuously press left arrow key to go to the initial position of the previously executed command
    3. In command at the start position we will start type sudo 
    4. Instead of that we have an alternative to avoid navigating towards start of your command

    New Procedure

    1. Now we are going to see how to execute the permission denied command alternative and fast way
    2. In your terminal type sudo !!
    3. In terminal, you will see previously failed command is executing with superuser permission
    4. PPT to PDF

      1. The above one line shell snippet in php script is used to convert the powerpoint file in to PDF file using libreoffice. The same command can be used for all the files which are able to open using libreoffice like doc, docx, odt, odp, etc., Shell command is enclosed in back tick symbol not single quotes. PHP by default execute command inside back tick as shell command alternatively you can use shell_exec
      2. Let’s we see each arguments and it’s description (this is an excerpt from official document) we passed to the shell command libreoffice
      3. --headless        Starts in “headless mode” which allows using the application without GUI. This special mode can be used when the application is controlled by external clients via the API.
      4. --invisible        Starts in invisible mode. Neither the start-up logo nor the initial program window will be visible. Application can be controlled, and documents and dialogs can be controlled and opened via the API. Using the parameter, the process can only be ended using the taskmanager (Windows) or the kill command (UNIX-like systems). It cannot be used in conjunction with –quickstart.
      5. --convert-to OutputFileExtension[:OutputFilterName] \ [--outdir output_dir] [--convert-images-to]        Batch convert files (implies –headless). If –outdir isn’t specified, then current working directory is used as output_dir. If –convert-images-to is given, its parameter is taken as the target filter format for *all* images written to the output format. If –convert-to is used more than once, the last value of OutputFileExtension [:OutputFilterName] is effective. If –outdir is used more than once, only its last value is effective. For example:
        --convert-to pdf *.odt
        --convert-to epub *.doc
        --convert-to pdf:writer_pdf_Export --outdir /home/user *.doc
        --convert-to "html:XHTML Writer File:UTF8" \
        --convert-images-to "jpg" *.doc
      6. Finally we pass shell command textual output to virtual device /dev/null using > symbol in linux based distros whatever it receives as input it will discard it. As a result there won’t be displaying of any message when you using this snippet inside your custom function or method.