I am a big fan of linux command line utils and work with many of those on windows as well. One of the commands I have started to like is xargs. I Like the way you could compose commands with pipes. Have tried using xargs on windows without much success.
One of the things I often use this is to clean temp directories of certain log files. My linux commands would have been:
|
|
Now I could have done this on windows as:
|
|
but xargs dies with environment being too large, instead had to switch to a less elegant solution:
|
|
forfiles
– is the command to iterate over files/s
– to search recursively in subdirectories/p .
– to search in current directory/M *.syslog
– find all syslog files/c
– to execute specified command in this case I want to remove files
Following variables are available for the command with /c
option (case doesn’t matter):
Variable | Description |
---|---|
@FILE | File name |
@FNAME | File name without extension |
@EXT | File name extension |
@PATH | Full path of the file |
@RELPATH | Relative path of the file |
@ISDIR | Evaluates to TRUE if a file type is a directory. Otherwise, this variable evaluates to FALSE |
@FSIZE | File size, in bytes |
@FDATE | Last modified date stamp on the file |
@FTIME | Last modified time stamp on the file |
Or one could do this entirely with powershell:
|
|
or:
|
|
For now I prefer forfiles
, it is easy and handy to use.
Powershell looks promising, but is verbose and don’t want to switch between two shell commands.