What are the commands for showing the hidden folders in Git repository in windows?
For example - command in mac is ls -la or ls -a.
I am new to git.
The simplest way : start a terminal using git-bash, or from WSL (Windows Subsystem for Linux).
You will have a bash shell with access to the standard linux utilies, and ls -la should work from such terminals.
If you started a Powershell terminal, try ls -Hidden.
ls is actually an alias to the powershell command : Get-ChildItem.
The Powershell team mapped a number of usual linux command names to Powershell built-ins (e.g : cd -> Set-Location, uniq -> Get-Unique, pushd -> Push-Location, ... ), but didn't map the options, so the options expected by ls in a Powershell terminal aren't -a ... but rather the options to Get-ChildItem.
One way to figure out what's expected from a "linux" command name you know is to type : get-help <command name> you will see the actual powershell command name, and the options it expects, for example :
$ get-help ls
NAME
Get-ChildItem
SUMMARY
Gets the items and child items in one or more specified locations.
SYNTAX
Get-ChildItem [[-Filter] <System.String>] [-Attributes {Archive | Compressed | Device | Directory | Encrypted |
Hidden | IntegrityStream | Normal | NoScrubData | NotContentIndexed | Offline | ReadOnly | ReparsePoint |
SparseFile | System | Temporary}] [-Depth <System.UInt32>] [-Directory] [-Exclude <System.String[]>] [-File]
[-Force] [-Hidden] [-Include <System.String[]>] -LiteralPath <System.String[]> [-Name] [-ReadOnly] [-Recurse]
[-System] [-UseTransaction] [<CommonParameters>]
Get-ChildItem [[-Path] <System.String[]>] [[-Filter] <System.String>] [-Attributes {Archive | Compressed | Device
| Directory | Encrypted | Hidden | IntegrityStream | Normal | NoScrubData | NotContentIndexed | Offline | ReadOnly
| ReparsePoint | SparseFile | System | Temporary}] [-Depth <System.UInt32>] [-Directory] [-Exclude
<System.String[]>] [-File] [-Force] [-Hidden] [-Include <System.String[]>] [-Name] [-ReadOnly] [-Recurse]
[-System] [-UseTransaction] [<CommonParameters>]
DESCRIPTION
The `Get-ChildItem` cmdlet gets the items in one or more specified locations. [...]
If the OP is asking to simply see the hidden .git folder in a regular Windows Command terminal (cmd.exe), then the easiest is to use the dir command with the /a attribute. This is the simplest native equivalent to ls -a.
C:\Users\--redacted-->dir /a
Volume in drive C has no label.
Volume Serial Number is --redacted--
Directory of C:\Users\--redacted--
2022-10-29 10:31 PM <DIR> .
2022-10-29 10:31 PM <DIR> ..
2022-10-29 10:31 PM <DIR> .git
2022-10-29 10:31 PM 489 .gitignore
...
If you do not use the /a, you don't see the .git folder:
C:\Users\--redacted-->dir
Volume in drive C has no label.
Volume Serial Number is --redacted--
Directory of C:\Users\--redacted--
2022-10-29 10:31 PM <DIR> .
2022-10-29 10:31 PM <DIR> ..
2022-10-29 10:31 PM 489 .gitignore
...
This is because the .git folder has the Hidden Windows file attribute set, as can be seen with the attrib command:
C:\Users\--redacted-->attrib .git
H C:\Users\--redacted--\.git
Enter dir /? for all the flags that can be used with dir.
Related
I would like to use tar (on Windows) in a command line to extract files from an archive, that has a variable name, like *-archive.zip, that I don't know beforehand. I haven't found a way to use a wildcard for the targeted archive name, is there an option to do that ?
I have tried things like tar -xf "*-archive.zip", but it searches for a file with the same exact name, not the pattern.
Thanks.
Use 'tar --wildcards ...' (works at least with tar 1.33). Example:
╰─➤ $ tar --wildcards -tvf /home/johndoe/.cpan/sources/authors/id/T/TO/TODDR/XML-Parser-2.44.tar.gz '*enc'
-rw-r--r-- todd/staff 40706 2014-12-11 07:51 XML-Parser-2.44/Parser/Encodings/big5.enc
-rw-r--r-- todd/staff 45802 2014-12-11 07:51 XML-Parser-2.44/Parser/Encodings/euc-kr.enc
-rw-r--r-- todd/staff 1072 2014-12-11 07:51 XML-Parser-2.44/Parser/Encodings/ibm866.enc
...
What I ended up doing is switching to PowerShell, and ditched tar that cannot handle PowerShell pipes. The final command is :
Get-ChildItem -Name -Filter *-archive.zip | Expand-Archive
It works provided there is only one file matching the pattern in the current working folder.
I got the following directories :
.
|__ scripts
|
|__ logs
In my logs folder, I got files formated this way :
AAAAAAA_X1-09-09-2018.log
BBBBBBB_Y2-09-09-2018.log
CCCCCCC_Z3-09-09-2018.log
When I run the command ls | grep AAAAAAA*.log" from logs it works fine :
user /my/path/logs #> ls | grep AAAA*log
AAAAAAA_X1-09-09-2018.log
But if ran from scripts directory, I got no match :
user /my/path/scripts #> ls ../logs | grep AAAAA*log
I noticed that the command ls ../logs | grep AAAAA* would work, but I have to force the .log to be matched (other files being generated in that directory sometimes). I can fix this issue by doing :
ls ../logs | grep AAAAA* | grep log
but I wonder, why ls ../logs | grep AAAAA*log doesn't work from scripts but logs ?
Better change directory to log like below first:-
cd /full/path/log
ls | grep AAAA*log
cd - #go back to the original path
Modify above in your script and try.
Also try to follow the instruction given by Kamil Cuk.
Informatica runs a process daily and generate folders like cycle_1_work and next day it will generate folder like cycle_2_work .
I need to pick the latest folder and grab all the txt files .
Also any day they can reset the counter and x can start from 1 .
Please help me with this
This works for me in linux bash shell (I assume the folders are generated in a particular directory where the command below can be executed to display the files therein):
ls $(ls -ltr | grep ^d | grep "cycle_*_work" | tail -1 | awk '{print $9}')
How can I get the path of a .pid file that is inside a directory.
the code below returns only the file
root#linux [/]# ls -l $(find /* -name dovecot | grep var/run) | grep pid
-rw------- 1 root root 5 Nov 28 15:22 master.pid
Guess this is what you are looking for:
find /var/run -name "*.pid" 2>/dev/null | grep dovecot | xargs ls -l
You can also narrow the matches down in the grep command when you specify (parts of) the path inside the filter expression.
I think the interpretation of the output must be that the find command finds a directory name such as:
/var/run/dovecot
and you do an ls -l on the directory, which lists the files in the directory without any path leading to it. What you need is to find a reliable way of listing the files in the directory with their full path names.
One way — not I think a good way — of doing it would be:
find $(find /* -name dovecot -type d | grep var/run) -type f -name '*.pid' \
-exec ls -l {} +
This uses your first find command to get the directories you're interested in, then runs find again to find .pid files and execs ls -l on them. The + notation means that find behaves a bit like xargs, bunching a lot of file names together into a single run of ls -l.
cat /var/run/dovecot/master.pid
?
Or :
# readlink -f /var/run/dovecot/*.pid
/var/run/dovecot/master.pid
How would I write a batch or cmd file that will rename all files in a directory? I am using Windows.
Change this:
750_MOT_Forgiving_120x90.jpg
751_MOT_Persecution_1_120x90.jpg
752_MOT_Persecution_2_120x90.jpg
753_MOT_Hatred_120x90.jpg
754_MOT_Suffering_120x90.jpg
755_MOT_Freedom_of_Religion_120x90.jpg
756_MOT_Layla_Testimony_1_120x90.jpg
757_MOT_Layla_Testimony_2_120x90.jpg
To this:
750_MOT_Forgiving_67x100.jpg
751_MOT_Persecution_1_67x100.jpg
752_MOT_Persecution_2_67x100.jpg
753_MOT_Hatred_67x100.jpg
754_MOT_Suffering_67x100.jpg
755_MOT_Freedom_of_Religion_67x100.jpg
756_MOT_Layla_Testimony_1_67x100.jpg
757_MOT_Layla_Testimony_2_67x100.jpg
A FOR statement to loop through the names (type FOR /? for help), and string search and replace (type SET /? for help).
#echo off
setlocal enableDelayedExpansion
for %%F in (*120x90.jpg) do (
set "name=%%F"
ren "!name!" "!name:120x90=67x100!"
)
UPDATE - 2012-11-07
I've investigated how the RENAME command deals with wildcards: How does the Windows RENAME command interpret wildcards?
It turns out that this particular problem can be very easily solved using the RENAME command without any need for a batch script.
ren *_120x90.jpg *_67x100.*
The number of characters after the _ does not matter. The rename would still work properly if 120x90 became x or xxxxxxxxxx. The important aspect of this problem is that the entire text between the last _ and the . is replaced.
As of Windows 7 you can do this in one line of PowerShell.
powershell -C "gci | % {rni $_.Name ($_.Name -replace '120x90', '67x100')}"
Explanation
powershell -C "..." launches a PowerShell session to run the quoted command. It returns to the outer shell when the command completes. -C is short for -Command.
gci returns all the files in the current directory. It is an alias for Get-ChildItem.
| % {...} makes a pipeline to process each file. % is an alias for Foreach-Object.
$_.Name is the name of the current file in the pipeline.
($_.Name -replace '120x90', '67x100') uses the -replace operator to create the new file name. Each occurrence of the first substring is replaced with the second substring.
rni changes the name of each file. The first parameter (called -Path) identifies the file. The second parameter (called -NewName) specifies the new name. rni is an alias for Rename-Item.
Example
$ dir
Volume in drive C has no label.
Volume Serial Number is A817-E7CA
Directory of C:\fakedir\test
11/09/2013 16:57 <DIR> .
11/09/2013 16:57 <DIR> ..
11/09/2013 16:56 0 750_MOT_Forgiving_120x90.jpg
11/09/2013 16:57 0 751_MOT_Persecution_1_120x90.jpg
11/09/2013 16:57 0 752_MOT_Persecution_2_120x90.jpg
3 File(s) 0 bytes
2 Dir(s) 243,816,271,872 bytes free
$ powershell -C "gci | % {rni $_.Name ($_.Name -replace '120x90', '67x100')}"
$ dir
Volume in drive C has no label.
Volume Serial Number is A817-E7CA
Directory of C:\fakedir\test
11/09/2013 16:57 <DIR> .
11/09/2013 16:57 <DIR> ..
11/09/2013 16:56 0 750_MOT_Forgiving_67x100.jpg
11/09/2013 16:57 0 751_MOT_Persecution_1_67x100.jpg
11/09/2013 16:57 0 752_MOT_Persecution_2_67x100.jpg
3 File(s) 0 bytes
2 Dir(s) 243,816,271,872 bytes free