New answers tagged files
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 ...
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 ...
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 ...
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/
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 -...
-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, ...
-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 ...
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 ...
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 }'
...
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.)
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 "...
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'
...
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 ...
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&...
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 ...
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 ...
Top 50 recent answers are included
Related Tags
files × 4943linux × 810
bash × 531
shell-script × 492
permissions × 451
filesystems × 381
shell × 374
find × 345
directory × 292
command-line × 271
rename × 234
text-processing × 218
scripting × 172
timestamps × 161
ls × 150
awk × 148
rm × 147
grep × 129
filenames × 124
sed × 115
mv × 109
ubuntu × 103
wildcards × 98
file-copy × 91
date × 86