Tag Info

New answers tagged

1

A pipe, just like any file, is a stream of text (more precisely, a stream of bytes). The basic building blocks of Unix tend to be simple. Interactions between processes are mostly based on unstructured data. The operating system doesn't provide a communication channel with multiple streams labeled by a file name. If programs need this, they need to arrange ...


1

Are you talking about program1 file1.txt | program2 | program3 > folder/file1.txt program1 file2.txt | program2 | program3 > folder/file2.txt program1 file42.txt | program2 | program3 > folder/file42.txt program1 green.txt | program2 | program3 > folder/green.txt program1 indigo.txt | program2 | program3 > folder/indigo.txt program1 ...


0

First, why --exclude=* --include=* doesn't work: because the first matching rule applies. * matches everything, so everything is excluded, and rsync doesn't even try the second rule for any file. See Rsync filter: copying one pattern only for a guide to rsync filters. To include .mp3 files, you need rsync -a -m --include='*.mp3' --include='*/' ...


0

You don't need to worry about --include or --exclude for this situation. Just tell rsync to copy the mp3 files that are in the well-structured known places: cd /path/to/source rsync -avR */*/*.mp3 /path/to/target/ Perhaps instead you want to copy all the files in directories that contain an mp3. You can do that with this little loop, again assuming the ...


1

You're trying to do too much with rsync. The first thing to do is to produce the list of all the MP3 files. find Music -type f -iname '*.mp3' Then convert the list of files into a list of the directories that contain the files. sed 's:/[^/]*$::' Eliminate any duplication of directories in the list. sort -u Now you have the list of directories you ...


2

Most probably you have hidden files in the folder. The point is that glob * selects only files and folders that do not start with .. So, if they do they are not passed to du command. On the other hand from top directory you get size of the directory as a whole, including dot files. To match all files in given folder, including hidden ones try (with bash) ...


1

Putting quotes around some text disables expansions such as wildcards expansion and brace expansion. A logical way to remember this is that they produce a list of words, but contexts such as quotes ensure that the content is a single word. Furthermore you have spurious commas. In a shell script, words are separated by spaces. declare -a ...


1

shw@shw:/tmp $ ls testdir/!(*/) & pidls=$! [1] 18453 shw@shw:/tmp $ shw@shw:/tmp $ cat /proc/18453/cmdline bashshw@shw:/tmp $ shw@shw:/tmp $ shw@shw:/tmp $ kill -9 18453 shw@shw:/tmp $ [1]+ Killed ls --color=auto testdir/!(*/) shw@shw:/tmp $


5

In zsh you can reverse the globbing order: cat access.log.*(On) ~/test % ls 1 2 3 ~/test % cat 1 1 ~/test % cat 2 2 ~/test % cat 3 3 ~/test % cat * 1 2 3 ~/test % cat *(On) 3 2 1


2

cat $( ls | tac ) or simply cat $( ls -r )


4

Try this: ls -rt access.log* | xargs cat First list the files from oldest to newest and then cat each one of them.


4

You can use nullglob for bash return empty string when file name expansion fail : $ shopt -s nullglob $ a=(/tmp/nofileexists*.pdf) && echo ${#a[@]} && echo ${a[@]} 0 <blank line> Or using failglob to report error: $ shopt -s failglob $ a=(/tmp/nofileexists*.pdf) && echo ${#a[@]} && echo ${a[@]} bash: no match: ...


3

q1) Doing a ls -ld show me a . - why ? When you give no arguments to ls, the default is to run the command on the current directory, also known as .. Normally that means listing the contents of the directory, but you have used the -d option which requests listing the directory itself, not its contents. So you get the information for ., the current ...


2

The portable way to do this is with a case statement - and it doesn't hurt to trim the glob a little. for f in ~/common/.?*; do case $f in (*/..) ;; (*) : do something w/ "$f" esac done


5

Here is a method using bash's extglob: shopt -s extglob for f in .!(|.); do echo "$f" done With extglob the pattern !(pattern-list) matches anything except for the given pattern. The pattern in the example says match everything that starts with . and is not followed by nothing or another single ..


2

Using find find ~/common -type f -name ".*" -print0 | \ while read -d $'\0' file; do \ echo $file; \ done or with find and IFS find ~/common -type f -name ".*" -print0 | \ while IFS= read -rd '' file; \ do echo $file; \ done


0

.*[!.] for f in ~/common/.*[!.]; do echo $f done Will give you all .[...]foo but not . and .. Addition: Here's for excluding symlink files: for f in ~/common/.*[!.]; do [[ -L $f ]] || echo $f done .note: change || to && if you want to echo only symlink files.


1

You need to modify your glob pattern (currently *), probably you are looking for {[^.],.?}*, so for f in ~/common/.{[^.],.?}*; do echo "$f" done


1

Did you mean: ls -A also you can use ls -Al This wont list the . and .. (its the capital A that does that). a will list all, and A will list almost all, almost all cause . and .. arent listed. EDIT: The above is aimed at his second question, where he states he has the same issue with ls -a


-2

find . -maxdepth 1 -type f | while read f do ls -la "$f" done


1

You could use extended globbing if your shell supports it, e.g. bash: shopt -s extglob for f in NA*([[:alnum:]]).txt; do something; done zsh: setopt extendedglob for f in NA([[:alnum:]])#.txt; do something; done where *(...) and respectively (...)# mean zero or more occurrences.


1

for f in ./* do case ${f#??} in (*.*.*|*[!-_.[:alnum:]]*) ;; (NA*.txt) : do something w/ "$f" esac done The case statement allows you to branch code blocks for multiple possibilities. Though I make the above match for 2 or more dots or a not-dash-underscore-dot-alphanumeric character a no-op, you're just as free to put a ...


0

egrep should do: egrep 'NA[A-Z a-z 0-9]*\..{3,4}$' So ls /path/to/dir | egrep 'NA[A-Z a-z 0-9]*\..{3,4}$' would list: NAfoo.txt NAbar1.jpeg NA123baz.txt but would exclude: aiNA1foo.txt NA2foo_bar.jpeg NAbar.baz.txt And so on.


3

The code below will allow you to perform some action on text files starting with "NA", only having alphanumeric characters, and ending in ".txt". for f in /path/to/your/folder/*; do if [[ ${f##*/} =~ NA[a-zA-Z0-9]*.txt ]]; then # perform some action on $f fi done If you want to allow your file to start with "N" or "A" use this: for f in ...


1

Here a fast hack: #!/bin/bash for i in *; do if [ $(echo $i|cut -c 1-2) == "NA" ]; then EXECUTE_COMMAND fi done Did I understand your question correct?


2

Like this? for f in *.cut *.cut.bak do [ -e "$f" ] || continue f="${f%%.bak}" f="${f%%.cut}" [ -e "$f".mpg ] || [ -e "$f".rec ] || rm -i -- "$f".cut "$f".cut.bak done


0

As Chazelas points out, your script would fail if wildcard expansion matches more than one file. However, there is a trick I use (even I don't like it very much) to get around: PATTERN=(/*.txt) if [ -f ${PATTERN[0]} ]; then ... fi How it works? Wildcard expansion will match an array of filenames, we get the first one if there are some, otherwise null if ...


2

The command Forward=*R1*.at.fastq sets the variable Forward to the string *R1*.at.fastq (star, capital R, digit 1, star, dot, lowercase A, etc.). Wildcards are only expanded in contexts that allow multiple words; the right-hand size of a variable assignment expects a single word, so no wildcard expansion occurs. In a command like cat $Forward, the wildcards ...


13

The answer from @ubaid-ashraf is almost there. The way to specify file with no extension, in ksh would be: cp -- !(*.*) /new/path/ so that any file with dot in file name is skipped. For that to work in bash, you need to enable the extglob option (shopt -s extglob) and the kshglob option in zsh (set -o kshglob).


1

You can use find+grep to get only files that have no extension find . -maxdepth 1 -type f | sed 's/^\.\///' | grep -v "\." So your copy command will be cp ` find . -maxdepth 1 -type f | sed 's/^\.\///' | grep -v "\." ` destination_folder


5

You can do something like: cp -- !(*.txt) /path/to/directory The above code will copy all the files without .txt extension. You can also give multiple extension via pipe character. For example: cp -- !(*.txt|*.c|*.py) /path/to/directory



Top 50 recent answers are included