Creating file in all system directories and displaying their paths LINUX - linux

I have a problem with a task I've been given "Create files in each system directory and display the paths to those files". As I understand I need to create a file in all of the directories, I tried with using find . -type d -exec touch {}/file \; but I don't think it's what im asked for.

Related

How to list down the full paths to all files in multiple directories of a certain file format?

I am looking for a Bash solution to my dilemma here. I have directory project, and within that I have project/Batch1 project/Batch2 project/Batch3 and so on.
Within each Batch folder, I have a mix of files but what I am interested in are files in the .txt format, for example. I am able to recursively acquire the names of every file in my project directory using the ls -LR command. However, how should I get full paths including the file names, and also only for .txt files?
Thanks!
Use find command. Open man 1 find and check possible option you need for above task.
Here is the simple example. Open terminal and run
find pwd -type f -name "*.txt"
Or
find pwd -name "*.txt"
Or you can do same using bash script also.

Eliminating subfolders to move all files into one folder

I have a folder that contains 32 folders, each with several image files. I would like to move all of these image files into one main folder. I know how to do that manually, folder by folder. Is there an automated command-line way to do that? I have Crunchbang Waldorf, and usually use PCmanFM as a file manager.
/*/ stands for directories.
mv /path/from/*/*.jpg /path/main/
if all these images have one extension, for instance .jpg:
find /directory/You/Want/To/Search -name "*.jpg" -exec cp -t /destination/directory {} +
Note: just make sure that all these images have one unique name otherwise this command would break
UPDATE:
if you don't know what are the images extensions you could just do that one:
find /directory/You/Want/To/Search -regex ".*\.\(jpg\|gif\|png\|jpeg\)" -exec cp -t /destination/directory {} +

Linux command to create the empty file called 'test1'

Enter a Linux command to create the empty file called 'test1' in the directory 'systems' (you are still in your home directory).
Assuming 'systems' is a subdirectory of the current directory:
touch systems/test1
Assuming that you only know that the directory 'systems' is some subdirectory in the directory tree of the current directory then: find . -name systems -type d -exec touch "{}/test1" \; Will create such a file. Alternately, so will find . -name systems -type d -execdir touch systems/test1 \; However, both will do so in every subdirectory named 'systems' in the current directory tree. We could limit that action to only the first, the last, or some other criteria, but the list of possible permutations is just too long.
You really have not provided enough information for us to provide a complete answer.

Rsync make flat copy

I'm trying to write a script that copy all the files of one dir (with subdirs) to the root of another dir.
So Imagine I have this file structure:
/
pic.JPG
PIC5.JPG
FOLDER
pic2.JPG
pic3.JPG
FOLDER2
pic4.JPG
I want all the .JPG files from that directory and copy them over to another destination. But I don't want the directory structure, just the files.
This is what I've got:
"sudo rsync -aq --include '*/' --include '*.JPG' --exclude '*\' /source/picturesRoot/ /destination/flatView/
But it also copies the directories :(
I found this link on stackoverflow:
rsync : Recursively sync all files while ignoring the directory structure
I looked at the solution and didn't see much difference with my command, apart from the * and . in the path. I tried it but it didn't work.
I hope somebody can help me, thanks.
This answer cannot work for you because your pictures are not at the same level in directories. There is no option in rsync to skip the creation of directory structure. In the link you gave, it's working because the user explicitly select source files with *.
You can try something with find and rsync. Find will find files and rsync copy them.
Here is a solution :
find /source/picturesRoot -type f -name "*.JPG" -exec rsync -a {} /destination/flatView/ \;
Be careful, if two files have the same name just one will be in destination directory.

Command Line to find and delete Similar files in Linux

I want to find and delete all the "similar files as shown below" recursively from the specified directory of my Linux Server by Using COMMAND LINE....
"file.php?p=10&file=load%2Fnew Animations 1%2FAwesome_flowers-(text1).gif&sort=0"
"file.php?p=10&file=load%2Fnew Games 1%2FAwesome_flowers_-(text1).gif&sort=1"
Note: All these files having different file sizes and The mathed text is in all files is "file.php?p***"
This should help you to delete files recursively..
find /path/to/dir -type f -name 'file.php\?p*' -exec rm -i {} \;

Resources