New answers tagged

2

Don't write shell loops just to manipulate text, see why-is-using-a-shell-loop-to-process-text-considered-bad-practice, and when you want to use literal strings use a tool like awk that understands literal strings, not a tool like sed that doesn't. You didn't provide any .ts.meta files for us to test against so obviously this is untested but something like ...


2

tail -f prints the last 10 lines of the file. Once it reaches the end of the file, it waits and prints everything that gets appended later. That's the principle of following a file's growth. If you want to always “print the last 10 lines of the file”, that's not well-defined, since it depends on when it checks. If there's a program that prints one line at a ...


1

One way to do that is to bypass the regex route and use the read r command of sed. cat 1TBMovie2_dotTSdotMeta.txt | while IFS=, read file moviename; do printf '%s\n' "$moviename" | sed -i -e '2r /dev/stdin' -e '2d' "$file"; done It should be written soread out on multiple lines as shown below: cat 1TBMovie2_dotTSdotMeta.txt | while IFS=,...


1

If you have commands you use often, write them as functions, and store them in the shell's startup files, e.g. .bashrc. That one could be defined like this (though you'd need a better name): f() { chmod "$1" "/home/$2/.bashrc" } and called as f 740 bobsa That doesn't work too well if you need to edit the command often on the command ...


1

You can use the bash command with -c flag as follows: bash -c 'chmod "$1" /home/"$2"/.bashrc' bash 740 bobsa Remember to use single quotes for the bash command.


3

tar can create or extract tar's but it can't operate on streams in this way. You'll need something like tar-stream - it even has an example that does what you are asking: https://github.com/mafintosh/tar-stream#modifying-existing-tarballs


1

This is relevant for FreeBSD, since htpasswd isn't available without installing apache. Building on @meuh's answer, here's how to use Python3 in FreeBSD to get a bcrypt hash of a password - for example, for basic auth in a traefik jail. Note the following assumes a jail. Be careful with pip if this is the base OS. Adjust for version of Python3 depending on ...


0

A value of 377 (or is that 0377) for the user mask is unusual to say the least, it resets all the access flags and only leaves read access to the file owner (if even resets the execute flags, making directories unusable even by their owner). The usual umask values are 0002: full r/w access to user and group, R/O access for others 0022: full r/w access to ...


1

The concept of setting a network mask without an IP is a strange one. The ifconfig utility appears to have been written to assume there will be only one IP address. Interfaces can have many IP addresses and the network mask is always associated with an IP address. Your question doesn't indicate whether or not the interface already has an ip address. But ...


0

First make sure you have the device you want with: ip a show From there you can just set an ip and mask: sudo ip a add 192.168.0.1/255.255.240.0 dev eth0


0

ip addr add 192.168.0.1/20 dev eth0 Still requires you to specify the host IP address, so there's no direct alternative.


1

awk '{ count[$1]++ } END { for (field in count) print field, count[field] }' file.txt That is, use the first field as the key in the associative array count. For each record, increment the value corresponding to the field. At the end, loop through the keys of count and print them and the associated values.


4

Portably, you can use shell parameter expansion: $ pDate=2020-06-22 $ year=${pDate%%-*} $ yearmonth=${pDate%-*} $ month=${yearmonth#*-} $ echo $year 2020 $ echo $month 06 With ksh, you can read from a herestring: $ IFS="-" read year month day <<<"$pDate" $ echo "$year .. $month .. $day" 2020 .. 06 .. 22


2

Since sha1sum hashes are 40 characters long, you could pipe the output into a head command and pull the first 40 characters from it: echo test | sha1sum | head -c 40 Source: https://stackoverflow.com/a/14992739/4642023


1

You can try something like $ xargs -a list.txt -I myfilename find . -name myfilename -exec sed 1,7d '{}' \; xargs reads the name of the files in list.txt and replaces the myfilename pattern with the name of the file read in the find command find will find your file and pass it to sed wich delete the first 7 lines (or empty the file if there is less than 7 ...


0

Since everyone else has already provided the answer to finding ifconfig or available alternatives, I will provide some generic tips on how to get out of this situation because this is not the first or last time one would need to get hold of a command/package/utility on their system (basically I am teaching a person how to fish :). The instructions are for ...


8

For anything involving forensics, including undeleting files, dd is the RIGHT tool (at least for the read). The problem, as others have pointed out, is that at the end of a ssh pipe, you aren't reading it blocked. So you either need iflag=fullblock on the second dd, or to just skip the second dd altogether. flag=noerror is probably wrong. You want to ...


Top 50 recent answers are included