This question already has answers here:
How to copy a file to multiple directories using the gnu cp command
(22 answers)
Closed 6 years ago.
I have directory named "public" in every directory inside Documents.
I want to copy file named File.txt in every directory "public".
cp -r File.txt Documents/*/public/
doesn't seam to work. What should I do?
Well I'm very certain that using cp combined with xargs would do just what you want to do if you know how to use 'em... or you can just write a script to perform just that
Related
This question already has answers here:
How to delete a folder that name ended with a dot (".")?
(10 answers)
Closed 5 years ago.
I wanna create a file that file name end with a dot in Windows.
use "mkdir a.", but i only create a folder named with "a"
And I just wonder how to write a function to create such directory, thanks
mkdir \\?\c:\test2.
this creates a folder ending with (.)
provide drive letter
Use an extra dot and a trailing backslash:
mkdir a..\
But I highly recommend not to do so. You'll mess the directories up instantly.
This question already has answers here:
Create an empty file on the commandline in windows (like the linux touch command)
(27 answers)
Closed 5 years ago.
So far my project is all about creating files for an imaginary game and I have to create files (and files within files), first, I have to ask them what version they want, and then the batch will create new files on my computer.
I just want to know what is the command to create new files, no need for other info.
Yes, you can.
type nul > your_file.txt
It is already resolved here
Windows equivalent of 'touch' (i.e. the node.js way to create an index.html).
This question already has answers here:
Looping through the content of a file in Bash
(16 answers)
Closed 7 years ago.
I am trying to make a checkpoint management script, which will delete all checkpoints that are over 3 days old for a variety of databases.
I want to keep the code in one script and then keep a list of all the paths to each database I want to manage in another.
How do I reference the file with the list of databases, so I can use them in a for loop?
In the loop, how do I change directories to each directory listed in the text file?
Ex. File with list of databases (db.list):
/directory/directory/databse1
/directory/directory/databse4
/directory/directory/databse10
Ex. Code:
for database in db.list
do
cd $database
code
done
A file listing database paths wouldn't be called a script. It just a text file.
To iterate over lines of a text file, you can read the file:
while read -r database ; do
echo "$database"
done < db.list
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Delete all but the most recent X files in bash
The scenerio is as follows:
Two tar files will be created in one directory per day, but I need only the latest two files, so how to delete the other files automatically each day?
Is i possible to write this script using pure shell commands, and not with high level language such as perl, python or ruby...
This issue is a bit similar to FTP - Only want to keep latest 10 files - delete LRU and how to delete all files except the latest three in a folder
but mine also needs to test if a tar file is corrupt
If newer tar file is corrupt, I would not keep it, but reserve the older ones, so what the script should be like?
Obviously this is solvable using a two pass approach.
Detect and remove corrupt tar files.
Remove all but the latest N files as described in the referenced question.
The first pass could be performed with something along
for t in *.tar; do
if program_that_checks_tar_file_for_integrity $t; then
: # OK
else
rm $t
fi
done
This question already has answers here:
How can I create nonexistent subdirectories recursively using Bash?
(4 answers)
Closed 6 years ago.
Why I can't do something like this? mkdir folder/subfolder/ in order to achive this I have to do:
mkdir folder
cd folder
mkdir subfolder
Is there a better way to do it?
You can:
mkdir -p folder/subfolder
The -p flag causes any parent directories to be created if necessary.
To create multiple sub-folders
mkdir -p parentfolder/{subfolder1,subfolder2,subfolder3}
FWIW,
Poor mans security folder (to protect a public shared folder from little prying eyes ;) )
mkdir -p {0..9}/{0..9}/{0..9}/{0..9}
Now you can put your files in a pin numbered folder. Not exactly waterproof, but it's a barrier for the youngest.