Tag Info

New answers tagged

1

With bash: for f in XYZ*/*; do mv -v "$f" "${f%/*}/${f:0:5}${f##*/}"; done The for loop runs trough all XYZ* directories. Then the mv command renames the files. Where: $f is the original filename ${f%/*} is the directory name ${f:0:5} is the prefix ${f##*/} is the original filename


0

You can run this command which just shows you what it would do: ls -d XYZ*/* | sed -n s'|\(XYZ[0-9][0-9]\)\([^/]*\)/\(\2_.*\)|mv & \1\2/\1\3|p' | cat and if you like the commands to run, replace cat by sh.


0

With zsh: autoload zmv # best in ~/.zshrc zmv '(XYZ??)(*)/(*)' '$1$2/$1$3'


1

du -ch /home/bzz/.cache* will give you the total size of all files which starts with .cache in /home/bzz/.


1

That's not correct. When you cat the files and send them to the pipe, it's no longer counting the files separately, it's just getting all its input from the pipe as a single file.


3

Use this instead: awk -F, '{print FNR}' file1 file2 The FNR variable in awk gives the number of records for each input file. But, when you use cat .. | awk awk reads for the stdin file descriptor, therefore awk sees only 1 "file". Try this to understand better (FILENAME contains the current file being processed): $ awk -F, '{print FILENAME" "FNR}' file1 ...


3

You concatenate (cat) them together, so for awk it is just one file (or standard input in this case). If you want to have desired result run instead awk -F, '{print FNR}' File1 File2


1

test -f won't work for multiple files expanded from wildcards. Instead you might well use a shell function with null-redirected ls. present() { ls "$@" >/dev/null 2>&1 } if [ $# -lt 1 ]; then echo "Please enter the path" exit fi path=$1 if ! present $path/cc*.csv && ! present $path/cc*.rpt && ! present ...


-1

It should work if you remove the outer square brackets in the second if condition


1

If I understand the question correctly, you want to rsync all the files in the range A0000000 through A0000095.  Well, then, don’t say A*; use a list of positive wildcards (a.k.a. globs or filename expansion patterns) that generate the file names you want, rather than identifying the ones you want to exclude.  Do it by decomposing the range into subranges: ...


0

Since the numbers are padded with zeros to the same width, the numerical order is identical to the lexicographic order. Therefore your problem is equivalent to removing the files starting with a given file in the lexical order. You can do this by building a string containing the file names separated by newlines, and using string substitution to remove the ...


4

On a GNU system, you can use this: sed -i '/^#[[:blank:]]Person/{n;s/#root:[[:blank:]]\+marc/root:\tsomeone@something.tld/;}' file It searches for a line beginning with # Person. Then switches to the next line and replaces #root:<blanks>marc with root:<tab> .... The -i flag edits the file inplace. -i, \+ and \t are GNU extensions. The ...


3

You could use pv: </mnt/nfs/image.img pv -L 5m >/dev/sda The -L flag limits the throughput to 5 megabytes per second. pv also writes to the stdout so you have to redirect to the target with >.


0

A modern cat implementation (sunos-4.0 1988) uses mmap() to map the whole file and then calls 1x write() for this space. Such an implementation will not loop as long as the virtual memory allows to map the whole file. For other implementations it depends on whether the file is larger than the I/O buffer.


2

Use this: c=132 for f in *; do mv -v "$f" "enum-$(printf '%0*d' 5 $c)" c=$(($c+1)) done The c=<your_starting_number>; I assumed 132 as in your question. Then the for loop runs trough all the files in the current directory. For every file the mv command is called. the printf utility prints the new filename with leading zeros. And finally the ...


0

As written in Bash pitfalls, you cannot read from a file and write to it in the same pipeline. Depending on what your pipeline does, the file may be clobbered (to 0 bytes, or possibly to a number of bytes equal to the size of your operating system's pipeline buffer), or it may grow until it fills the available disk space, or reaches your operating ...


1

With zsh (using the glob qualifier D): print -rl ./**/.*(D) To include non-hidden files in hidden directories: setopt extendedglob print -rl ./**/*~^*/.*(D)


0

With zsh: print -rl mydir/**/*.A(.e_'REPLY=$REPLY:r; [[ -f $REPLY.B ]]'_) :r removes the extension, so if the content of $REPLY was mydir/somedir/somefile.A after running REPLY=$REPLY:r its content becomes mydir/somedir/somefile; the rest is similar to this answer.


1

This should work: tune2fs -i180d <block device> The default unit is days, so 180 will be interpreted the same as 180d but explicit is better than implicit. For example: tune2fs -i180d /dev/sda3 Make sure you always use tune2fs when the filesystem is unmounted!


1

ctime, or status change time, refers to the time when the file metadata has changed. For example, $ ls -ltc under Linux will sort by and show the time of the last modification of file status information. To get a little deeper, ctime is the inode reported time since data blocks AND/OR the file metadata has changed. Changes in file metadata can refer here to ...


0

With zsh and glob qualifiers (estring): print -rl -- *(/e_'[[ ! -f $REPLY/README ]]'_) or print -rl -- *(/^e_'[[ -f $REPLY/README ]]'_) add D to include hidden directories: print -rl -- *(D/e_'[[ ! -f $REPLY/README ]]'_) / selects only directories and e_'[[ ! -f $REPLY/README ]]'_ further selects only the directory names for which the shell code ...


2

sox doesn't need to play the file in order to gather statistics on it. Use -n to suppress sound output. Use the stat effect to find info on max levels: $ sox mytest.mp3 -n stat ... Maximum amplitude: 0.228743 Minimum amplitude: -0.235424 ... Volume adjustment: 4.248 The above example file can have its volume increased by 4.2 to be normalised ...


1

What you can do is try to copy the .txt file to the documents directory. Then you can go ahead and delete the sub-directory. That would be 100X easier.


2

Another way with im using the fx operator: find . -type f -name \*.gif -exec sh -c \ 'identify -format "%[fx:n>1]\n" "$0" | grep -q 1' {} \; -print This searches the current directory and its subdirectories for .gif images running that shell command for each .gif found. If number of frames n>1 then fx prints 1, otherwise it prints 0. This is piped ...


8

Using exiftool: exiftool -q -if '$framecount > 1' -p '$directory/$filename' -r -ext:gif . Would report the paths of the GIF files that have more than one frame (in the current directory, recursively).


21

This can easily be done using ImageMagick identify -format '%n %i\n' -- *.gif 12 animated.gif 1 non_animated.gif identify -format %n prints the number of frames in the gif; for animated gifs, this number is bigger than 1. (ImageMagick is probably readily available in your distro's repositories for an easy install)


12

In bash (version 3.0 (2004) and above), ksh (since ksh93r (2006)) and zsh (version 5.0.6 (2014) and above): touch {a..z} (note that only zsh supports characters other than ASCII letters and digits, none goes as far as perl's .. operator which inspired those shells operators). With other zsh version (since 2.2 (1992)): setopt braceccl touch {a-z}


0

Based on Glenn's input, I have: #!/bin/bash if [ ! -d "$2" ]; then mkdir -p $2 fi find $1/ -type f -print0 | while IFS= read -rd "" filename; do v=$((RANDOM % 4)) if (( v == 0 )); then cp "$filename" $2/`uuidgen`.jpg fi done I added uuidgen because $RANDOM didn't supply a large enough number space to eliminate collision. ...


0

grep should suffice your solution grep -o "`grep -of file1 file2`" file3 the inner grep "grep -f file1 file2" will grep the pattern present in file1 and file2 and the pattern returned is searched in file3.


2

grep -of file1 file2|xargs -I {} grep -o "{}" file3 This starts by taking the input of file1 and feeding it in line by line into file2, returning the exact matched text if any. Then the results if any are fed into file3 line by line again returning only matched text.


1

You could use join 2 times on a row: join -1 1 -2 2 -o 1.1 <(join -1 1 -2 2 <(sort file1) <(sort -k2 file2)) <(sort -k2 file3) Prints only: 465 First look at the inner join. It joins file1 and file2 by using the field 1 in file1 and the field 2 in file2. Then all of this is joined again with file3. Notice, the files must be sorted on the ...


0

The following worked for me. Sorry if it was posted previously, but I did not see it in a quick scan. ls path/to/dir/containing/files/* | head -100 | xargs -I{} cp {} /Path/to/new/dir


1

--hide=PATTERN in the fine manual looks promising, e.g. set a shell alias for ls that includes appropriate things to hide.


1

You have to do that in two steps: mv /Users/admin/Documents/Folder1/file1.txt /Users/admin/Documents/file1.txt rm -R /Users/admin/Documents/Folder1 With bash you can do the following shorter version: mv /Users/admin/Documents/{Folder1/,}file1.txt rm -R /Users/admin/Documents/Folder1


-2

Originally I had suggested this: cd /Users/admin/Documents/Folder1 mv $(ls -A) .. # the -A will find hidden items, but not return "." or ".." cd .. rmdir Folder1 But from the comments, I see that is not safe.


3

Regarding user names, the kernel don't need (and don't care about) them, since it is dealing only with numerical user ids (the uid 0, a.k.a. root, may have special status). See credentials(7) & capabilities(7) Conversion from user names to user ids is done by libc functions like getpwnam(3). The libc may access files (notably /etc/passwd) for that, see ...


3

In general, a Linux kernel doesn't open files on its own behalf (rather than on behalf of processes). Even /sbin/init (or the 'init' program specified on the kernel command line) is exec()ed by a process (process 1 is constructed directly from an image inside the kernel, IIRC). At one time, kernel modules requiring firmware would directly open the firmware ...


3

There is no file locking mechanism in place to protect file renaming or deletion because there is no need for it. Renaming or even deleting a file while it is open by another process, even if it actively writes and/or reads data, is harmless. The processes having the file open would see no difference and will access the original data of the renamed file ...


2

If file foo has a sibling foo~ the file with a tilde is likely a by-product, backup, or intermediate file for either your compiler or editor. They're usually cleaned up automatically, ignored by your version control, and hidden in guis. Thinks of it as one of those things that most people aren't familiar with and you probably don't want to deal with, ...


5

This is not about "compiling" a program, or even related to coding. This is your text editor creating a backup file. Your text editor (I assume gedit in this case, but correct me if I am wrong) seems to be configured to create a backup file by default. You should observe this behavior with any text file you edit. Check this answer for a solution.


0

Assuming you: wanted "1 + Ordinal date" at Position 2. "_"-padded station names. lowercasing of the channel name Then this should perform the wanted transform. $ ls 2007-07-22-2300-11S.NAN___024_ABI___HH_E_SAC $ for i in *; do od="$(expr $(date +%j -d "${i:0:10}") + 1 )"; chn="${i:39:1}"; sta="$(echo ${i:30:6} | tr -d '_')"; mv "$i" ...


-1

ls ?.* should give you desired results.


1

For mass renaming, prename is your friend. In this case: prename 's/^(\d*)-(\d*-\d*)-(\d*)-.*___\d*_(\w*)___\w*_(\w*)_\w*/$1.$2.$3.$4.$5/' * (ignoring the Julian date until the respective questions have been clarified).


0

Knowing the checksum of a part doesn't help calculate the checksum of the whole, so you'll have to calculate the checksum of all possible permutations until you find the right one. If you have n parts, there are n! (factorial of n) permutations, and if they're all equally likely you'll have to process n!/2 on average until you find the right one. When you ...


1

perl -MAlgorithm::Combinatorics=permutations \ -le '$i=permutations(\@ARGV); while ($p=$i->next) { $n++; print "combo$n @$p" }' frag1 frag2 frag3 frag4 \ | while read out a b c d; do cat $a $b $c $d > $out; md5 $out; done Or md5sum instead of md5 if you have the GNU tools.


0

How many fragments are there? It sounds like you would have to try every permutation of the fragments (or until you hit the right one), therefore even solving the problem for a relatively small amount of fragments will result in a large amount of work.


10

Use this with bash: find $1 -name "* *.xml" -type f -print0 | \ while read -d $'\0' f; do mv -v "$f" "${f// /_}"; done find will search for files with a space in the name. The filenames will be printed with a nullbyte (-print0) as delimiter to also cope with special filenames. Then the read builtin reads the filenames delimited by the nullbyte and ...


8

Using rename find . -type f -name "* *.xml" -exec rename "s/\s/_/g" {} \; or with $1 find "$1" -type f -name "* *.xml" -exec rename "s/\s/_/g" {} \; Using mv find . -type f -name "* *.xml" -exec bash -c 'mv "$0" "${0// /_}"' {} \; or with $1 find "$1" -type f -name "* *.xml" -exec bash -c 'mv "$0" "${0// /_}"' {} \;


1

mediainfo command also gives you lots of information: $ mediainfo IMGP3793.AVI General Complete name : IMGP3793.AVI Format : AVI Format/Info : Audio Video Interleave File size : 121 MiB Duration : 2mn 16s ...


2

RAND_FILE=$( find pics/ -type f -print0 | shuf -n 1 -z ) # TODO check that RAND_FILE actually got a file, e.g. what # if pics/ dir is empty, what happens? cp "$RAND_FILE" ... Though hard linking the copy would save space if it's on the same filesystem and the duplicate file will not be modified.



Top 50 recent answers are included