Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Favorites infavorites:mine
infavorites:1234
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with Search options answers only user 22142

Manipulating files: copying, renaming, searching, analyzing, archiving, etc. For operating on text in a file, see /text-processing. For questions about the Files file manager (formerly Nautilus), see /nautilus.

1
vote
You could use set, process batches of 100 files via "${@:START:COUNT}" (range of positional parameters) and shift 100 while incrementing a counter c to create the directories: set -- *.pdf c=1 while …
answered Jul 13 '17 by don_crissti
2
votes
You have to extract the directory part, the file name and then the chars preceding the first underscore (since all files are .wav there's no point to save the extension in a separate variable): find … /home/scott/ -maxdepth 4 -type f -name '*_*.wav' -exec sh -c 'h=${1%/*} t=${1##*/}; echo mv "$1" "${h}/${t%%_*}".wav' doom {} \; remove the echo to actually rename the files. …
answered Dec 20 '16 by don_crissti
3
votes
You could try with: for z in ./*.zip do name="${z%%_*}"; dest=".${name//[ .-]/}"; mkdir "$dest"; unzip "$z" -d "$dest" done For each zip file it extracts the name part ( ${z%%_*} deletes suffix gre …
answered Nov 21 '15 by don_crissti
3
votes
You could use substring expansion: for file in ./*.mp3 do videoid=${file:${#file}-15:11} printf %s\\n $videoid done or, if more than one extension, use noext=${file%.*} videoid=${noext:${#noext}-1 …
answered Jan 18 '16 by don_crissti
1
vote
A shell-only alternative: process batches of COUNT files via "${@:START:COUNT}" (range of positional parameters) and shift COUNT while incrementing a counter c to name the archives: set -- * c=1 …
answered Apr 26 '16 by don_crissti
0
votes
" then your code could do something like this: for f in /path/to/files/* do if ! getfattr -n user.validation "$f" >/dev/null 2>&1 then echo "$f" setfattr -n user.validation -v … iterate over its elements: filez=( /path/to/files/* ) for f in "${filez[@]}" 1: for the sake of simplicity the script only checks if the attribute is set - it does not check its value. …
answered Oct 18 '17 by don_crissti
1
vote
array to remove the first dash and everything that follows. Any duplicate elements are removed via the (u) flag. To select hidden files too, use myfiles=(*-*(.D)) …
answered Apr 28 '17 by don_crissti
0
votes
You could use find and extract the parts before and after the dash from the file name, testing if the pair exist and if so removing the respective file: find . -name \*-\*.txt -execdir sh -c 'fn=${1# …
answered Mar 17 '17 by don_crissti
4
votes
On a gnu setup you could run: myarr=( $(find . -type f -name '[0-9][0-9][0-9]*' -printf '%f\n' | cut -c1-3 | sort -n) ) join -v1 <(seq -w ${myarr[-1]}) <(printf '%s\n' ${myarr[@]}) Alternatively, …
answered Apr 8 '17 by don_crissti
5
votes
'*/*/*' will extract in the current directory all files matching *.csv from depth level 2 in the ex1234.zip archive (excluding archive members from depth level 3 and below as '*/*/*' means paths that match at … '*/*/*'; done which should yield the same result. To dry-run and see which files will be extracted (their archive paths) without actually extracting them, replace -j with -qql: for zipfile in *.zip …
answered Aug 7 '15 by don_crissti
1
vote
names not present in the array: the . selects only regular files (add D if your list contains dotfiles) and the negated ^e_'expression'_ further selects only those for which the expression returns … false, i.e. if their name ($REPLY) is not an element of the array. If you're happy with the result replace print -rl with rm to actually remove the files: rm -- *(.^e_'(($mylist[(Ie)$REPLY]))'_) To …
answered Jan 25 '16 by don_crissti
6
votes
default selects the last line. This will not search recursively and will not process hidden files (aka dotfiles). If you want to edit those too see How to match * with hidden files inside a directory …
answered Jan 31 '17 by don_crissti
1
vote
Assuming you only know the names of directories but not the names of the files you could save the file names from one of the directories in an array and then iterate over the elements, removing the … directory name and pasting the resulting file name from each directory: files=(dir3/*) for p in "${files[@]}"; do f=${p#*/}; paste dir1/"$f" dir2/"$f" dir3/"$f" > "$f"; done Note that it could be …
answered Apr 14 '17 by don_crissti
1
vote
With zsh (using the glob qualifier D): print -rl ./**/.*(D) To include non-hidden files in hidden directories: setopt extendedglob print -rl ./**/*~^*/.*(D) …
answered Aug 25 '15 by don_crissti
5
votes
With a shell that supports extended globs and null globs e.g. zsh: for d in ./**/rules/ do set -- ${d}*.pdf(N) (( $# > 0 )) && printf %s\\n $@ done or bash: shopt -s …
answered Mar 16 '16 by don_crissti

15 30 50 per page