Output of command -> CertUtil -hashfile MD5
Can i convert the path output of the file on which i run "cerutil -hashfile" as relative rather than absolute ?
Regards
Related
I have a simple ping script that produces an output file at the end to a local folder, the file name contains a variable that pulls the host name of the computer its run on and adds it to the file name. I then want to be able to move this file to another file path but wasn't how to do with the variable names .txt file.
$H = hostname
cd c:/users
ping ipaddress -n 4 |Foreach{"{0} - {1}" -f (Get-Date),$_} > chosenfolder\$H"DC1!".txt
Any help would be appreciated.
Thanks
Tried using the basic copy-item cmdlet but this didn't work.
If all you are after is to move the file then you can you the mv command in powershell.
$H = hostname
cd c:/users
ping ipaddress -n 4 |Foreach{"{0} - {1}" -f (Get-Date),$_} > chosenfolder\$H"DC1!".txt
mv chosenfolder\$H"DC1!".txt C:\<whatever path>
Im trying make an script which can find and store specific type files in a folder.
When I run myScript.sh:
$ ./myScript.sh *.txt
It should save in files.txt all files with .txt extension but doesn't work for me. Only save first file.
myScript.sh:
var=`find $1`
for file in $var
do
echo $var >> files.txt
done
That's an example for practice
Do it like this:
for file in $#
do
echo "$file" >> files.txt
done
Using $#, you can get all the arguments in the script that you pass.
You don't need a loop at all. Just redirect the output of find to your file.
find . "$1" >> files.txt
Finally, i fix this issue passing .txt instead *.txt and changing my script like this:
$ ./myScript.sh *.txt
var=`find *$1`
for file in $var
do
echo $var >> files.txt
done
It works for me.
Thank you all for answer!
I don't understand why you are passing arguments to the script at all. If you want all the files in the current directory whose name ends in ".txt", you could do either:
ls *.txt > files.txt
or
find . -name '*.txt' > files.txt # descends the directory tree
or (not standard)
find . -maxdepth 1 -name '*.txt' > files.txt
None of these will handle files with embedded newlines particularly well, but that use case is not handled well when storing names in a file.
My command line is very rusty so any help appreciated.
I have cd into the drive.
touch newfile.txt
now how do I echo the names, date created and date modified into newfile.txt?
Thank you
You don't need to 'touch newfile.txt' as shell stdout redirect can create a file if it doesn't exist (assuming you have the permissions in that directory).
To get the data, you can use the 'stat' command - e.g.:
cd /path/to/some/directory
stat -f %N,%c,%m * > newfile.txt
If you need the timestamps in a human-friendly output, you can try:
stat -f %N,%Sc,%Sm * > newfile.txt
Refer to the man page of stat for other options.
I have a folder with a lot of jpg files and I want to convert them all into png. The thing is that I want to keep the name of the files. Let's see if you can help me.
#! /bin/bash
unset i2
for i in ./drawable/*.jpg
do
$i2 = ${i%%.jpg}
sips -s format png $i --out Converted/$i2.png
done
Here is a corrected version of your code :
#! /bin/bash
#you don't need to unset variables in bash if you want to reuse them
#for your script to be more portable, I would rather use 'for IMG in ./*.jpg'
#that way, you could execute the script anywhere on your computer with any .jpg file.
#with your current syntax, the script will fail if there is no ./drawable folder
for IMG in ./drawable/*.jpg
do
IMG_BASENAME=$(basename $IMG) #this will convert './drawable/img.jpg' to 'img.jpg'
sips -s format png $IMG --out Converted/${IMG_BASENAME%%.jpg}.png
#again, if you want the script to be portable, I would suggest using a fixed output directory
#for instance : sips -s format png $IMG --out ~/Documents/Converted/${IMG_BASENAME%%.jpg}.png
done
I have a .bat file that unzips a kml from a kmz. If I run the batch file again it prompts me if I want to replace the file. Is there away I can have it always replace the file without prompting the user or displaying a cmd window?
#echo off
md tempKml
cd tempKml
..\unzip ..\%1 >nul
cd ..
dir tempKml\*.kml /s/b
Use the -o option?
..\unzip -o ..\%1 >nul