Wednesday, May 2, 2018

unix - Copy and rename multiple files in one step by txt list

I have list of files what I have to rename. There is no sequence or pattern in renaming therefore I use a .txt files to do it. I can rename and copy files in separate step but I would like to combine this process into one step. The challenging part, why I am going to do it in one step, is some source file should be renamed (and copied) to multiple files.



Example:




source-file-1.jpg -> renamed-file-1.jpg



source-file-1.jpg -> renamed-file-2.jpg



source-file-1.jpg -> renamed-file-3.jpg



I use following xargs commends to rename and copy files.





xargs -a copy.txt cp -t /new-folder



xargs -a rename.txt -n 2 mv




It is possible co combine these commands? I hope if I copy files first I could achieve my goal.

windows - copy multiple files to multiple "folders with Unicode names"

i have 29000+ mp3 files which have English names , i want to move or copy subgroups of the files to multiple folders with Arabic names, i have a list of each file and where it needs to go, i could use the move command from the cmd prompt if the folders were in English but it doesn't work with Unicode names Or i can rename the folders to non-unicode names then use the move command then rename the folders back to their original names But i dont want that ..my question is is there a command line utility or any utility in general or a script that can achieve my goal?

How do I "combine" two hard drives in Ubuntu?


My old hard drive layout was:



  • 200GB holding /

  • 500GB holding /home/


However, the 200GB drive kicked the bucket this morning, and I have a new 500GB to replace it. I don't need a full 500GB for /, since most of my data is on /home/, but I could do with more space on /home/. Is there any way to transparently combine the disks?


I'm going to put Ubuntu Karmic on the new drive, and don't care what filesystem I use. I'm using reiserFS (I think reiser3, not certain) on /home/.


Answer



LVM is the best way I think, make sure to create a Volume Group (VG) that contains all your Physical Volumes (PV, i.e. your partitions), and then you can divide the VG into several Logical Volumes (LV) for your need.


LVM is not easy to grasp at first, and an image might help :


LVM Schema


I've also seen mdadm used together with LVM. mdadm provides a software RAID system to gather the various drives. If it's to make a RAID0 system (striped disks), it might not be worth it, but it gets interesting if you want to have a RAID1 (mirror) with your two drives, and still use LVM on top of it.


linux - basename command is outputting an 'enter' character along with the file name

I'am reading a text file line by line using while loop whose contents are directories and file names. I read the file names using basename command. I want to check if that file exists in a directory. But the below written code does'nt work. When i echo the basename command, it is outputting an 'enter' character along with the file name. How do i remove the 'enter character' ?


while read line;do
file=`basename "$line"`
dir=`dirname "$line"`
if [ -f "/data/config/${file}" ]; then
echo "${file} is present"
fi
done < /data/textfile.txt*

content of textfile.txt is given below


config/local/common/environment.properties
config/local/common/jmsservices.xml
config/local/common/ejbservices.xml

Tuesday, May 1, 2018

Batch Script - Parenthesized echo of the word "Where" issue


A while back I asked about Batch Script Redirection Syntax and received a nice answer. I've utilized the parenthesis () method more often to echo in batch scripts and redirect to files, etc.


I've run into an odd issue where it appears the word Where is not be able to be echo'd as that word literally and it seems it's interpreted as the Where command being invoked instead.




To keep this example simple, I've dumbed down the script logic to a much simpler version, but the PowerShell logic being echo'd could be much more complex than this.


Script Example


@ECHO ON
(
ECHO [System.IO.DriveInfo]::GetDrives() ^| Where {$_.Name -like "C:\"}
)>> Outfile.txt
PAUSE

Error



INFO: Could not find files for the given pattern(s).

enter image description here





What I've done


I troubleshot this a little and did some quick research and couldn't find a simple answer. Since I have not asked many questions on SuperUser, I figured this would be a good one potentially.


One thing in particular I tried was setting a variable as a string value of Where (i.e. SET w=Where) and then in the parenthesized echo commands I referenced that variable (i.e. %w%) in place of the word Where but the result is still the same error.


I also played around a little with SETLOCAL ENABLEDELAYEDEXPANSION but it made no difference.


@ECHO ON
SET w=Where
(
ECHO [System.IO.DriveInfo]::GetDrives() ^| %w% {$_.Name -like "C:\"}
)>> Outfile.txt
PAUSE



The Workaround


I have simply not been using the parenthesized method for echoing the word "Where" and I have just been utilizing the appended >> redirect to the file method on each echo'd line individually where "where" is involved. No big deal for this small example but a bigger deal for a larger script.


@ECHO ON
ECHO [System.IO.DriveInfo]::GetDrives() ^| Where {$_.Name -like "C:\"}>> Outfile.txt
PAUSE



Correlated Questions


Hmmmmm......



  1. What is causing this and what exactly is happening when this occurs?


  2. Is there a way to allow the word (or string) "Where" to be used without the issue?





Resources


Answer



You have misdiagnosed the problem - WHERE has nothing to do with it.


You simply need to escape the closing parenthesis:


@ECHO ON
(
ECHO [System.IO.DriveInfo]::GetDrives(^) ^| Where {$_.Name -like "C:\"}
)>> Outfile.txt
PAUSE

performance - What does the percent CPU mean?

I am watching my CPU percent utilization by a process. How does a process use only 50% CPU? Doesn't a process use 100% then 0%, then 100%? Its not like every other instruction is a different program.

display - Computer Freezes Up With Vertial Lines Across Screen and Audio Spazz

Here is a (terrible) photo (angled looking down) of the stripes:
Notice the purplish vertical stripes about every 1/10 of the time
Notice the purplish vertical stripes that appear evenly about 1/10 of the time.


My computer is randomly freezing up and showing lines across the whole screen, and freezing any audio (slightly after the screen freezes). The frozen audio means playing that last "frame" of sound forever.


It's happened to me four times, now, each time when I was pushing the 'f', 'a', 'b', and tab keys, and right and left-clicking a lot, when doing work in Blender 2.62.


It happened twice a few weeks ago when I was doing the repetitive task of pushing f, a, b, tab, and right-clicking in Blender. After the second crash I stopped doing the Blender work. I also think my computer itself started making a slightly different noise when it froze.


A few days ago I did a little bit more of the Blender f, a, b, tab, right-and-left-click work (doing some basic painstaking modeling), and there was no problem.


Then today, I decided to do some more of this modeling work, after thinking it was a one-time problem. I was surprised to see my screen completely replaced by the vertical blackish stripes across 100% of the screen. I took a video of it, then held down the power button for 5 seconds to kill the computer and booted it up again, and went back to more modeling. A few minutes later, it happened again.


These two times today I happened to be playing music, and I got some good results from it. It continued playing the music for about a second or less after the screen turned to dark stripes. Then it froze on the last bit (frame?) of sound it was playing, and continued playing that sound forever (like when a game freezes and the last tone keeps blurring out forever). The second time it happened today, it ended on a different sound and a different pitch came out. Pushing the mute button on the keyboard does not do anything to stop the constant sound. I went straight to posting here instead of trying Blender again, so it hasn't crashed yet.


I build my own computer, and here are its specs:
- Operating System - Windows 7 Professional 64 Bit
- Motherboard - Asus P8P67 Deluxe
- CPU - Intel i7-2600K
- GPU - Gigabyte ATi Radeon HD 6950 (newish but not newest driver)
- RAM - 16 GB of G.SKILL Ripjaws X Series
No sound card, just using the motherboard's default audio output.


The whole system is well cooled, and there is no way it's overheating from doing almost nothing with a very basic 3D mesh on screen. I've played graphic-intense games for hours, and run distributed computing on my graphics card overnight a lot. It's also a pretty cold day here.


I'm not sure if this is a coincidence with Blender or not, but the only times it's ever happened was while working in Blender. I've never seen software freeze up an entire computer, so that's why I'm posting here and not on the Blender forum (though I Googled it and couldn't find anyone using Blender with the same problem).


It couldn't be my monitor. I don't think it could be my graphics card, either, since the audio wouldn't freeze if it were just video output that died. Could it be my motherboard?


I would greatly appreciate help or tips to troubleshoot it. I know computers well, but I do not know what I should do here. Thank you so much!

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...