I am a new ubuntu user (have to use it for work) and I am trying to learn and familiarize myself with commands that I will be using frequently.
I would like some help in how I can get a list of all files with certain keywords in the filename.
Welcome to the UNIX & Linux Forums. We are here to help you.
Quote:
For example, I have a directory with numerous subdirectories that have a bunch of files in them. Two of those files contain the following format in the name: numericals_eddy_corrected.nii.gz and numericals_eddy_corrected_brain_mask.nii.gz.
I want to get a list of all the eddy_corrected.nii.gz and eddy_corrected_brain_mask.nii.gz files.
Please search the forum for similar questions that have already been answered before posting a new question. Without knowing what the format of other filenames in your directories, you could use a find command searching exactly for filenames ending with those two strings in the file hierarchy rooted in the current working directory:
If there aren't any other names containing eddy_corrected that end with nii.gz you could use the simpler:
Quote:
I am wondering, what command do I type in terminal so that I get a list, including the path, of all the files that have eddy_corrected in the name without the other eddy_corrected_brain_mask' showing up as well and vice versa? Is there a way to have terminal make a .txt file of the list?
The terminal application running in your window manager emulates a terminal from days of yore. The terminal application just emulates hardware, it doesn't run commands, it doesn't create file, it doesn't do anything except emulate a terminal device. When you start (or your system starts) the terminal application, you specify a program to run in that terminal window. Usually the program that you run in a terminal window will be a command interpreter such as bash, csh, ksh, or zsh. These command interpreters are known as shells. The commands recognized by different shells varies. All of the examples I'm suggesting in this post will work with bash, ksh, and zsh; some, but not all, will work in csh.
Adding > filename to the end of either of the above commands will redirect the output from those commands to the file named filename (creating the file if it does not exist, and overwriting its previous contents if it did exist). Using >> filename will append the output of those commands will create the file if it did not exist and append the output to the end of the file if it did exist.
Quote:
Second thing I need help with is renaming some files in those subdirectories. These files end in the extension .bvec and .bval and have absurdly long names with numbers in the format of subjectnumberDTISiementsTClessnumericals.bvec/.bval or 1000047785DTISiemensTCless005.bvec etc.
How can I rename all the files in the subdirectories to something simpler or shorter like subjectnumber_DTI.bvec?
You could try something like:
(this assumes that you want to preserve the .bvec or .bval at the ends of the pathnames) and if the output looks like it correctly supplies the proper arguments to rename files the way you want them to be, remove the echo shown in red and rerun the command to actually rename the files. If you want to the new names of all of the files to have the extension .bvec, change the two lines:
to be just:
Quote:
I have heard of find and grep but I'm not sure how to go about combining commands to achieve what I need to do.
I will be required to do similar tasks in the future so I figured I should learn it once and for all. I would appreciate any help.
If I have posted this in the wrong forum, please feel free to move it to the correct location.
This is a perfectly reasonable forum for this topic.
Quote:
Thank you in advance.
Moderator's Comments:
Please use ICODE tags, not B tags for partial line sample input, output, and code segments.
Hi,
I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern.
Note:These are the samples of two files,but i can have more... (2 Replies)
Hello,
i wanna rename my files which names are written in movies.txt
films.txt = amovie
bmovie
cmovie
dmovie
emovie
and i wanna find this files and rename the files to 1_amovie
... (12 Replies)
I want to rename the files by taking part of the file and appending date to it. please help
e.g.
abc-390.csv
xyz-908.csv
desired format is abc_YYYYMMDD.csv
This is what I have but it is not working
for each in *.csv;
do
mv $each /abc/data/"`date '+test_%Y%M%M'`".csv
done (2 Replies)
Hi,
I have a very urgent requirement here. I have to find all files in the specified directory but not in the sub directories(The directory name is stored in a variable) which are older than the current date as well as current time and rename it as filename_yyyymmddhhmmss.ext and move it into a... (7 Replies)
Hello,
I wanted to rename one file where filename contains space.. How can i rename in unix?
The file name is ABC XYZ.TXT
I wanted to rename this file as ABCXYZ.TXT.
Any help is greatly appreciated...
Regards. (4 Replies)
Hi All
I have a folder that contains hundreds of file with a names
3.msa
4.msa
21.msa
6.msa
345.msa
456.msa
98.msa
...
...
...
I need rename each of this file by adding "core_" in the begiining of each file such as
core_3.msa
core_4.msa
core_21.msa (4 Replies)
Hi
i have to achieve the following
i have files as xyz001.csv, xyz002.csv.......xyz0025.csv in a folder, i need to keep xyz001.csv as it is
but want to remove the extra zero on filename from 10 say
xyz0010 should be renamed to xyz010
xyz0025 should be renamed as xyz025
Note xyz... (8 Replies)
Hello,
I am looking for a command line that will rename name files :
f700_abc_o_t_MASTERID_AS_AE_20130323.csv
like this
f700_abc_o_t_MASTERID_AS_AE_20130324.csv
The great idea could be to get the date stamp 20130323
and change any part of it, instead of just change the... (4 Replies)
Hi,
In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this?
I am using #!/bin/ksh
For eg: sftp user@host <<EOF
cd /path
get *.txt
rename *.txt *.txt.done
... (7 Replies)