Translating linux command script to powershell command script - linux

i am attempting to translate this snippet:
"find &filsti./ -name '*.sas7bdat' -type f -printf '%u;%p;%a\n'"
into powershell, so that i can scan for files the same way in windows as i do in linux. Can anyone assist me? Appreciate any help i can get.

No idea what that last part is, but try this:
Get-ChildItem -Path "C:\path" -Include *.sas7bdat -Recurse

Related

Usage of "find" linux command

My question is about linux commands. I need to find all ".sh" files and I need to delete all the files which end with ".sh" extension automatically. Could anyone please help me out by giving suitable linux command for it?
find . -type f -name '*.sh' -exec rm {} \;

combining results of two find commands linux

I have a set of configuration backups that are organized like
backup/site1/10-11-2019
backup/site1/11-11-2019
backup/site1/12-11-2019
backup/site2/10-11-2019
backup/site2/11-11-2019
backup/site2/12-11-2019
backup/site3/10-11-2019
backup/site3/11-11-2019
backup/site3/12-11-2019
I need to list the configuration files that are less than specific size for one particular date for all sites. In a way so that I could combine following two commands from backup directory
find . -type d -name "11-11-2019"
find . -name "*.cfg" -size +500c
Please help me combining these two commands
Have you tried this?
find 11-11-2019 -name "*.cfg" -size +500c
Source: https://unix.stackexchange.com/questions/60849/find-files-in-multiple-folder-names
Can't check if it works right now :(
Thanks for the link. It gave me the hint to develop my command which serves my purpose.
find . \( -type f -and -path '*/2019-11-11/*' \) -name "*.cfg" -size -50c -print

Looks like Busybox shell was not doing quotes removal

It is about following setup: Linux machine, bash, adb, embedded Linux target system with Busybox.
For target system following applies:
adb shell echo $SHELL
/bin/sh
adb shell echo $0
/bin/sh
The problem is my find command in some script does not find anything (it has been proved by other means that items being looked for in fact do exist on target). My command:
adb -s $AdbID shell find / -type f \( -name "'"*audio*"'" -or -name "'"*alsa*"'" \) \
\( -path "'"/usr/lib/*"'" -or -path "'"/usr/bin/*"'" -or -path "'"/etc/*"'" \)
If to debug with echo echo gets following string as input arguments:
$ adb -s $AdbID shell echo find / -type f \( -name "'"*audio*"'" -or -name "'"*alsa*"'" \) \
\( -path "'"/usr/lib/*"'" -or -path "'"/usr/bin/*"'" -or -path "'"/etc/*"'" \)
find / -type f ( -name '*audio*' -or -name '*alsa*' ) \
( -path '/usr/lib/*' -or -path '/usr/bin/*' -or -path '/etc/*' )
Note: above transcript uses escaped newlines so you dont need to scroll much here, however those are not used in original command.
I guess same will apply to find if to remove echo from command string.
For me it looks like Busybox was not doing the quotes removal as myself used to have in Bash, after expansions of all other kinds. Ash as it seems to be Busybox shell, in its manual no word reg. quotes removal was found, so no idea how ash works in this regards.
#
If to replace Linux host with Windows desktop machine + dos command line, remaining elements as in case above* the command works fine. One can figure out difference at following point:
*) actually also other target system, however on this side no intentional changes so both setups should be identical regarding target system.
If to debug with echo echo gets following string:
c:\adb_shell>adb -s 2233445 shell echo find / -type f \
\( -name "'"*audio*"'" -or -name "'"*alsa*"'" \) \
\( -path "'"/usr/lib/*"'" -or -path "'"/usr/bin/*"'" -or -path "'"/etc/*"'" \)
find / -type f ( -name *audio* -or -name *alsa* ) \
( -path /usr/lib/* -or -path /usr/bin/* -or -path /etc/* )
Here the command gets from shell the string of input arguments with quotes removed.
I realize just the minute as myself writes this Q that command grouping will also not work as expected (busybox shell will consume paranthesis so 'find' won't receive them), let's address this question in other scope. Possibly command has more errors of this kind.
I believe the lack of quotes removal in case of two Linux shells in a chain is also real problem for my command string. What are possible reasons, solutions?
Note that in
"'"*audio*"'"
the asterisks are not escaped from the shell. The shell will happily glob them, should a file matching *audio* be in the current working directory. If the ' are really part of the filenames, you want to use "'*audio*'" instead. Then find will seach for files named '*audio*' (where find, not the shell, does the globbing for *).
If you simply want to find files matching *audio* (audio anywhere in the name), then use -name "*audio*" etc.
It would help if you told us exactly what the file names you want to find are.

I want to know exact command of "find . -name '*.c' -or -name '*.cpp'" in Linux

I'm studying shell in Linux these days. and I've had one question.
Please, look at below command:
$ find . -name '*.c' -or -name '*.cpp'
Exact command of above command is processed like below command?
$ find . -name '*.c' -and -print -or -name '*.cpp' -and -print
You are combining different search expressions with the logical operator or.
Basically your command will find all files in the current directory ending with .c or .cppand will print them to STDOUT.
For further info check the man page of find command.
Also note that this question would be more suitable to ask here.

How to use variable as a path for find command

Can someone give me a hint, how I can make the following bash script run properly:
path="/path/"
excludepath="! -path \"/path/to/exclude/*\" "
find "$path" "$excludepath" -name *."txt" -type f
When I try to run it I get:
find: `! -path "/path/to/exclude/*"': No such file or directory
Thank you in advance.
Your problem was the fact that "$excludepath" is a single argument, even if it contains spaces. To put several arguments, use an array of strings instead of a string:
excludepath=(! -path "*webshow*")
find "$path" "${excludepath[#]}" -name "*.txt" -type f
This is a bashism, though (people that stumble onto this and don't use bash will need to do something else).

Resources