20160308

Linux Terminal Commands

Simply, a reference/cheat-sheet for terminal commands.


  1. chown
    • chown username:groupname *, and let the shell expand the * to the contents of the current directory. This will change permissions for all files/folders in the current directory, but not the contents of the folders.
    • chown -R username:groupname ., which would change the permissions on the current directory, and then recurs down inside of it and all sub-folders to change the permissions.
    • chown -R username:groupname * will change the permissions on all the files and folders recursively, while leaving the current directory itself alone. This style and the first style are what I find myself using most often.
  2. chmod 
    • If you want to set permissions on all files to a+r, and all directories to a+x, and do that recursively through the complete subdirectory tree, use:
      chmod -R a+rX *
      
      The X (that is capital X, not small x!) is ignored for files (unless they are executable for someone already) but is used for directories.
  3. apt
    1. If there are GPG errors
      • sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys [ALPHANUMERIC]
    2. To remove a repository
      • sudo apt-add-repository --remove ppa:name/repository
    3. To force install of dependencies
      • sudo apt-get install -f
    4. To install suggested packages
      • sudo apt-get --install-suggests install [package]
  4. dpkg errors
    1. sudo apt-get install -f -y
    2. Then re-run the previous command.
      • sudo dpkg -i --force-all appliation*.deb
  5. GVfs
    1. Mounts
      • gvfs-mount -l
      • Volume(0): xxxxx@gmail.com
          Type: GProxyVolume (GProxyVolumeMonitorGoa)
          Mount(0): xxxxx@gmail.com -> google-drive://xxxxx@gmail.com/
            Type: GProxyShadowMount (GProxyVolumeMonitorGoa)
        Mount(1): xxxxx@gmail.com -> google-drive://xxxxx@gmail.com/
      • If unmounted, it will only show Volume(0)
    2. Rules
      • cd /usr/share/gvfs/mounts then do ls
      • There should be listed a number of mount point rules.
    3. Dependencies
      • Within the directory: /usr/lib/gvfs/ are gvfs related deps.
      • Check to see if you have gvfsd and gvfsd-fuse installed.
    4. Error When Integrating Google Drive with Files
  6. Links
    1. Make
      • $ ln -s /path/to/link /linked/path
    2. Remove
      • $ rm /path/to/link/to/remove
    3. Rename
      • $ mv oldsymlink newsymlink
  7. Mounts
    1. Bind Mounts (How to use bind mounts)
      • $ mount -o bind /opt/var_log /var/log
      • You will now see this reflected when running the mount command:
        • # mount | grep var
        • /opt/var_log on /var/log type none (rw,bind)
    2. If you want this to persist across reboots, you’ll just need to update your /etc/fstab with the bind mount as well.
      • # /etc/fstab
      • /opt/var_log              /var/log                 none    bind    0 0
    3. gvfs - See GVfs
  8. GOA - gnome-online-accounts
    1. Install GNOME Control Center (GNOME System Settings) and GNOME Online Accounts:
      1. $ sudo apt-get install gnome-control-center gnome-online-accounts
    2. Launching GNOME Control Center
      1. Using a command to launch GNOME Control Center
        1. $ Exec=env XDG_CURRENT_DESKTOP=GNOME gnome-control-center --overview
      2. Editing the GNOME Control Center .desktop file
        1. $ mkdir -p ~/.local/share/applications/
        2. $ cp /usr/share/applications/gnome-control-center.desktop ~/.local/share/applications/
        3. $ sed -i '/^OnlyShowIn/d' ~/.local/share/applications/gnome-control-center.desktop
      3. To get GNOME Control Center to display all the available panels:
        1. $ sed -i 's/^Exec.*/Exec=env XDG_CURRENT_DESKTOP=GNOME gnome-control-center --overview/' ~/.local/share/applications/gnome-control-center.desktop
  9. Command output write to file
    To write the output of a command to a file, there are basically 8 commonly used ways.
    1. command > output.txt
      The standard output stream will be redirected to the file only, it will not be visible in the terminal. If the file already exists, it gets overwritten.
    2. command >> output.txt
      The standard output stream will be redirected to the file only, it will not be visible in the terminal. If the file already exists, the new data will get appended to the end of the file.
    3. command 2> output.txt
      The standard error stream will be redirected to the file only, it will not be visible in the terminal. If the file already exists, it gets overwritten.
    4. command 2>> output.txt
      The standard error stream will be redirected to the file only, it will not be visible in the terminal. If the file already exists, the new data will get appended to the end of the file.
    5. command &> output.txt
      Both the standard output and standard error stream will be redirected to the file only, nothing will be visible in the terminal. If the file already exists, it gets overwritten.
    6. command &>> output.txt
      Both the standard output and standard error stream will be redirected to the file only, nothing will be visible in the terminal. If the file already exists, the new data will get appended to the end of the file..
    7. command | tee output.txt
      The standard output stream will be copied to the file, it will still be visible in the terminal. If the file already exists, it gets overwritten.
    8. command | tee -a output.txt
      The standard output stream will be copied to the file only, it will still be visible in the terminal. If the file already exists, the new data will get appended to the end of the file.