New answers tagged

0 votes
Accepted

Can't interact with a file with an apostraphe directly in bash

If quoting the filename I'm here.mp3 doesn't work in any way, then probably the filename is actually not what it looks. Maybe the space between I'm and Here is not a space, or there is an additional ...
raj's user avatar
  • 1,014
0 votes

Changing file names based on enclosing directory

It's not clear from the question how the files should be renamed, so I'm going to assume that they should be renamed by appending the name of their original directory to their original name. The code ...
Kusalananda's user avatar
  • 323k
0 votes

Any operations with file system takes forever

After reloading my computer four times, all started to work fine. There are some actions I do before: Install dbus-launch Updated all Fixed warning while I tried sudo dpkg configure -a Reinstall ...
Minuta18's user avatar
0 votes

curl prints its pid then runs in background

Just replace & with %2, encode the url This will work - curl 'http://example.com/endpoint/?arg1=val1%2arg2=val2' It's best always use curl with encoded url - https://www.urlencoder.org/
Amit Ahuja's user avatar
0 votes

Preserve image's modification time with mogrify/imagemagick

I'm not sure about ImageMagick, but GraphicsMagick supports this natively. $ ls -lh family_photo.jpg -rw-r--r-- 1 justin justin 901K Sep 9 2007 family_photo.jpg $ gm mogrify -preserve-timestamp -...
maelaglhum's user avatar
-2 votes

Use bash to overwrite old file with a new file named according to current date

You can do like this: # Save the list of files in the backup folder files=$(ls /backups/backup_[0-9][0-9][0-9][0-9]_[0-9][0-9]_[0-9][0-9]_[0-9][0-9]_[0-9][0-9]_[0-9][0-9].txt) # [Do your backup here, ...
setenforce 1's user avatar
-1 votes

Use bash to overwrite old file with a new file named according to current date

If you only want a single backup file then its easy - pseudo code looks like this: Capture list of existing backup files create new backup file if new filecreated OK, delete files in list If create ...
symcbean's user avatar
  • 5,110
0 votes
Accepted

Use bash to overwrite old file with a new file named according to current date

The following bash script fragment would use the list of positional parameters (see further down for a variant that uses a named array instead) to store all the pathnames of old backups. When the new ...
Kusalananda's user avatar
  • 323k
1 vote
Accepted

How to get the size of a folder as reported by Windows Explorer on Linux?

Essentially, you only want to count the lengths of the contents of “real” files inside the directory; with GNU find: find /path/to/directory -type f -printf '%s\n' | awk '{ s += $1 } END { print s }' ...
Stephen Kitt's user avatar
1 vote
Accepted

Using find in order to detect a magento module

You need -path instead: find ./vendor -path '*/adminhtml/routes.xml' -exec grep "sales" {} + (Possibly with -type f, it's not likely there will be a directory named routes.xml.)
muru's user avatar
  • 70.2k
0 votes

Using find in order to detect a magento module

An approach of mine is to filter all files matching the routes.xml name and contain the required wotd then filter further the result of find with grep: find ./vendor -name routes.xml -exec grep "...
Dimitrios Desyllas's user avatar
1 vote

Counting characters between grep searches

Input file cat file GAATTCXXXGAATTC With shell (GNU grep): grep -oP 'GAATTC\K.*(?=GAATTC)' file | tr -d $'\n' | wc -c 3 The regular expression matches as follows: Node Explanation GAATTC 'GAATTC' ...
Gilles Quénot's user avatar
0 votes

Where does KVM hypervisor store VM files?

To get the information from the command line (as root): Determine the domain name you want to check: # virsh list --all Id Name State ------------------------------ - lab_master1 ...
tvs's user avatar
  • 296
1 vote

Shell script: How can I write multiline content to file if the file doesn't exist?

There's nothing stopping you passing newline characters to echo. Inside single or double quotes, in Bourne-like shells, newline is not any more special than any other characters¹ if [ ! -e "$file&...
Stéphane Chazelas's user avatar
1 vote
Accepted

How to copy a directory structure and rename a subdirectory in the destination

This might be a solution. #!/bin/bash # This is file 'script'. set -e # (optional) # immediately exit on some errors, like # mkdir <existing directory> ROOT=. # or ...
minorChaos's user avatar
1 vote
Accepted

How to preserve file creation date when overwriting files?

Birth time can’t be set arbitrarily, other than by setting the “context” time (system time typically). This means that it isn’t possible to copy a file to another and have the copy preserve the ...
Stephen Kitt's user avatar

Top 50 recent answers are included