Listing folders and sub-folders in DOS and Unix? - dos

I have to list folders and sub-folders from a given directory in DOS and Unix. I know i cand make this with DIR command, as follows: dir directory /ad /s, but the assignment tells me that I have to make it with find. It works with dir, but i have no idea how to make it with find. And I have to make it in UNIX too, so if you have some hints or something, please let me know.
Thanks.

Windows native find command is for finding strings in files or stdin, not for listing file names. download findutils for windows, then you can use find the same as what you used in Unix
WindowS:
C:\test> gnu_find.exe c:\path
Unix:
find /path

Related

How to find all header files in directory and subdirectories in Windows

i recently started working on windows operation system(2012 R2) and i am trying to find all files with header format (*.h) in my directory and it subdirectories .
this how i got it when i ran in linux shell :
find /auto/sw_work/fwshared/ibrahims/git/svx/pci_verification -name "*.h"
i got the following results :
/auto/sw_work/fwshared/ibrahims/git/svx/pci_verification/pci_properties/src/BlockStateMainProperty.h
/auto/sw_work/fwshared/ibrahims/git/svx/pci_verification/pci_properties/src/BlueFieldBdfProperty.h
/auto/sw_work/fwshared/ibrahims/git/svx/pci_verification/pci_properties/src/CfgLastIndexProperty.h
/auto/sw_work/fwshared/ibrahims/git/svx/pci_verification/pci_properties/src/CfgLastIndexPropertyProperty.h
/auto/sw_work/fwshared/ibrahims/git/svx/pci_verification/pci_properties/src/ComponentIsUpstreamProperty.h
/auto/sw_work/fwshared/ibrahims/git/svx/pci_verification/pci_properties/src/ConfigTraceProperty.h
/auto/sw_work/fwshared/ibrahims/git/svx/pci_verification/pci_properties/src/DmesgProperty.h
/auto/sw_work/fwshared/ibrahims/git/svx/pci_verification/pci_properties/src/DriverProperty.h
/auto/sw_work/fwshared/ibrahims/git/svx/pci_verification/pci_properties/src/HeaderLogProperty.h
/auto/sw_work/fwshared/ibrahims/git/svx/pci_verification/pci_properties/src/HotPlugProperty.h
/auto/sw_work/fwshared/ibrahims/git/svx/pci_verification/pci_properties/src/I1FrequencyProperty.h
/auto/sw_work/fwshared/ibrahims/git/svx/pci_verification/pci_properties/src/LinkEqProperty.h
how can i get the following results when running in windows command line?
thank in advance .
That's an easy one.
The command to list files is dir. See dir /? for various switches.
dir /s /b "\auto\sw_work\fwshared\ibrahims\git\svx\pci_verification\*.h"
The /s switch looks recursive (including subfolders), the /b switch will show the files in bare format (no header, no summary, timestamps or size)
Note: the directory separator in Windows is \, not / as in Unix/Linux.

for f in do command, but looking in subdirectoreis (OSX terminal)

I have found this command but am not finding a way to make it remove the .bts extension off of files within subdirectories.
The problem is this program bittorrent sync had a major bug and added .bts to all the filenames on a folder of my NAS. The files are there but not readable until the extension is removed.
I have managed to use this withing a directory:
for f in *.bts; do mv "$f" "${f%.*}"; done
Though know nothing about the command line/terminal in osx or anywhere... I read I could use
for /r in %%G
but that's not working. Anybody know a fix?

How do you match an exact file extension under Windows/command line/file open dialog?

I am trying to get a directory listing of only files with a given extension. At first blush this seems to be a simple thing to do, however check out this simple example:
C:\CODE\metcal>dir /b *.exe
metcal.exe
metcal.exe1
Notice that this returns metcal.**exe** and metcal.**exe1** as matches.
With python files a similar thing happens:
C:\CODE\metcal>dir /b *.py
metcal.py
metcal.pyc
Notice again Windows has determined that *.py takes anything that starts with *.py so it captures the .pyc files as well.
Is there a way to get only the extensions that match exactly? In the above python files example I would like the following to occur (obviously with the correct syntax substituted for *.py)
C:\CODE\metcal>dir /b *.py
metcal.py
As a note the matching under Windows not as simple as it seems.
*.exe matches foo.exe, foo.exe1, foo.exeabcde but not foo.exe.bak
There are other questions on SO that are similar that are related to long/short file names. The *.py and *.pyc example here should not introduce name mangling machinery.
**I have experimented on XP and Win7 machines and this behavior is not consistent at the cmd Prompt and file open dialogs. This inconsistant behavior makes me suspect this problem is related to settings of somekind. **
It's because windows wildcards on extensions check both long and short names as explained in this answer:
https://superuser.com/questions/238900/winxp-dir-command-3-and-4-char-extensions-are-the-same#238930
Solution there is to disable 8.3 names creation and then striping them on ntfs volumes which will also improve performance.
Microsoft Docs: Fsutil 8dot3name
Remarks:
Permanently removing 8dot3 file names and not modifying registry keys that point to the 8dot3 file names may lead to unexpected application failures, including the inability to uninstall an application. It is recommended you first back up your directory or volume before you attempt to remove 8dot3 file names.
So if you want to get only those extensions (.py and .pyc), you should try like this way :
#echo off
dir /b *.py*
pause
You can use the Unix ls command from the Windows Subsystem for Linux to do this, assuming you have WSL installed. It's freely available from Microsoft. From your Windows command prompt, type wsl followed by the ls command to list the files you want.
So, for your example, wsl ls metcal.py returns only metcal.py. To get the same results as you're seeing with dir, use wsl ls metcal.py*.

Batch file to recursively find files named a specific name and move to a directory

So, I was hit with the Cryptowall 3.0 ransomware virus. After decryption I am still left with a large amount of DECRYPT_HELP files in .txt, .html, .png and Windows Shortcut formats.
I need a batch script to recursively find the files containing the name "DECRYPT_HELP" regardless of its' extension and move those files into a directory which I will delete.
I am a Linux guy, so I can't FIND and GREP my way through this. Any assistance would be appreciated.
You can find the files using
dir /s *decrypt_help*
dangerous command follows
del /s *decrypt_help*
will delete all of those files. use with extreme caution

Location of windows command prompt command files

In Unix, the terminal commands are in /etc folder. Similarly, I'd like to know where the command files of Windows are located eg., mkdir, cd, etc. Thanks in advance.
You can use where to find where the executables are located.
Some as #sb9 said, are not separate exe's and they are built in. Using where you can find out if they have their own exe file or not.
where ftp
where at
where cd
In this case cd will error as it is built in.
Some commands are located in windows\system32, and some others (like mkdir and cd) are built in internally into the shell cmd.exe, so you won't find them on the hard disk.

Resources