I have a main directory and its sub-directories as;  main_directory == main_directory  0001 0102 0203 ... == first order sub_directories  001 002 003 ... == second order sub_directories  I use below command to merge all data.txt files in the second order sub_directories  find path_to_main_directory -name '*data.txt' -exec cat {} + &gt; data_all    However, I see that data_all file doesn't seem orderly, such as (which I want); 0001/001+0001/002+.... it seems that the order is random.  Is there a way to merge all files orderly?
121770
I use the command  find . -type f -exec sha256sum {} \; &gt; sha256SumOutput   to hash every file in a folder hierarchy. Unfortunately, sha256sum doesn't get the file names from find in alphabetical oder. How can this be fixed?  I'd like to have them ordered before they are hashed so they are hashed in alphabetical order (this has a reason).
59954
I have around 100,000 files in a directory. As you can imagine, that's not an ideal situation, and I'd like to split the directory up into subdirectories. But the filenames aren't such where I can put them into subdirectories based on their names or anything, so I'd like to create, say, 10 directories and put about 1000 files in each. Is there an easy bash command or loop that would do this?
29714
If I have a large file and need to split it into 100 megabyte chunks I will do  split -b 100m myImage.iso   That usually give me something like  xaa xab xac xad   And to get them back together I have been using  cat x* &gt; myImage.iso   Seems like there should be a more efficient way than reading through each line of code in a group of files with cat and redirecting the output to a new file. Like a way of just opening two files, removing the EOF marker from the first one, and connecting them - without having to go through all the contents.  Windows/DOS has a copy command for binary files. The help mentions that this command was designed to able able to combine multiple files. It works with this syntax: (/b is for binary mode)  copy /b file1 + file2 + file3 outputfile   Is there something similar or a better way to join large files on Linux than cat?  Update  It seems that cat is in fact the right way and best way to join files. Glad to know i was using the right command all along :) Thanks everyone for your feedback.
20596
Given the following structure:  source/   dir1/    file1.ext1    file2.ext2   dir2/    file3.ext3     dir3/      file4.ext4   I want to achieve the following:  destination/  dir1file1.ext1  dir1file2.ext2  dir2file3.ext3  dir3file4.ext4   In other words, I want to move all the files, recursively, from source to destination, appending the original subdirectory name to the file name.
62517
Is the expansion of a wildcard in Bash guaranteed to be in alphabetical order? I am forced to split a large file into 10 Mb pieces so that they can be be accepted by my Mercurial repository.  So I was thinking I could use:  split -b 10485760 Big.file BigFilePiece.   and then in place of:  cat BigFile | bigFileProcessor   I could do:  cat BigFilePiece.* | bigFileProcessor   in its place.  However, I could not find anywhere that guaranteed that the expansion of the asterisk (aka wildcard, aka *) would always be in alphabetical order so that .aa came before .ab (as opposed to be timestamp ordering or something like that).  Also, are there any flaws in my plan? How great is the performance cost of cating the file together?
90028
I'm running similar commands on (e.g.) a set of files. As an example, let's say I'm doing something like this (this isn't what I'm doing, it's just an example):  &gt; cat path/to/dir/file01.txt   [file contents] &gt; another-command path/to/dir/file01.txt   [more output] &gt; cat path2/to/dir/file02.txt   [file contents, from which I can tell I should do something different] &gt; different-command path2/to/dir/file02.txt   [yet more output] &gt; cat path3/to/dir/file03.txt   [file contents] &gt; another-command path3/to/dir/file03.txt   [output]   etc.  It would be convenient if, after using the &uarr; key to return to a previous command, I could overwrite non-duplicated text ― like the file name, or a common part of the path — rather than having to delete it and retype it.  Is there a way to do this?
95620
I've been using mkvmerge to merge a video file and subtitles, I'm using the following command  mkvmerge -o output.mkv video.mp4 subtitles.srt   Which is working fine but as you can probably guess this is really slow operation   I've to open terminal in every one of those directories where movies are stored. Then I've to copy and paste the names of the files in the command Then I've to rename the output file Then delete the original files which I used   This is a lengthy process.     Ideal situation that I want.   I'll go into the folder which contains a movie file and a subtitle file with the same name. I select a movie file and and a subtitles file, right click and run a nautilus script on them. They get merged Original file gets deleted. Rename the merged file with the name of the orignal file with mkv extension      This doesn't need to be recursive, I don't want my HDD creating and deleting 100's of files at ones. Movie files and Subtitle files generally have the same name but some times have "_en" post fixed to subtitle files. If you have another approach of doing it I'm on board with that too.
70689
Now,I have two files:  aaaa.txt:  a=0; b=1; c=2;   bbbb.txt:  d=3 e=4 f=5   I want to merge aaaa.txt and bbbb.txt to cccc.txt.   cccc.txt as follow:  a=0;d=3 b=1;e=4 c=2;f=5   So, what can I do for this?
44386
I have a directory filled with various files, differently named (i.e. not named with a specific pattern) and with different extensions, and I want to put each file in a newly created subdirectory named after each file; what's the best way to accomplish that from the command line under Linux? This sounds a bit confusing, let me make and example: let's call a random file in the directory ./filename.ext, I'd like to put it in a subdirectory called ./filename so that effectively the new path will be ./filename/filename.ext.  I did some trials with the following steps:   I've created some test files, from file-1.txt to file-9.txt, inside a test directory with for num in {1..9}; do touch file-$num.txt; done  I've created a directory named after each filename with for name in $(eval ls | cut -b 1-6); do mkdir $name; done I've moved the source files in their respective directories with for name in $(eval ls | grep -e ".txt" | cut -b 1-6); do mv $name.txt $name/$name.txt; done   As you can see, this solution works, but its huge drawback is that it works just in this case, with files of that extact filename lenght and with that particular extension. If I have some files with different names and extensions, this would be of no use at all. The use of cut command is not the ideal solution here, I suppose, but I haven't found anything better at the moment.  As a bonus, it would be cool to find a way to create the subdirs automatically when moving/renaming the files, without having to use mkdir previously (so when I ls to actually rename, I don't have to worry about excluding the newly created directories); but in the end this is a secondary problem.
4886
If I understand the cat manual correctly:       concatenate files and print on the standard output   cat will take files as argument and print them on standard output. What I don't get is if I use the command:    cat img.png &gt; copy.png   I will obtain 2 png files identical while if I just    cat img.png     I have all chance that my terminal get messed up and misinterpret what I type.     How's that possible?   Binary values are still binary data. Why it does not simply shows a series of 0 and 1 or the interpretation of those binary data in ASCII or whatever the encoding in terminal is?   Is this behavior also possible by cating a text file containing strange characters?   Should a mechanism to prevent this behavior  like try{}catch{} statement should be implemented?
114942
I'm trying to combine two different files, one called itemnum and another called items.   itemnum contains:  ItemNumber 1201 1221 1320 1340 1410   and items contains:  Item Lobby Furniture Ballroom Specialties Poolside Carts Formal Dining Specials Reservation Logs   I want to use join here right? So that the output looks like this:  ItemNumber:Item 1201:Lobby Furniture 1221:Ballroom Specialties 1320:Poolside Carts 1340:Formal Dining Specials 1410:Reservation Logs   I can't even figure out how to get them to join, let alone add the :  I tried join itemnum items &gt; prodinfo, but that just gives me an empty file.
50976
I am bit of a batch file noob, so I'd really appreciate your help. I have a ton of files stored in a single directory which I wish to sort into subfolders based on the first word in their filenames. So, I have files like these:  C:\Folder\Wedding2018 img20929.jpg  C:\Folder\Wedding2018 entrance.mov C:\Folder\Wedding2018 registry of guests.pdf  C:\Folder\HorseRiding2017 spirit1.jpg C:\Folder\HorseRiding2017 guests.txt  C:\Folder\HorseRiding2017 certificate.pdf C:\Folder\HorseRiding2017 jumping.mov   And I wish to move all files to subfolders based on the first word, ending up like this:  C:\Folder\Wedding2018\img20929.jpg C:\Folder\Wedding2018\entrance.mov C:\Folder\Wedding2018\registry of guests.pdf  C:\Folder\HorseRiding2017\spirit1.jpg C:\Folder\HorseRiding2017\guests.txt C:\Folder\HorseRiding2017\certificate.pdf C:\Folder\HorseRiding2017\jumping.mov   I've found a couple of scripts that almost do what I need, but I don't have the chops to bring it home:       I just can't work out how to integrate the script to grab the first word and make a directory to which the files will be moved.  Can you help me get this across the line?
121234
I have a bunch of files like this:  C:\G\G1\35antique-shop.mp3 C:\G\G2\35antique-shop.mp3 C:\G\G1\09saguri.mp3 C:\G\G2\09saguri.mp3   I just want to know how to keep the folder structure while archiving. This is more important than the duplicate thing, to know how to solve that, would be a bonus.     @Lamb "Do you want to archive only selective files (not the whole folder content) from the G1 and G2 folders?"   That almost says it all, but I'll try to improve: Not only do I want to move only some selected files to an archive. I also have a list of these files, including path-names to each file.  So, in SubDir1 there might be 10 files, of which I want to zip three, and in SubDir1\sub2 there might be five files, of which I want to zip all five. The files that I need to archive are in a listfile.  There might be duplicate files, so my hope is that with subdirectories added, 7-Zip does NOT see them as duplicates.  And I like to do it on the command line.  I've tried a batch file like this:  7z a -r MyArchive.7z C:\G\G1\35antique-shop.mp3 7z a -r MyArchive.7z C:\G\G2\35antique-shop.mp3 7z a -r MyArchive.7z C:\G\G1\09saguri.mp3 7z a -r MyArchive.7z C:\G\G2\09saguri.mp3   This also means that files 01antique-shop.mp3, 02antique-shop.mp3, ...., til 33antique-shop.mp3 and 34antique-shop.mp3, should NOT be archived.  The foldernames (=subdirectories) weren't added to MyArchive.7z, and this is the problem.  Obviously, I'd like to use just one commando with a listfile, but that doesn't work either.  I've tried:  7z a -mx0 -tzip C:\$$-edrive\F-G-H.zip @fgh.txt   which actually works pretty fine as far as the selecting goes, but it does NOT keep the directory structure. Sadly.  How do I do this?
18451
I have a 2 files with the following:   File1.txt  A 1 B 2 C 5 Z 3  File2.txt A 4 B 7  C 10 D 11   What I would like to do is create something like   A 1 4  B 2 7 C 5 10 D - 11 Z 3 -   Is there a utility that does this? If not how Can this be done? Using a find and awk or something?
3477
I don't quite understand how the computer reads this command.  cat file1 file2 1&gt; file.txt 2&gt;&amp;1  If I understand, 2&gt;&amp;1 simply redirect Standard Error to Standard Output.  By that logic, the command reads to me as follows:    concatenate files file1 and file2.  send stdout from this operation to file.txt. send stderr to stdout. end?   I'm not sure what the computer's doing. By my logic, the command should be   cat file1 file2 2&gt;&amp;1 &gt; file.txt   but this is not correct.
83439
I have a directory full of files with names in this format (with numbers as the start of each filename):  102_file.txt 104_list.txt 242_another_file.txt   I would like to rename them as follows (i.e. removing the numbers):  file.txt list.txt another_file.txt   Can anyone suggest a way to do this (presumably from the terminal)?
42446
I have a directory that I am trying to clean out that contains both files and subdirectories.  What I am trying to do is simple: move all the files into another directory, but leave all the sub-directories as they are.  I am thinking something like:  mv [*_but_no_dirs] ./other_directory   It seems like there should be a simple way to do this with wildcards * and regex...  Anyone have ideas?