Answer to Question #301864 in UNIX/Linux Programming for Sunitha

Question #301864

Write Shell script to perform operations like display, list, make directory and copy, rename, delete, edit file.


1
Expert's answer
2022-02-25T03:40:10-0500

The following command renames a file:

Rename-Item -Path "\\fs\Shared\temp.txt" -NewName "new_temp.txt"


This command to copy files from a remote file server to the local C: directory:

Copy-Item \\fs\c$\temp -Recurse C:\data\


Example of Shell script to Delete files from multiple computers in one script

$filelist = @(" \c$\Temp", "\c$\Backups") #variable to delete files and folder
$computerlist = Get-Content  C:\data\pc.txt #get list of remote pc's
    foreach ($computer in $computerlist){
        foreach ($file in $filelist){
            $filepath= Join-Path "\\$computer\" "$filelist" #generate unc paths to files or folders
            if (Test-Path $filepath)
            {
            Remove-Item $filepath -force -recurse -ErrorAction Continue}}}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS