I have multiple directories that have +w (Always writable in workspace).
How do I change all files to keep all permissions as is, and remove the +w if exists. Need the p4 command (I know p4 edit -t is per file type...).
Some files are text, some are binaries...
This'll do it:
p4 -F "%type%#%depotFile%" files ... | grep -e ".*w.*#.*" | sed -e "s/\(.*\)w\(.*\)#\(.*\)/edit -t \1\2 \"\3\"/" | p4 -x - run
Note that you need "grep" and "sed" -- if you're on Windows (like I am) I recommend the versions that come with Cygwin. :)
Related
I am new to linux. I have a folder with many files in it and i need to get the latest file depending on the file name. Example: I have 3 files RAT_20190111.txt RAT_20190212.txt RAT_20190321.txt . I need a linux command to move the latest file here RAT20190321.txt to a specific directory.
If file pattern remains the same then you can try below command :
mv $(ls RAT*|sort -r|head -1) /path/to/directory/
As pointed out by #wwn, there is no need to use sort, Since the files are lexicographically sortable ls should do the job already of sorting them so the command will become :
mv $(ls RAT*|tail -1) /path/to/directory
The following command works.
ls | grep -v '/$' |sort | tail -n 1 | xargs -d '\n' -r mv -- /path/to/directory
The command first splits output of ls with newline. Then sorts it, takes the last file and then it moves this to the required directory.
Hope it helps.
Use the below command
cp ls |tail -n 1 /data...
Files stored in P4 depot are decorated with file type and optional attributes:
The above example is for <binary+S4>.
How can I search the depot tree for all files which have <binary+S4>?
I want to audit these files and change attributes of some of them to <binary+S10>.
p4 fstat should solve it for you.
So a command like this would show you all of the writable text files.
p4 fstat -F "headType=text+w" //DEPOT/...
From the command line (I'm on Windows using Cygwin's version of "grep" and "cut", should work on Mac/Unix too):
p4 -F %type%:%depotFile% files //... | grep ^binary+S4 | cut -d: -f2- | p4 -x - edit -t +S10
I am making a script that allow's me to unzip a given file. My problem is that i don't now how to change directory to the directory just created by the unzip process.
I tried with this command, but it's not working: SITE_DIRECTORY="$(ls -dt */ | head -1)"
Any idea on how to get the name of the directory just extracted ?
Edit: Now i got to SITE_DIRECTORY=unzip $SITE_NAME | grep 'creating:' | head -1 | cut -d' ' -f5-
But a new problem arise: the unzip command does not extract all the files.
New ideas ?
If the directory is known, you could
unzip -j yourzip.zip -d /path/to/dir && cd /path/to/dir
Extra info from man page (j option)
-j junk paths. The archive's directory structure is not recreated; all files are deposited in the extraction directory (by default, the
current one).
The solution to my problem was the following commands:
unzip $SITE_NAME >output.txt
SITE_DIRECTORY=$(cat output.txt | grep -m1 'creating:' | cut -d' ' -f5-)
rm output.txt
Thanks goes to Evan # Unzip File which directory was created
I am used to searching specific keywords under Linux.
For example, I may search "TAIWAN" under home by
grep -i -r TAIWAN ./ | grep -v".svn"
However, I thought this is a little redundant; I want to use an alias so I can type
grep TAIWAN
and then the alias will expand my command into
grep -i -r TAIWAN ./ | grep -v".svn"
How could I achieve this?
You won't be able to do it with an alias, but you can create a bash function:
mygrep () { grep -i -r $* ./ | grep -v".svn"; }
I don't believe alias can accomplish what you want because there is no way to reorder the arguments. It is simpler to make a small shell command. Rather than replace grep, and thus possibly mess up programs which expect grep to behave in a certain way, I'd give it a new name such as rgrep.
#!/bin/sh
grep -i -r "$#" | grep -v .svn
Put that somewhere in your PATH such as ~/bin and make it executable with chmod +x ~/bin/rgrep. Then you can rgrep TAIWAN ..
Unfortunately, this will ignore lines which contain .svn as well as files.
You could try to fix up the grep -v pattern match to only match the file part of the grep output, or you could whip up a more complicated command using find instead of grep -r... or you can use ack.
Ack is a better grep and will avoid version control directories and other common files and directories you don't care about. It will also automatically use a pager and color the output.
I don't want the changelists; I want the actual files that are shelved. So the results should look like the results of p4 opened but filtered to show only the files that are shelved.
Anyone know how to do this in a few commands? (Preferably one)
I couldn't find a way to get it down to less than this, but maybe this will help as a starting point:
for cl in `p4 -ztag changes -u your.name -s shelved | \
grep -oP '(?<=^\.{3} change )\d+'`
do
p4 describe -Ss $cl | grep -E '^\.{3}'
done | sort | uniq
This does a p4 describe -S on each of your shelved changelists, but tries to only show the files. It might be a bit fragile. It should look like:
... //depot/yourfile.txt#4 edit
... //depot/otherfile.txt#5 edit