Sida loo abuuro file cusub ee Powershell?

new-item keyword creates a new file in the filesystem. The type of item new item creates depends on where the item is being created. Tusaale ahaan, item cusub ayaa sidoo kale abuuri kartaa furayaasha diiwaanka iyo entries haddii loo isticmaalo diiwaanka.

Type the following command in to create a new file in the current path:

ni {filename.extension}

 

The above is the alias for the following command

cusub-item {filename.extension}

 

tusaale

ni fun.txt

 

Beegyada uu sidoo kale loo isticmaali karaa wax cusub.

soo socda wuxuu abuuraa file ah ee Jidka hadda la content qaar ka mid ah:

ni -n fun.txt -p . -it f -v 'this is some silly text'

 

In the above example we have added the -name, -path and -itemtype parameters with their default values. Omitting these will generate the same result.

ni fun.txt -v 'this is some silly text'

 

If you want to overwrite an existing file use the -force or -f parameter:

ni fun.txt -v 'this is some silly text' -f

 

Abuur files badan ee buugga tusaha hadda:

ni -it f -p 'file.txt', 'fun.txt'

 

Create multiple files in the c:/ root and things directory

ni -it f -p 'c:\file.txt', 'c:\things\fun.txt'

 

Creating Directories

You can create a new directory instead of mkdir or md by using the new item command and setting the item type as directory.

ni fun -it d

 

Abuur buugga cusub ee xididka c ah:

ni -n fun -it d -p c:\

 

Abuur tusaha badan ee jidka hadda:

ni -it d -p 'fun', 'Doqon'

 

Create multiple directories in the c:/ root and things directory

ni -it d -p 'c:\folder', 'c:\things\fun'

 

The following table shows the parameters and it’s alias

Parameter alias tusaale Description
-name
-n or no parameter
ni fun.txt
Specify the new item’s name
-itemtype
-it
-it d ama -it dir ama -it directory
-it f ama -it file
Specify the type of item to create. Creates file by default.
-force
-f
-f
Overwrite existing file.
-value
-v
-v 'Some file content...'
Write content of file
-path
-p
-p c:\
Path of where the new item should be created

Some commands that is useful with the ni command:

lsGet-ChildItem, lists files and directories of the current working directory. tusaale ls

gcGet-Content, view the contents of a file eg. gc fun.txt

mdmkdir, make directory eg. md mynewdirectory

rmRemove-Item, remove directory or file

 

Official Microsoft Docs

 

Leave a Reply