== Helpful Perforce One-liners ==
=== About This Project ===
The page contains a list of handy single-line Perforce scripts. Most of these can easily be converted into custom tools to run from the Perforce GUIs. If you have a favorite that's not listed here, please share it!
The "shell command" one-liners will run in most generic shells, including the standard Windows '''cmd''' prompt, but most require a set of CLI tools that are only standard on Unix. The free [http://www.cygwin.com Cygwin toolkit] is a popular way to get similar versions of these tools on Windows.
The [http://en.wikipedia.org/wiki/Windows_PowerShell Powershell] one-liners do not require Unix tools.
The [[px]] commands use an extended command-line client.
{| style="width:100%"
|-
|
{{OnelinerEntry |
description=Delete all empty submitted changelists. |
shellcmd=p4 changes -s submitted <nowiki>|</nowiki> cut -d " " -f 2 <nowiki>|</nowiki> xargs -n1 p4 change -d -f |
powershellcmd=<nowiki>p4 changes -s submitted | %{p4 change -d -f $_.split()[1]}</nowiki> |
pxcmd=px -F %change% changes -s submitted <nowiki>|</nowiki> px -X- change -d -f |
contributor=Sam Stafford, Philip Kania, Shawn Hladky}}
|-
|
{{ OnelinerEntry |
description=Find all files containing a given expression. (Obsoleted by [http://www.perforce.com/perforce/doc.current/manuals/cmdref/grep.html p4 grep].)|
shellcmd=p4 print PATH | grep -e EXPR -e "^//" | grep -B1 -e EXPR |
powershellcmd=<nowiki>p4 print PATH | select-string EXPR,^//\w | %{if($_ -match "^//\w"){$f=$_}else{if($f){$f;$f=0};$_}}</nowiki>
<nowiki>p4 print PATH | select-string EXPR,^//\w | %{if($_ -match "^//\w"){$f=$_}else{$_}} | select @{n="file";e={$f}},@{n="match";e={$_}}</nowiki> |
script=//guest/sam_stafford/scripts/p4find.bat |
contributor=Sam Stafford, Philip Kania}}
|-
|
{{OnelinerEntry |
description=List all files opened on any client owned by USER, without using p4 opened -a. |
shellcmd=p4 -Ztag clients | grep -B3 "... Owner USER" | grep "... client" | cut -d ' ' -f 3 | xargs -n1 p4 opened -C |
powershellcmd=<nowiki>p4 clients -uUSER | %{p4 opened -C $_.split()[1]}</nowiki> |
pxcmd=px -F %client% clients -u USER <nowiki>|</nowiki> px -X- opened -C |
contributor=Sam Stafford, Philip Kania, Shawn Hladky}}
|-
|
{{OnelinerEntry |
description=List all changelists that contributed via integration to target change CHANGE. |
shellcmd=p4 files @CHANGE,@CHANGE | sed s/#.*/@CHANGE/ | p4 -x - filelog -m1 | grep "^\.\.\. \.\.\." | grep -v "into" | grep -v "ignored by" | sed "s/.*\/\//\/\//" | p4 -x - changes |
powershellcmd=<nowiki>p4 files "@CHANGE,@CHANGE" | %{$_ -replace "#.*","@CHANGE"} | p4 -x - filelog -m1 | select-string "^\.\.\. \.\.\." | ?{$_ -notmatch "into" -and $_ -notmatch "ignored by"} | %{$_ -replace ".*//","//"} | p4 -x - changes</nowiki> |
contributor=Sam Stafford, Philip Kania}}
|-
|
{{OnelinerEntry |
description=Delete all jobs matching the pattern "job=DELETEME*". |
shellcmd=p4 jobs -e "job=DELETEME*" <nowiki>|</nowiki> cut -d " " -f 1 <nowiki>|</nowiki> xargs -n 1 p4 job -d |
powershellcmd=<nowiki>p4 jobs -e "job=DELETEME*" | %{p4 job -d $_.split()[0]}</nowiki> |
pxcmd=px -F %Job% jobs -e "job=DELETEME*" <nowiki>|</nowiki> px -X- job -d |
contributor=Sam Stafford, Philip Kania, Shawn Hladky}}
|-
|
{{OnelinerEntry |
description= Get the latest version only for files you already have a copy of in your workspace |
shellcmd=p4 sync <path>#have,head |
script=//guest/matt_attaway/scripts/haveSync.pl |
contributor=Matt Attaway}}
|-
|
{{OnelinerEntry |
description= Open all the files in a submitted changelist for edit |
shellcmd=p4 files ...@<change num>,<change num> <nowiki>|</nowiki> sed s/\#.*// <nowiki>|</nowiki> p4 -x - edit |
powershellcmd=<nowiki>p4 files ...@<change num>,<change num> | %{$_.split("#")[0]} | p4 -x - edit</nowiki> |
pxcmd=px -F %depotPath% files ...@<change num>,<change num> <nowiki>|</nowiki> px -x - edit |
script=//guest/matt_attaway/scripts/editFilesInChange.bat |
contributor=Matt Attaway, Philip Kania, Shawn Hladky}}
|-
|
{{OnelinerEntry |
description=Returns output if and only if USER has access to FILE. (Doesn't necessarily work with wildcards.) |
shellcmd=p4 protects -u USER FILE | tail -n1 | grep -e " //" |
powershellcmd=<nowiki>p4 protects -u USER FILE | select-string " //" -quiet</nowiki> |
contributor=Sam Stafford, Philip Kania}}
|-
|
{{OnelinerEntry |
description=Simple triggers entry to enforce revertunchanged SubmitOption on client specs. |
shellcmd= ru form-in client "sed -i -e s/submitunchanged/revertunchanged/ %formfile%" |
contributor=Sam Stafford}}
|-
|
{{OnelinerEntry |
description=List all new files under the current directory not opened for add. |
shellcmd=dir /b /s /a-d | p4 -Ztag -x - add -nf | grep "clientFile" | cut -c16-
find . -type f -print | p4 -Ztag -x - add -nf | grep "clientFile" | cut -c16- |
powershellcmd=<nowiki>gci -recurse | ?{-not $_.PSIsContainer} | %{$_.FullName} | p4 -ztag -x - add -nf | select-string "clientFile" | %{([string]$_).substring(15)}</nowiki> |
pxcmd=px addr -n ... |
contributor=Sam Stafford, Philip Kania, Shawn Hladky}}
|-
|
{{OnelinerEntry |
description=List files modified by USER. |
shellcmd=p4 changes -u USER | cut -d" " -f2 | xargs -n1 -iARG p4 files @ARG,ARG |
pxcmd=px -F "@=%change%" changes -u USER <nowiki>|</nowiki> px -x- files |
contributor=Sam Stafford}}
|-
|
{{OnelinerEntry |
description=List all changelists with descriptions that match regexp. /\bfix/i in example below that means "list all fixes" |
shellcmd=p4 changes -l //depot/your/path/...@2008/04/25,@now | perl -lne '$a=$_ if /^Change/; print qq|$a\t$_| if /\bfix/i' |
contributor=Dmytro Gorbunov}}
|-
|
{{OnelinerEntry |
description=List all changelists that are pending (have not been submitted) by a user yet. |
shellcmd=p4 changes -u User_Name -s pending |
contributor=Richard Schilling}}
|}
[[Category: Perforce]]
[[Category: Shell]]
# |
Change |
User |
Description |
Committed |
|
#1
|
13792 |
Lester Cheung |
Archive of wiki.workshop.perforce.com in raw (mediawiki) and markdown formats. |
|
|