Linked Questions

240 votes
9 answers
328k views

I wrote the following script to diff the outputs of two directores with all the same files in them as such: #!/bin/bash for file in `find . -name "*.csv"` do echo "file = $file"; diff $...
Amir Afghani's user avatar
  • 7,373
4 votes
2 answers
3k views

Ubuntu 16.04 #!/bin/bash site="hello" wDir="/home/websites/${site}/httpdocs/" for file in $(find "${wDir}" -name "*.css") do echo "$file"; done exit 0; shellcheck warns me even if I define the ...
Vituvo's user avatar
  • 411
3 votes
1 answer
2k views

I am trying to recursively convert all .mkv files in a folder structure with subfolders to .mp4. I got a standard line that works in just the present folder for video in *.mkv; do ffmpeg -i "$...
Dr_Bunsen's user avatar
  • 145
3 votes
2 answers
2k views

The following link recommends against using loops in shells. bash variables in for loop range Why is this? Here is an example loop I just happened to be looking at when I came across that answer: ...
Zombo's user avatar
  • 1
2 votes
3 answers
420 views

Currently, I am trying to parse out all the files inside a directory. I have a find function, but it appears to not be able to parse in file directories with whitespaces into a loop. Here, "$DIR" is ...
user321627's user avatar
1 vote
3 answers
678 views

I would like to copy many files with the below command. cp `find /Volumes/DATA/ -name "*.app" -depth 1 2> /dev/null` /Volumes/VMWare/img/ But that doesn't work because if it finds a space then it ...
The33Coder's user avatar
1 vote
2 answers
561 views

If I want to find any files with .txt in the name, and for every match that is found copy it into the /junk folder, I understand I could use the following: find / -name ".txt" -exec cp {} /junk \; ...
microscope's user avatar
0 votes
1 answer
773 views

I want to list the size of directories under a given root (using du -hs) . The issue is that where the directory names have spaces the du command is getting each word of the name as a whole directory ...
Stephen Boston's user avatar
1 vote
3 answers
139 views

for X in $(find ~/Documents/ -type f);do date -r "${X}";done The above line works fine when the filenames in "/Documents/" contain no space. However, if the filenames contain a ...
Matthew Wai's user avatar
0 votes
0 answers
802 views

I have a music library that I am trying to restore from backup. The original source library was on a QNAP NAS and I copied it over to a CentOS system without any problems. Now that I am trying to copy ...
alpha754293's user avatar
0 votes
1 answer
130 views

I'm trying to run join a bunch of files using the find command. I have determined that filenames containing spaces are giving me a problem. The following comand works for files that do not contain ...
speld_rwong's user avatar
1 vote
1 answer
95 views

I have a file test.txt which contains file names like below where some file names will have spaces and some will not. Mon - Tue corrected item.csv Sat -Sun incorrect item.csv Wed_THU_corrected_item....
deepak's user avatar
  • 21
0 votes
0 answers
104 views

How can the script below be made to always work no matter the filenames returned by find ? #!/bin/sh cmds_should_always_work() { echo "\n\n*********************************" $1 stat --...
TrevTheDev's user avatar
0 votes
1 answer
74 views

I have the below folder structure in Linux env: |-- Fixed_Zip | |-- ipython_notebooks | | |-- notebook editor for compute_0anXhGEj.ipynb | | |-- notebook editor for compute_aucScores.ipynb | ...
arielma's user avatar
  • 243
0 votes
0 answers
19 views

I'm trying to loop through each files from current directory and subdirectories. But the problem is file names with blank-space are getting treated as separate files. How do I prevent that. I want to ...
user avatar
540 votes
14 answers
932k views

I have a folder with some directories and some files (some are hidden, beginning with dot). for d in *; do echo $d done will loop through all files and directories, but I want to loop only through ...
rubo77's user avatar
  • 30.6k
787 votes
6 answers
1.3m views

I'd like to find the files in the current directory that contain the text "chrome". $ find . -exec grep chrome find: missing argument to `-exec' What am I doing wrong?
ripper234's user avatar
  • 32.5k
386 votes
14 answers
733k views

I would like to list all files in the order of big to small in size and the files could be present anywhere in a certain folder.
Joe's user avatar
  • 3,993
282 votes
10 answers
99k views

I consistently see answers quoting this link stating definitively "Don't parse ls!" This bothers me for a couple of reasons: It seems the information in that link has been accepted wholesale with ...
mikeserv's user avatar
  • 59.4k
378 votes
6 answers
421k views

… or an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
Gilles 'SO- stop being evil''s user avatar
288 votes
5 answers
79k views

Is using a while loop to process text generally considered bad practice in POSIX shells? As Stéphane Chazelas pointed out, some of the reasons for not using shell loop are conceptual, reliability, ...
cuonglm's user avatar
  • 158k
169 votes
6 answers
423k views

I've got 14 files all being parts of one text. I'd like to merge them into one. How to do that?
Ivan's user avatar
  • 18.5k
145 votes
8 answers
68k views

The xargs command always confuses me. Is there a general rule for it? Consider the two examples below: $ \ls | grep Cases | less prints the files that match 'Cases', but changing the command to ...
Zaid's user avatar
  • 11k
124 votes
6 answers
319k views

I am searching for files which name which contain AAA within their path using following command: find path_A -name "*AAA*" Given the output showed by the above command, I want to move those files ...
huahsin68's user avatar
  • 1,967
149 votes
4 answers
199k views

I am using find and getting a list of files I want to grep through. How do I pipe that list to grep?
James's user avatar
  • 5,086
196 votes
2 answers
210k views

I find myself constantly looking up the syntax of find . -name "FILENAME" -exec rm {} \; mainly because I don't see how exactly the -exec part works. What is the meaning of the braces, the backslash ...
Zsolt Szilagy's user avatar
55 votes
16 answers
35k views

I somehow managed to create a file that doesn't seem to have a filename. I found some information regarding how to get more details of the file in the following thread. However, I tried some of the ...
Mr Moose's user avatar
  • 725
98 votes
5 answers
144k views

I am working through SSH on a WD My Book World Edition. Basically I would like to start at a particular directory level, and recursively remove all sub-directories matching .Apple*. How would I go ...
codedog's user avatar
  • 1,083
37 votes
14 answers
63k views

I have created the following script that move old days files as defined from source directory to destination directory. It is working perfectly. #!/bin/bash echo "Enter Your Source Directory" read ...
KK Patel's user avatar
  • 1,885
49 votes
4 answers
27k views

I have a bash script looping through the results of a find and performing an ffmpeg encoding of some FLV files. Whilst the script is running the ffmpeg output seems to be interupted and is outputting ...
Mark Williams's user avatar
28 votes
8 answers
60k views

I have a directory in which I would like to list all the content (files and sub directories) without showing the symbolic links. I am using GNU utilities on Linux. The ls version is 8.13. Example: ...
TheMeaningfulEngineer's user avatar
36 votes
7 answers
130k views

I have a directory with crash logs, and I'd like to use a conditional statement in a bash script based on a find command. The log files are stored in this format: /var/log/crashes/app-2012-08-28.log ...
cwd's user avatar
  • 47.1k
32 votes
3 answers
72k views

I want to copy over .jpg and .png files with scp, but there files with different extensions in the same folder I'm copying from. I am doing the following: scp [email protected]:/folder/*.{jpg,...
sodiumnitrate's user avatar
23 votes
4 answers
31k views

I want to write a Bash script to convert every .pdf file in the current directory into a .png file. For example: $ls . a.pdf b.pdf $./pdf2png.sh Converting pdfs to pngs a.pdf -> a.png b.pdf -> ...
I Like to Code's user avatar
23 votes
5 answers
55k views

My current best bet is: for i in $(find . -name *.jpg); do echo $i; done Problem: does not handle spaces in filenames. Note: I would also love a graphical way of doing this, such as the "tree" ...
Vorac's user avatar
  • 3,237
22 votes
3 answers
50k views

I tried finding some files (*.e*) that are in the same directory as another file (md.tpr). I needed to list them (for further processing) using the following: find . -name md.tpr -execdir ls *.e* \; ...
Wojtek's user avatar
  • 2,352
15 votes
5 answers
51k views

I want to copy and rename multiple c source files in a directory. I can copy like this: $ cp *.c $OTHERDIR But I want to give a prefix to all the file names: file.c --> old#file.c How can I do ...
BlackCat's user avatar
  • 405
19 votes
7 answers
24k views

Naive approach is find dir1 dir2 dir3 -type d -name .git | xargs -I {} dirname {} , but it's too slow for me, because I have a lot deep folder structures inside git repositories (at least I think that ...
user1685095's user avatar
10 votes
4 answers
38k views

I have a collection of files ( *.zip, *.txt, *.tar.gz, *.doc, ...etc ). These files reside within a path. I want to find all the files ( *.txt), then copy, only, the text files that contain specific ...
user avatar
14 votes
4 answers
41k views

If I just use basename {} .txt, it will work: find . -iname "*.txt" -exec basename {} .txt \; It will just print xxx instead of ./xxx.txt. If I use $(basename {} .txt) in the -exec option, ...
Wang's user avatar
  • 1,435
8 votes
8 answers
7k views

I'm trying to figure out how to get total number of lines from all .txt files. I think the problem is on the line 6 -> let $((total = total + count )). Anybody knows what's to correct form of this? ...
Ota Škvor's user avatar
14 votes
4 answers
54k views

What command do I have to use to delete all directories that begin with graphene-80 under the directory /tmp? What can I add to the rm command as option?
Thouraya's user avatar
  • 149
14 votes
4 answers
6k views

I want to find a subdirectory of the current directory, which (that is the subdirectory) contains 2 or more regular files. I am not interested in directories containing less than 2 files, neither in ...
porton's user avatar
  • 2,236
12 votes
4 answers
4k views

Given these file names: $ ls -1 file file name otherfile bash itself does perfectly fine with embedded whitespace: $ for file in *; do echo "$file"; done file file name otherfile $ select file in *; ...
DopeGhoti's user avatar
  • 79.2k
14 votes
2 answers
23k views

I was just trying to list all directories and files under current directory and also write if they are file or directory with the following command: find -exec echo `echo {} : ;if [ -f {} ]; then ...
Esref's user avatar
  • 563
5 votes
6 answers
1k views

I have a few million .jpg files and I want to generate a .jpg.webp version for each one (foo.jpg -> foo.jpg.webp). For this, I need to find all files ending in .jpg for which there’s no .jpg.webp ...
bfontaine's user avatar
  • 173
4 votes
8 answers
6k views

How do I name one random file in the deepest level of a directory tree using basic Bash commands and script? I was searching for a way to do it as an one-liner and without functions. Assuming also ...
Robert Sundström's user avatar
5 votes
4 answers
16k views

I have hundreds of files in various different subdirectories. Some of them have the correct file extension, but some of them don't. I want to rename all files that don't have a file extension and ...
ThoWe's user avatar
  • 153
9 votes
3 answers
14k views

I have a folder with 137795 files in it. I need to delete all of them. When I run rm * I get -bash: /bin/rm: Argument list too long. How do I get past this error?
David Oneill's user avatar
  • 1,218
5 votes
7 answers
10k views

I have a file with a long list of filenames (with full paths). I've also got a program I'd like to run multiple times, using one and one filename from this list as argument. The program I'd like to ...
Baard Kopperud's user avatar

15 30 50 per page
1
2 3 4 5 6