remove multiple files using terminal? - file

I want to delete two specific folders and a file from my current directory:
1. settings/
2. models/
3. file.txt
How do I remove these using single command in terminal?

rm -rf settings/ models/ file.txt

The solution provided by #jcpennypincher is correct for unix system since folders are functionally treated like files.
r stand for "recursive": delete files in directory and in its subdirectories and in its subdirectories etc...,
f stand for "force".
man rm
If you are looking for the same solution in windows (command prompt) it can't be done in just one command: files and folder in windows have different rappresentations. You have to use del for files and rmdir command for folders.

Related

Make a exclusion list + files list using winrar command line

I made this script below to make a backup of some files. It works fine, but i wanted make a list for the files that need be skipped from compressing.
For example:
my list.txt has all the files that will be compressed. But i wanted to make another list for the files that need be skipped, like exclusion_list.txt. Actually i put all files that i want be ignored from compressing into the command line, as shown below -x*\Test1 -x*\Test2.
But i really wanted to make a exclusion list for not keep changing the command line everytime i need to exclude a file or folder.
How i can do it?
"%winrar%\winrar.exe" a -x*\Test1 -x*\Test2 -ibck -ep1 -ilog%userprofile%\Desktop\log.log "compressed %date:/=.%.rar" "#list.txt"
From the documentation: the exclusion option -x also supports a list file when it is preceded by #:
"%winrar%\winrar.exe" a -x#exclusion_list.txt -ibck -ep1 -ilog%userprofile%\Desktop\log.log "compressed %date:/=.%.rar" "#list.txt"
with the file exclusion_list.txt containing:
*\Test1
*\Test2
By the way, there is even a console version of WinRAR, called rar.exe, which is a non-GUI version.

Iterate run inscript command line tool over all html files in subfolders

I would like to convert a large number of html files to txt files. I have downloaded the inscript command line tool from github but I am struggling to apply it to all html files which are located in subdirectories and then save these files as text files in the same directory where the html files are located.
I have tried:
for f in ./ do inscript.py -o test.txt done
The following should work:
for d in ./**/*/; do
pushd "$d"
for f in *.html(N); do
out=test-${f%.html}.txt
inscript.py -o "$out" "$f"
done
popd
done
The pattern .**/*/ will recursively match the current directory and all its subdirectories. pushd will change to a directory, but remember the current working directory. inscript.py does its thing, then popd returns to the original working directory so that the next value of d continues to be a valid
relative directory.
Changing the working directory isn't strictly necessary; it just simplifies the file paths involved, because you focus on the name of the file and ignore the rest of the path.

How to create a batch file that will zip few different files in one .zip file

I want to create a batch/shell script for windows and mac that will take few different files with different types and will compress it to a .zip file.
I already saw a few questions and answers about it, but all of them either compress all the files in the folder or compress them individually.
Example (look at attached image):
I have a folder that contains 1.txt, 2.xml, a sub directory.
And I want to turn all of them into a .zip file.
If possible to get a solution both for windows and Mac.
On Windows there is the file 7zip.chm in directory %ProgramFiles%\7-Zip which is the help file of 7-Zip. Double click on this file to open the help.
On Contents tab there is the list item Command Line Version with the help pages:
Syntax ... Command Line Syntax
Commands ... Command Line Commands
Switches ... Command Line Switches
The target is to compress everything in folder test into a ZIP file with name of the folder as file name.
This could be done for example with the command line:
"%ProgramFiles%\7-Zip\7z.exe" a -bd -mx=9 -r -y -- test.zip "C:\Path to Directory\test\*"
This command line adds (a) everything in directory C:\Path to Directory\test recursive (-r) to a ZIP file with name test.zip in current working directory without progress indicator (-bd) using best ZIP compression (-mx=9) with assuming Yes on all queries (-y).
In other words the file test.zip in current directory contains after execution the subdirectory main with everything inside and the files 1.txt and 2.xml.

How to unzip files that are in individual folders?

I own a MacBook Air. I'm trying to unzip all of these folders all at once instead of double clicking on each zip file that are in each directory. Is it possible? If so, how? For example, Folder 1 contains Cow.zip and Pig.zip, Folder 2 contains Dragon.zip, Dog.zip, and Cat.zip and
Folder 3 contains Hen.zip and Flowers.zip. Folder 1, Folder 2, and Folder 3, are in File called Animals.
Try this:
open ./*/*.zip
This will recursively traverse all the folders in the current directory and open all .zip files (i.e. "double click"/unzip).
If you need to unzip lots of files, use this command instead to avoid numerous pop ups. (Replace path/to/folder with the path that contains the folders with zips/more folders)
find path/to/folder -name "*.zip" | while read filename; do unzip -o -d "`dirname "$filename"`" "$filename"; done;

What does this command mean in batch?

I'm looking at a batch file and I see the line below. I know what %LOG% is, but I do not know what the "rm" command is doing. Can anyone tell me?
rm "%LOG%"
rm is a commandlet in Windows Powershell.
NAME:
Remove-Item
SYNOPSIS:
Deletes the specified items.
DESCRIPTION:
The Remove-Item cmdlet deletes one or more items. Because it is supported
by many providers, it can delete many
different types of items, including
files, directories, registry keys,
variables, aliases, and functions.
%LOG% is a variable defined in that batch file using
set LOG="Something"
(NOTE: It is not a global Variable or alias)
So what it will do is delete the item pointed by variable LOG.
The rm is a command that's being run, rather than anything special for the batch file. Does the system which ran this batch file include the cygwin package? That provides Windows / DOS versions of various standard unix utilities, including rm - which is the remove command - similar to del on such boxes.
%LOG% - variable that contain path to log file and that command remove it.
rm is not a standard ms-dos command. If you type it on the command line, what comes up?
perhaps it is short for rmdir (a synonym of rd) which removes the specified directory.
rm is the *NIX version of del
so its deleting %LOG%, unless it fails b/s its not a command on Windows. ( PowwerShell maybe)
Even if this is not Unix, rm is going to be a command to delete a file. For example, see http://www.mkssoftware.com/docs/man1/rm.1.asp or http://www.cygwin.com/

Resources