Update your Bookmarks to https://sites.google.com/view/gam--commands/home
By default GAM will/may copy files from the Bin. To avoid this you can add excludetrashed on the end of the command.
The keepuser option retains the original owner with the role writer.
gam user <User Email Address> claim ownership id <Folder or File ID> keepuser
~OwnerEmail must be a member of the Shared Drive. Files copied will be recorded in the files-copied.csv and errors in the files-error.csv.
gam csv gsheet <Google Sheet Owner Email> <Google Sheet ID> '<Sheet (tab) Name>' gam redirect stdout ./files-copied.csv redirect stderr ./files-error.csv user ~OwnerEmail copy drivefile ~FolderID teamdriveparentid ~DestinationID mergewithparent no recursive depth -1
Files copied will be recorded in the files-copied.csv and errors in the files-error.csv.
gam csv gsheet <Google Sheet Owner Email> <Google Sheet ID> '<Sheet (tab) Name>' gam redirect stdout ./files-copied.csv redirect stderr ./files-error.csv user ~OwnerEmail copy drivefile ~FolderID parentid ~DestinationID mergewithparent no recursive depth -1
The email address must be the user who wants the copy and they must be a member of the Team Drive.
gam user <User Email Address> copy drivefile <Team Drive Folder ID> recursive copytopfolderpermissions false copyfilepermissions false copysubfolderpermissions false newfilename "<New Folder Name>"
gam user <User Email Address> copy drivefile <File to Copy ID> parentid <New Folder ID>
Copy the folder structure without copying files. By default this will create a copy of the selected folder (and sub-folders) in the same location.
gam user <User Email Address> copy drivefile <Folder ID> recursive excludetrashed copysubfiles false copysubfolders true
The main types of mimeType most needed are gdoc|gform|gpresentation|gsheet|gsite. But others are can be found here https://github.com/taers232c/GAMADV-XTD3/wiki/Users-Drive-Files-Manage#definitionsÂ
gam user <User Email Address> create drivefile drivefilename "<File Name>" mimetype <mimeType> parentid <FolderID>
gam user <User Email Address> create drivefile drivefilename "<Folder Name>" mimetype gfolder parentid <FolderID>
By name
gam user <User Email Address> create drivefileshortcut name "<File Name>" parentname "<Folder Name>"
Use File and Folder IDs, which is more accurate
gam user <User Email Address> create drivefileshortcut id:<FileID> parentid <FolderID>
This will create a shortcut in the users MyDrive, with a specific name (<Name Of Shortcut>)
gam user <User Email Address> create drivefile drivefilename "<Name Of Shortcut>" mimetype gshortcut shortcut <FolderID>
Add a <Parent Folder ID> to specify a specific folder where the shortcut is created.
gam user <User Email Address> create drivefile drivefilename "<Name Of Shortcut>" mimetype gshortcut shortcut <FolderID> parentid <Parent Folder ID>
gam user <User Email Address> print driveactivity todrive
gam user <User Email Address> print driveactivity start <yyyy-mm-dd> end <yyyy-mm-dd> todrive
gam user <User Email Address> print driveactivity start <yyyy-mm-dd> end <yyyy-mm-dd> folderid <Folder ID> todrive
gam user <User Email Address> delete drivefile query "name='<Exact File Name>'"
Move all the files from a users My Drive to a Shared Drive (folder). The <User Email Address> has to be a Manager of the destination Shared Drive.
gam user <User Email Address> move drivefile root teamdriveparentid <Shared Drive Parent ID> mergewithparent duplicatefolders merge createshortcutsfornonmovablefiles
This option (Viewers and commenters can see the option to download, print, and copy) is found in the share settings > cog. To toggle this option, note that true = unticked &Â false = ticked. By default the option is ticked (false) so to prevent use the true flag.
gam user <Manager Email> update drivefile <File ID> copyrequireswriterpermission true
This may need checking as I think the some files are not moved if they are duplicates.
gam user <User Email Address> print filelist query "'<Current Parent Folder ID>' in parents and mimeType != 'application/vnd.google-apps.folder'" id title mimetype | gam csv - gam user "~Owner" update drivefile id "~id" parentid <Destination Folder ID>
Example, move all Google Sheet files, created between 2 dates, from one folder to another folder. Change the +08:00 offset to suit your location
gam user <Owner Email Address> update drivefile query " '<Parent Folder ID>' in parents and mimeType='application/vnd.google-apps.spreadsheet' and createdTime>='2022-08-01T00:00:00+08:00' and createdTime<'2023-07-31T00:00:00+08:00' " parentid <Destination Folder ID>
Change true|false as required.
gam user <User Email Address> update drivefile <File ID> starred <true|false>
To add an editor, you first need to find the owner email address, of the file.
gam user <File Owner Email> add drivefileacl <File ID> user <New Editor Email> role editor
gam user <File Owner Email> add drivefileacl <File ID> domain <Domain> withlink allowfilediscovery true role reader
gam user <Owner Email Address> delete drivefileacl <File ID> "id:<Permission ID>"
gam user <Owner Email Address> delete drivefileacl <File ID> "<Shared Email Address>"
Show presents the data in a readable format on the screen. Change to print to view in CSV format and add todrive option to create Google Sheet. The command can be performed on users, OUs or groups.
gam user <User Email Address> show drivesettings
gam ou </Path/To/OU> print drivesettings todrive
gam group <Group Email> print drivesettings todrive
Empty a users bin
gam user <User Email Address> empty drivetrash
gam group <Group Email Address> empty drivetrash
gam ou "</Path/To/OU>" empty drivetrash
gam user <user email address> show fileinfo <File ID>
Add permissions to the end to limit the info to just show the file permissions
gam user <user email address> show fileinfo <File ID> permissions
gam user <user email address> show fileinfo root id
Export the URL links for each document type shown in the File > Download options.
gam user <user email address> show fileinfo <File ID> exportlinks
Show the file path (location) of a file from its <File ID>
gam user <User Email Address> show filepath <File ID>
gam report drive filter "doc_id==<File ID>" todrive
gam report drive filter "doc_title==<Document Title>" todrive
Shared With External Email
gam report drive filter "target_user==<External Email Addrerss>" todrive
Using gam report drive [todrive] [start <Time>] [end <Time>] [(user all|<UserItem>)] [event <String>] [filter|filters <String>] [ip <String>]
gam report drive todrive start <yyyy-mm-dd> end <yyyy-mm-dd> user <User Email Address>
A subfolder named olduser@domain.com old files will be created as a subfolder
gam user <source email> transfer drive <destination email> select <folder id> retainrole writer nonowner_targetrole source
gam user <User Email Address> move drivefile drivefilename <Drive File Name> parentname <Drive Folder Name>
A subfolder named olduser@domain.com old files will be created as a subfolder
gam user <source email> transfer drive <destination email>
gam user <user email address> add drivefileacl <file ID> user <Email Address of Recipient> role reader sendemail
Add withlink on the end when dealing with the domain or anyone ACL. The roll writer can be changed [owner|writer|commenter|reader] to suit.
gam user <Owner User Email> add drivefileacl 1fMKPq-dIiFxxxxxxxxxxxxx user <User Email Address> role writer
The Target Folder needs to exist for this to work. See Add Folder.
gam csv <CSV File Name>.csv gam user "~OldOwner" transfer drive "~NewOwner" select "~FileId" targetfoldername "~TargetFolderName" targetuserfoldername "" retainrole writer
Create a Google Sheet of the IDs of the files and folders to copy, from a specific folder. The showownedby me will only list the files the Original Owner owns. Then either transfer ownership or copy to a new folder
gam user <Original Owner Email> print filelist select ID <Folder-To-Copy-ID> showownedby me fields id todrive
Transfer the Ownership
gam csv gsheet <User Email Address> <gSheet DriveFileID> <gSheet Name> gam user ~Owner add drivefileacl ~id user <New Owner Email> role owner
Copy to New Folder
gam csv gsheet <User Email Address> <gSheet DriveFileID> <gSheet Name> gam user ~Owner copy drivefile ~id parentid <New Folder ID>
Create a CSV file of all the files to transfer. Other mimetype can be found here https://developers.google.com/drive/api/v2/mime-types
gam redirect csv ./sheets.csv user <Existing Owner Email> print filelist query "mimeType='application/vnd.google-apps.spreadsheet'" fields id,name,mimetype
Transfer the files. No notifications will be sent. Existing owner will retain Edit permissions. The transfer.txtÂ
gam redirect stdout ./transfer.txt multiprocess redirect stderr stdout csv ./sheets.csv gam user ~Owner transfer ownership ~id <New Owner Email>
This will list the file tree in the terminal.
gam user <User Email Address> show filetree
TXT Create a file of the file tree
gam redirect stdout ./FileTree.txt user <User Email Address> show filetree
gSheet
gam user <User Email Address> print filetree todrive
This command will only show the files owned by the user. Remove excludetrashed if you want to show files in the bin, that have been deleted from the folder.
gam user <User Email Address> print filetree select id:<Folder ID> excludetrashed todrive tdtitle "<Google Sheet Title>"
Save the Filetree to Google Drive and only show the top level folders. Add the excludetrashed to prevent the folders in the Bin showing. However, this will analyse all the files in your MyDrive so may take a long time to complete. For just seeing the top level folders see the File List section
gam user <User Email Address> print filetree depth 0 showmimetype gfolder excludetrashed todrive
When reviewing the list, you will notice that My Drive will have a depth of -1 and the rows below this will be for each folder in the Drive. You may also see a line for Orphans with depth of -1 and the rows below this will be for the orphaned folders.
Use the noindent to reduce the spaces in the printed list.
gam user <User Email Address> print filetree showmimetype gfolder noindent
The diskusage for a users My Drive.
gam user <User Email Address> Print diskusage root todrive
gam user <User Email Address> Print diskusage <Folder ID> todrive
This allows you to specifiy the delimiter character used when displaying the folder path.
gam user <User Email Address> Print diskusage <Folder ID> pathdelimiter '<Text Character>' todrive
Print the permissions for a file. Useful when you want to remove a specific permission.
gam user <Owner Email Address> print drivefileacls <File ID> oneitemperrow todrive
gam config auto_batch_min 1 num_threads 10 redirect csv ./FileCounts.csv multiprocess redirect stdout - multiprocess redirect stderr stdout all users print filecounts summary plus showsize
File list (ACL) for a specific user. Either use the CSV file or the corresponding Google Sheet.
gam redirect csv ./files.csv user <User Email Address> print filelist fields id,title,permissions,owners.emailaddress todrive
Files shared to a user by people outside their Domain.
gam config csv_output_row_filter "owners.0.emailAddress:notregex:@<Your Domain>" user <User Email Address> print filelist showownedby others fields id,name,owners.emailaddress,webviewlink todrive
This command will create a Google Sheet showing the top level folders you own. Other mimeTypes can be found on this page https://developers.google.com/drive/api/v3/mime-types.
gam user <User Email Address> print filelist query "'root' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false" todrive
All the files and folders in a folder owned by the user.
gam redirect csv - todrive tdtitle "<File Name>" user <User Email Address> print filelist select <Top Folder ID> fields id,name,webviewlink,owners.emailaddress,modifiedtime
To view the folders at the top level, but shared with you use. You will need to use the showownedby others to display the results. If this is not used then any shred folders will be found in the search, you will see "Got 1(or more) Drive File/Folder that matched query ..." but nothing will be displayed. In other commands you can change the others to me or any as required.
gam user <User Email Address> print filelist fullquery "not 'me' in owners and 'root' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false" showownedby others todrive
For displaying more information in the results use the fields option, for example.
gam user <User Email Address> print filelist fullquery "not 'me' in owners and 'root' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false" fields id,title,mimetype,owners.emailaddress showownedby others todrive
All Drives | Shared & My Drive
Create a Google Sheet with all the Google Sites from both users Drives and Team Drives. Looking into the API info, it appears that allTeamDrives can also be allDrives and this not affect the results. This command will show for all users.
gam all users show filelist corpora allTeamDrives anyowner showmimetype gsite fields name,id,title,alternateLink,createdDate,description,teamdriveid,teamdrivename todrive
My Drive only
gam all users print filelist query "mimeType = 'application/vnd.google-apps.site'" id name mimetype
Change all users as required, for example;-
gam user <User Email Address> show filelist ...
gam group <Group Email Address> show filelist ...
gam ou_and_children </Path/To/OU> show filelist ...
Some sites will be shared with multiple users. You can use the TRANSPOSE, UNIQUE & FILTER functions to show the which users have access to which sites. This example Google Sheet shows 2 ways to manipulate the data.
Find a file(s) which have names containing specific text, but not located in a specified folder. Add corpora alldrives to include Shared Drives as well as user My Dive. This works for all files, except Google Sites.
gam user <User Email Address> print filelist query "name contains '<Part of File Name>' and not '<Folder ID>' in parents" filepath fields id,name,webviewlink todrive
For Google Sites, use this command. The csv_output_row_drop_filter option will exclude the rows where a column matches the value.
gam config csv_output_row_drop_filter "parents.0.id:regex:<Folder ID>" user <User Email Address> print filelist query "name contains '<Part of File Name>' not '<Folder ID>' in parents" filepath fields id,name,webviewlink,parents corpora alldrives todrive
Create a Google Sheet showing a line per permission for users in an OU and child OUs
gam ou_and_children "</Path/To/Top/OU>" print filelist fields id,owners,basicpermissions pm role editor em pmfilter oneitemperrow todrive
Using file extension
gam user <User Email Address> print filelist fields title filenamematchpattern ".*<Part of File Extension>.*"
Using file name
gam user <User Email Address> print filelist fields title filenamematchpattern ".*<Part of File Name>*.*"
Exact File Name
gam user <User Email Address> print filelist query "title = '<Exact File Name>'"
File Name starts with
gam user <User Email Address> print filelist filenamematchpattern "<Start of File Name>"
These will search in Google Docs, Sheets, Forms, PDF, Microsoft Documents and PNG. I assume others as well.
Exact phrase, e.g. Hello & World next to each other.
gam user <User Email Address> print filelist query "fullText contains '\"Hello World\"'" todrive
Both Hello and World in the same document.
gam user <User Email Address> print filelist query "fullText contains 'Hello World'" todrive
Search for files that are shared with an domain user from an external email account.
gam user <User Email Address> print filelist id name owners fullquery "'<External Email Address>' in owners" anyowner
For New Google Sites, stored in Google Drive.
For all users. Finding the mimeType = site (Google Sites). Check other mimeType here https://developers.google.com/drive/api/v2/mime-types
gam all users print filelist query "mimeType = 'application/vnd.google-apps.site'" todrive
To show specific fields
gam all users print filelist fields id,name,mimetype query "mimeType = 'application/vnd.google-apps.site'"
For a single user
gam user <User Email Address> print filelist query "mimeType = 'application/vnd.google-apps.site'" todrive
Or this command, but takes much longer. The mimeType can be changed, check other options here https://github.com/taers232c/GAMADV-XTD3/wiki/Users-Drive-Files
gam user <User Email Address> print filelist showmimetype gsite todrive
MIME Type contains
gam user <User Email Address> print filelist fields id,name,mimetype query "mimeType contains '<Text To Search>'" todrive
Using showmimetype
gam redirect csv ./Forms.csv ou </Path/To/OU> print filelist fields id,name,mimetype showmimetype gform fullpath todrive
This is useful for finding the owners of Google Forms as the ID of the viewform view does not relate to the actual form. For my use-case, I have searched using the OU (our Staff OU) as generally these are the forms we need to find the owner of. The owners are both owners and editors of the forms.
gam ou_and_children <Top Level OU> print filelist query "fullText contains '\"<Form Title>\"'AND mimeType = 'application/vnd.google-apps.form'" fields id,name,webViewLink todrive
Adding corpora alldrives will search in Shared Drives as well as MyDrives. And using the filepath option will display the file path to make finding the location of the file easier.Â
gam ou_and_children <Top Level OU> print filelist query "fullText contains '\"<Form Title>\"'AND mimeType = 'application/vnd.google-apps.form'" fields id,name,webViewLink filepath corpora alldrives todrive
From https://github.com/taers232c/GAMADV-XTD3/wiki/Users-Drive-Files-Display#file-selection-by-queryÂ
query "xxx" -Â and xxx is appended to the current query; you can repeat the query argument to build up a longer query.
fullquery "xxx" - The query is set to xxx eliminating the initial 'me' in owners.
<DriveFileQueryShortcut> - Predefined queries
gam user <User Email Address> print filelist fullquery "not '<Not Email Address>' in owners" id title
gam user <User Email Address> print filelist query "fullText contains '\"<Text To Search>\"'" fields id,name,driveid filepath corpora alldrives todrive
Results show the sharedWithMeTime.
gam user <User Email Address> print filelist fullquery "sharedWithMe=True" showownedby others allfields todrive
Files that are older than 90 days from the viewedByMeTime.
gam user <User Email Address> print filelist querytime90d -90d query "mimeType = 'text/csv' and viewedByMeTime < '#querytime90d#'" fields id,name,createdtime,viewedbymetime,modifiedtime
gam config auto_batch_min 1 multiprocessexit rc=0 redirect stdout - multiprocess redirect stderr stdout all users print filelist query "name='<Exact File Name>'" fields id,name,driveid filepath corpora alldrives todrive
gam config auto_batch_min 1 multiprocessexit rc=0 redirect stdout - multiprocess redirect stderr stdout all users print filelist query "name contains '\"<Part of File Name>\"'" fields id,name,driveid filepath corpora alldrives todrive
This will search file content and titles
gam config auto_batch_min 1 multiprocessexit rc=0 redirect stdout - multiprocess redirect stderr stdout all users print filelist query "fulltext contains '\"<Text to Search>\"'" fields id,name,driveid filepath corpora alldrives todrive
gam all users print filelist query "fullText contains '<Text Option 1>' or fullText contains '<Text Option 2>'" todrive
gam user <User Email Address> print filelist minimumfilesize <File Size in Bytes> title size todrive tdtitle "<File Title>"
Remove countsonly if you want a list of all the files.
gam redirect csv ./BigFiles.csv ou "</Path/To/OU>" print filelist minimumfilesize <File Size in Bytes> title size countsonly todrive tdtitle "<File Title>"
NB. I need to confirm that the minimumfilesize is in Bytes
gam user <User Email Address> print filelist minimumfilesize <File Size in Bytes> query "mimeType='image/jpeg' or mimeType contains 'application'" todrive
Using the ParentFolderID & Folder Name
gam user <User Email Address> print filelist query "'<ParentFolderID>' in parents and title='<Folder Name>'" id
Search in whole MyDrive
gam user <User Email Address> print filelist filepath query "title='<Folder Name>'" id todrive
gam user <User Email Address> print filelist query "visibility='domainCanFind'or visibility='anyoneCanFind'" todrive
gam ou_and_children </Path/To/OU> print filelist fields id,name,permissions,webViewLink pm type domain domain <mydomain.com> role editor em query "(visibility='domainCanFind' or visibility='domainWithLink')" todrive
gam ou_and_children </Path/To/OU> print filelist select teamdriveid <Shared Drive ID> fields id,name,permissions,webViewLink pm type domain domain <mydomain.com> role editor em query "(visibility='domainCanFind' or visibility='domainWithLink')" todrive
(not fully tested)
gam config auto_batch_min 1 redirect csv ./SharedWithGroup.csv multiprocess all users print filelist fields id,name,mimetype,basicpermissions query "'<Group Email Address>' in readers or '<Group Email Address>' in writers" pm type group emailaddress '<Group Email Address>' em pmfilter oneitemperrow
File revisions made by a specific user
gam user <User Email Address> print filerevisions <File ID> todrive oneitemperrow
gam users <User1 Email Address>,<User2 Email Address>,<User3 Email Address>,<ETC>Â print filerevisions <File ID> todrive oneitemperrow
Change ou to ou_and_children if members of sub-OUs are also to be counted.
gam ou </Path/To/OU> print filerevisions <File ID> todrive oneitemperrow
The purge option bypasses bin and deletes forever.
gam user <user email address> purge drivefile <file ID>
gam user <user email address> print filelist query "mimeType='audio/mp3'" id title mimetype | gam csv - gam user ~Owner delete drivefile ~id purge
gam ou "</Path/To/OU>" delete drivefile query:"createdTime<'<yyyy-mm-ddT00:00:00Z>'" purge
This allows the Google Sheet to be shared so that other users always have the most up to date info.
Login as the user and create the Google Sheet and rename the tab. For this example the Sheet will be called UpdateByGAM and the Tab will be TabInfo.
gam user <Sheet Owner Email> info sheet name "UpdateByGAM"
Look for Spreadsheet: 1234xxxxxxxxxxxxxxxxxxxxxxxxxxxXYZ & sheetId: 15xxxxxxxxx42 in the info listed.
For example
gam redirect csv - todrive tduser <Sheet Owner Email> tdtitle UpdateByGAM tdtimestamp false tdfileid 1234xxxxxxxxxxxxxxxxxxxxxxxxxxxXYZ tdsheet id:15xxxxxxxxx42 tdupdatesheet tdnobrowser tdnoemail ous "'</Path/To/OU>'" print users fields primaryEmail,name,ou
NB the tdtimestamp false option will make sure the file name is not appended with the date/time of update. You may, however want to omit this if you want to know when the file was updated.
Use this command to update a Google Sheet using a local CSV file. For example if you generate a local CSV file, the contents can be used to update a Google Sheet.
gam user <Sheet Owner Email> update drivefile <File ID> csvsheet id:<Sheet ID> localfile <CSV File Name>.csv retainname
gam user <User Email Address> print filelist query "modifiedTime >= '2020-01-01T00:00:00Z' and modifiedTime < '2020-02-01T00:00:00Z'" fields id,name,modifiedTime filepath todrive
For a user
gam user <User Email Address> print filelist fields id,name,permissions,webViewLink pm type anyone withlink true role editor em todrive
For an OU
gam ou </Path/To/OU> print filelist fields id,name,permissions,webViewLink pm type anyone withlink true role editor em todrive
Show all fields
Change fields id,name,permissions,webViewLink to allfields
For a user
gam redirect csv ./AnyLinkEdit.csv user <User Email Address> print filelist fields id,name,permissions pm type anyone withlink true role editor em
Then to delete the ACLs
gam csv ./AnyLinkEdit.csv gam user <User Email Address> delete drivefileacl ~id anyonewithlink
NB. Check syntax before running commands in a live enviroment.
Removing allowfilediscovery = true from users files. This command will create a Google Sheet with file permissions. Filter to only show files with allowfilediscovery = true AND either permissions.0.type = domain or the role, e.g. anyone. Change all users for user <User Email Address> or ou </Path/To/OU> as required.
gam config auto_batch_min 1 redirect csv ./filelistperms.csv multiprocess all users print filelist fields id,title,permissions,owners.emailaddress pm allowfilediscovery true em todrive
permissions.0.type = domain
gam csv gsheet <File Owner Email> <File ID> <Sheet Name> gam user ~Owner add drivefileacl ~id ~permissions.0.type ~permissions.0.domain role ~permissions.0.role allowfilediscovery false
permissions.0.type = anyone
gam csv gsheet <File Owner Email> <File ID> <Sheet Name> gam user ~Owner add drivefileacl ~id ~permissions.0.type role ~permissions.0.role allowfilediscovery false
Info on parameters for search: https://developers.google.com/drive/api/v3/search-files
Show all the files and folders starred, including in the trash. This will show the name and webViewLink for each file.
gam user <user email address> print filelist fullquery "starred = true" showownedby any corpora alldrives todrive
Add excludetrashed to exclude the files in the trash.
gam user <user email address> print filelist fullquery "starred = true" showownedby any corpora excludetrashed alldrives todrive
Add fields id,name,mimetype to display the file type (including folders) and the id.
gam user <user email address> print filelist fullquery "starred = true" showownedby any corpora excludetrashed fields id,name,mimetype alldrives todrive
gam config all users print filelist fields id,title,permissions permissionmatch type anyone endmatch todrive
Or
gam all users print filelist filepath id title owners query "visibility='anyoneWithLink'" todrive
gam config ou_and_children_ns <top level OU> print filelist fields id,title,permissions permissionmatch type anyone endmatch todrive
gam config user <user email address> print filelist fields id,title,permissions permissionmatch type anyone endmatch todrive
Or
gam user <user email address> print filelist filepath id title owners query "visibility='anyoneWithLink'" todrive
gam config ou_and_children_ns <top level OU> print filelist fields id,title,permissions permissionmatch type anyone endmatch todrive
gam user <user email address> print filelist id title permissions todrive
gam ou_and_children_ns <top level OU> print filelist id title permissions todrive
gam user <user email address> print filelist id title trashed todrive
gam user <user email address> print filelist filepath todrive
Searching for all users or a single user. Output the file list to a CSV or todrive.
gam all users show filelist query "mimeType contains 'video/mp4'" allfields > filelist.csv
gam user <User Email Address> print filelist query "mimeType contains 'video/mp4'" allfields todrive
Get a report of the file types in a folder and sub folders. Add anyowner if you want all the files.
gam user <User Email Address> print filelist select id:<FolderID> countsonly todrive
gam user <User Email Address> print filelist select name "<Top Folder Name>" countsonly todrive
gam user <User Email Address> print filelist id name owners fullquery "'<Non-Domain Email>' in owners" anyowner todrive
gam all users print filelist id name owners fullquery "'<Non-Domain Email>' in owners" anyowner todrive
Find all files owned by others
gam user <User Email Address> print filelist id name owners showownedby others
Or
gam user <User Email Address> print filelist fullquery "not 'me' in owners" anyowner
Specify the user who is the owner
gam user <User Email Address> print filelist id name owners fullquery "'<Sharing User Email>' in owners" anyowner todrive
Add not in the query to search for files not shared by a user.Â
gam user <User Email Address> print filelist id name owners fullquery "not'<Sharing User Email>' in owners" anyowner todrive
Using this command you can view the owner of a file that is "in use". It appears that it will only show files used within the last 180 days.
gam show ownership <File ID>
For older files you should be able to use this. Note the ' around the OU Path and " around the orgUnitPath.
gam print users query "orgUnitPath='/Path/To/OU'" | gam csv - gam user ~primaryEmail show drivefileacl <File ID> > results.txt
This command will show the files owned by the user matching the <File Name>.
gam user <user email address> print filelist query "title = '<File Name>'" todrive tdtitle "<Results File Name>"
Using title contains '<Part of File Name>' you can search for files containing a character string.
gam user <user email address> print filelist query "title contains '<Part of File Name>'" todrive tdtitle "<Results File Name>"
The above commands will limit the results to those owned by the user. If you need to see all the files, those shared wi
gam user <user email address> print filelist query "title contains '<Part of File Name>'" anyowner todrive tdtitle "<Results File Name>
Find the id of a users My Drive
gam user <user email address> show fileinfo root id title
id: <xxx My Drive ID xxx>
    name: My Drive
Use this ID to list the files in that users My Drive. The results will show File ID, Name and whether in Trash or not.
gam user <user email address> print filelist query "'<xxx My Drive ID xxx>' in parents" id name trashed title > rootfilesfolders.lst
Or, to save to your Google My Files
gam user <user email address> print filelist query "'<xxx My Drive ID xxx>' in parents" id name trashed todrive tdtitle "<File Name>"
By default, files in the Bin are listed;Trashed = True. To remove these run a fullquery with trashed=false.
gam user <user email address> print filelist fullquery "'<xxx My Drive ID xxx>' in parents and trashed=false" id name todrive tdtitle "<File Name>"
The above commands will only list files owned by the user. So show all the files use anyowner.
gam user <user email address> print filelist fullquery "'<xxx My Drive ID xxx>' in parents and trashed=false" anyowner id name todrive tdtitle "<File Name>"
The file will be moved to the Bin
gam user <user email address> delete drivefile <file ID>
gam user <user email address> delete drivefileacl <file ID> anyonewithlink
gam ou /Path/To/OU print filelist id mimetype name query "mimeType contains 'video/'" > VideoFiles.csv
Inspect and check VideoFiles.csv. If all OK to delete you can use this to delete files and bypass the bin.
gam csv VideoFiles.csv gam user ~Owner delete drivefile ~id purge
gam user <User Email Address> print filelist select drivefilename "<Top Folder Name>" showmimetype gfolder fields id,title,mimetype,foldercolorrgb showparent todrive
gam user <User Email Address> update fileinfo <Folder ID> folderColorRgb: <Colour Hex Value or Colour Name>
Prior to running these commands, use the GUI to set a colour of the top folder and record the <Folder ID> from the Address bar.
gam user <User Email Address> show fileinfo <Folder ID> fields id,title,foldercolorrgb
This will show some details of the folder. Make note of the <colour code>, such as #16a765
gam redirect csv ./<CSV File Name>.csv user <User Email Address> print filelist select <Folder ID> fields id,title,foldercolorrgb showmimetype gfolder
gam redirect stdout - multiprocess csv ./<CSV File Name>.csv gam user ~Owner update drivefile ~id foldercolorrgb "<colour code>"
gam user <User Email Address> get drivefile <File ID From The URL> csvsheet "<Sheet Name>"
Replace show with print if needed.
gam user <User Email Address> show sheetrange <File ID From The URL> range '<Tab Name>!<Range>'
Different operating systems reqire different quoting syntax. A combination of " and/or ' may be needed.
If you create a file in Drive that you later can’t find, the file might have lost all of its parent folders. It becomes an orphaned file. The file still exists but is harder to find.Â
gam user <User Email Address> collect orphans
gam ou_and_children </Path/To/Top/OU> collect orphans
Create a Google Sheet of the Orphan files before transferring them.
gam user <User Email Address> collect orphans preview todrive
gam user <User Email Address> add drivefile drivefilename "<Folder Name>" mimetype gfolder
gam all users add drivefile drivefilename "<Folder Name>" mimetype gfolder
gam user <User Email Address> update drivefile id <folder ID> addparent root
The role can be changed to either reader or editor.
gam user <Owner Email Address> add drivefileacl <Folder ID> user <New Share Email Address> role editor
Ensure the user sees the folder in their My Drive
gam user <New Share Email Address> create drivefileshortcut <Folder ID>
gam user <User Email Address> print filelist my_folders todrive
gam user <User Email Address> show filelist query "title = '<Exact File Name>'"
FileID = 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9
Show file info to see who have permission
gam user <User Email Address> show fileinfo 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9
Or , for just info about the users
gam user <User Email Address> show drivefileacl 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9
gam user <User Email Address> print filelist todrive select 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9 showmimetype gfolder fields id
gam user <Original Owner Email> add drivefileacl 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9 user <New Owner Email> role owner
gam user <New Owner Email> delete drivefileacl 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9 <Original Owner Email>
OR: By viewing the fileinfo you can find the user id of the original owner.
gam user <New Owner Email> show drivefileacl 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9
This will show id: 1xxxxxxxxxxxxxxxxxxxxx6 for the user.
gam user <New Owner Email> delete drivefileacl 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9 id:1xxxxxxxxxxxxxxxxxxxxx6
Convert a local file into a Google Sheet or Google Doc
gam user <User Email Address> update drivefile id 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9 localfile <Local File Name>
Files can be downloaded as in various formats. The most useful are (probably) CSV, DOC, JPG, PDF, TXT & ZIP.
This will work for both Drive files and Shared Drive files. If you are working in the Cloud then this will be saved in your designated 'Downloads' folder.
gam user <User Email Address> get drivefile <File ID> format pdf
Download an individual tab (sheet) from a Google Sheet.
gam user <User Email Address> get drivefile <File ID> gsheet id:<Sheet ID> format pdf
The output from the above command will be something like this.
User: <User Email Address>, Drive File: <File Name>, Downloaded to: /home/user_name/Downloads/<File Name>.pdf, Type: Google Doc
To download to your local machine copy the file path /home/user_name/Downloads/<File Name>.pdf and use for downloading.
Download all Photos from a Users Drive.
gam user <User Email Address> get drivefile query "mimeType = 'image/jpeg'" targetfolder /Path/To/Download/Folder
The file will be restored to it's original location.
gam user <User Email Address> untrash drivefile <File ID>