New answers tagged

0

less does not provide fine-tuning on the features which it displays, preferring to use video attributes such as bold and reverse (or standout): the ~ character is printed with bold attribute, and only if the "twiddle" option is set ("Show tildes after end of file"). while you could modify the terminal capabilities used to draw bold text, the "END" is ...


0

To map from the host argument given on the command line to the ssh_config hostname entry is easy using ssh itself. You can ask it to evaluate and print out what it would use for the configuration for a command line, without actually connecting. Then you simply need to pull out what it lists for hostname (Note that it canonicalizes configuration key names by ...


2

For the cases where it "works", you are leaving a process running cat which is reading its standard input, which has not been closed. Since that is not (yet) closed, cat continues to run, leaving its standard output open, which is used by the shell (also not closed).


0

To read data from the file that an executable is stored in: #!/bin/bash old_dir="$(pwd)" cd "$(dirname "$0")" this_dir="$(pwd)" cd "${old_dir}" unset old_dir # read from where executable is stored echo "${this_dir}/data" # read for present working directory echo "$(pwd)"


1

You have to add /var/lib/app/ directory to your PATH, not /var/lib/app/startapp.sh. To do this permanently, first take a look at your PATH environment variable by entering this command: echo $PATH The output you will get, will be something like: /usr/local/bin:/bin:/usr/bin/:usr/local/sbin:/usr/sbin/ ... You shouldn't alter the order, so while exporting ...


0

Following on from Peter.O's comment which is what I wanted to align (tab delimited data, TSV), this phrase works very nicely: column -t -s $'\t' /Users/me/data.csv | less --chop-long-lines


1

Here you are: ifconfig -a | grep -e "inet [0-9]" | cut -d" " -f 2 Most of the given answers won't work well on Mac OS X! The easiest thing you can do, is using cut or awk.


1

Open an SSH connection once, and then piggyback on it. This feature of OpenSSH is called master connections. See Using an already established SSH channel ssh_control_socket="$(mktemp)" ssh -o ControlPath="$(ssh_control_socket)" -o ControlMaster=yes -o ControlPersist=yes administrator@host "mkdir ${DIR}" # other commands using ssh (ssh, scp, rsync, …): pass ...


1

Use ping to measure round-trip latency to servers over ICMP/IP. You can also traceroute or tracepath to your server, and check how much round-trip latency there is to the first few hops. You're mainly trying to check for symptoms of bufferbloat, so be aware that only happens when the link is fully used! ("latency under load" measure). You can check ...


-2

Try #!/bin/bash oldversion=12345 newversion=67890 ls -l /home/user/ mv /home/user/MyDir_$oldversion /home/user/MyDir_$newversion ls -l /home/user/


1

Character 16 in the sed script does not exist. This is the " character that sed is complaining about, and that means that your editor or input method replaced it with some non-ASCII rendition of ". My guess would be either “ or ” or ¨. Use file on your file in order to get some guess on the encoding. It should be "ASCII". Anything else hints to the file ...


2

What you are suggesting is nigh impossible to do properly with standard tools. As you noticed, saving the command history is usual will not work, since the file will be owned by the user, and they can can delete, clear or edit the file at will. Even if we could work around this, perhaps by making the command history file a pipe read by some trusted process, ...


0

It's difficult to give a good answer without knowing more about your setup, but it sounds like a way to achieve some of your goals, assuming you use a file system that supports it, such as ext3, would be to mark the log file "append-only", using chattr +a <file>. Setting or unsetting the attribute requires special privileges, and then the file can ...


2

A short answer is no. There is no "undo command" on GNU/Linux terminals. Although lots of commands have an inverse operation, like rename, compress, decompress, etc.


1

You don't need to do it as a HERE document (which is what the << stuff does). You can simply do ssh remotehost "command1; command2 ; command3" e.g. % ssh localhost "date ; uptime ; echo hello" sweh@localhost's password: Tue Jul 19 08:07:48 EDT 2016 08:07:48 up 15 days, 31 min, 3 users, load average: 0.33, 0.33, 0.40 hello The scp however, won'...


2

With GNU find: find . -daystart -type f -mtime -2 -mtime +-1 -ls Would give you the files last modified between yesterday 00:00:00 and today 23:59:59.999999999. It could give you wrong results around the switch from/to summer time (in timezones that have winter/summer time) as it counts the number of 24 hours unit from the start of today and around the ...


1

You seem to have a directory whose name consists entirely of non-printable and whitespace characters. You can use a wildcard to match it: mv -i [^A-Za-z0-9_]* renamed This prompts you to move all files whose name don't begin with a letter, a digit or an underscore. There's probably only that one file. Alternatively, if your shell is set up to iterate ...


0

As I commented, I don't think there is an easy way to do this transparently for any command. You could create a wrapper script and call it, say, f, so you can do f() { local command=$1; shift local files=() arg file for arg in "$@"; do file=$(some method to look up the current file in $CDPATH) files+=("$file") done "$...


1

You have managed to create a directory with a space (or several) as its name. Rename it: mv " "* I_see_you In the case that it's not a simple space, you could try replacing any non graphical characters with X: $ # (having moved everything else away to a safe place...) $ for d in *; do test -d "$d" && echo mv "$d" "$( tr -c '[:graph:]' 'X' <&...


0

would instead look something like this: If one wanted to break down what you want is : 1) the stdout stream would not end each line with a CRLF but instead with a '|' character. This would not align the two streams together of course, and alignment is out of the question because it would have to predict the length of future lines added in the stdout, which ...


-1

alias cd='builtin cd $1 && ls -l && builtin cd $1'


3

You can use shell globbing for this: cp -rp *bat*/ /destination/ Here *bat*/ will expand to directories having bat in their names. Or using find, which will work even if there are so many files that you get an error because the command line is too long: find . -maxdepth 1 -type d -name '*bat*' -exec cp -rpt /destination {} +


3

You can use moreutils sponge: ls | sponge list Or with zsh: cp =(ls) list With GNU ls: ls -I list > list (though if there had been a file called list before, that means it won't be listed). Since ls output is sorted anyway, you can also use (assuming your filenames don't contain newline characters): ls | sort -o list Or to avoid the double ...


2

Partial/most credit goes to @StephenHarris... echo "`ls`" > list equivalent to echo "$(ls)" > list


9

As you've noticed, the file is created before ls is run. This is due to how the shell handles its order of operations. In order to do ls > file the shell needs to create file and then set stdout to point to that and the finally run the ls program. So you have some options. Create the file in another directory (eg /tmp) and then mv it to the final ...


8

The output file is created by the shell before ls begins. You can get around this by using tee: ls | tee list To thoroughly defeat any race condition, there is always ls | grep -vx 'list' > list Or if you like that tee displays the results as well: ls | grep -vx 'list' | tee list However, as pointed out in comments, things like this often break ...


3

You can make the filename temporarily hidden: ls >.list && mv .list list


1

This is filthy, but simple : $ awk '{print $8}' < request_log | sort -u | wc -l To do the last 5 minutes bit, try: $ grep -A 9999999 'five minutes ago string' awk '{print $8}' < request_log | sort -u | wc -l obviously $8 is the position of the client ip in each line of your log. There are lots of log analyzers, many of which are free. Don't pay for ...


0

The form $ ./script.sh "$@" is the most convenient for argv. The arg delimiter is whitespace, but can be changed. Don't remember how off-hand. Then use $1, $2, shift, if [ $# -ne 3 ] to control flow. I don't usually embrace getopts if a case ... esac will suffice.


1

Most web statistics tools summarise the log over a period of 24 hours or a month. The simplest cli ncurses-based one is goaccess. For an instant view of your apache server current cpu usage and threads there is server-status which you could retrieve via curl, in html. See a live demo (beware large file). Nginx has a similar feature. You might also look ...


0

If you have awk, you can use the parentheses as field separators: awk -F '[()]' '{ for (i=1; i<=NF; i+=2) { if ($i) { gsub(/; */,"\n",$i) printf "%s", $i if ($(i+1)) printf "(%s)", $(i+1) } } print "" }' <<END ProductName: Threat Emulation; product_family: Threat; Destination: (...


2

The problem occurs because some programs do not cleanup properly when they are interrupted. The usual fix would be to use reset (you'll get less satisfactory results using stty sane): resetcontrolJ sends a newline even when your settings are messed up. Further reading: tset, reset - terminal initialization


4

A little bit confusing regex for sed but workable sed ' :a #mark return point s/\(\(^\|)\)[^(]\+\);\s*\([^)]\+\((\|$\)\)/\1\n\3/ #remove ; between ) and ( ta #repeat if substitute success s/[[:blank:];]\+$// #remove ;...


0

I'm not sure what is the best solution, but I would use file *


2

This is what you are looking for cp -TRv A A.bak When you use the option -T it overwrites the contents, treating the destination like a normal file and not directory. from man cp : -T, --no-target-directory treat DEST as a normal file -v, --verbose explain what is being done Alternatively, you copy the directory's contents and not the ...


1

Use ip addr show with -o flag. For instance, here's all IPv4 addresses of my connected interfaces $ ip -4 -o addr show | awk '{print $4}' 127.0.0.1/8 10.42.0.1/24 192.168.0.78/24 10.0.3.1/24 Getting only specific addresses that start with 10. like you have can be done this ...


1

To get all inet IP: ifconfig -a | grep -oP 'inet \K\S+' In order to get just 10.16 family: ifconfig -a | grep -oP 'inet \K10\.16\S+'


6

Try: awk '{f=1} $4 ~ /^192.168/{f=0} $4 ~ /192.168.(125.100|126.100|155.240)/{f=1} f' file Example Consider this test file: $ cat file Jul 13 21:47:41 192.168.100.254 "user from 192.168.100.101" Jul 13 21:47:41 192.168.125.100 "user from 192.168.100.101" Jul 13 21:47:41 192.168.126.100 "user from 192.168.100.101" Jul 13 21:47:41 192.168.155.240 "user ...


0

I fixed the probleme by mounting the hard disk pointed by the symbolic link. In fact, media/ is the path set by default so you need to mount the disk to set a valid path. Here is a link were you can find how to automatically mount a hard disk : InstallingANewHardDrive


0

String multiplication trick based on this answer: http://stackoverflow.com/a/5349772/4082052 Use substitution to insert programmable number of dashes paste $(for i in {1..400}; do echo -n '- '; done) or paste $(printf -- "- %.s" {1..400}) To know why printf -- was used: Dashes in printf


0

For a file with 4 rows: paste $(for((i=1;i<4;i++)); do echo -n "- "; done; echo -n "-") < file


1

Always check the man pages for help first. It'll save you a lot of time. Or if you're really busy, an ln --help at the shell gives Usage: ln [OPTION]... [-T] TARGET LINK_NAME (1st form) .... Further down the help text, we find ... -s, --symbolic make symbolic links instead of hard links -f, --force remove existing destination files ... which in ...


0

you can use -f option, it removes existing destination files, if any, before creating the link. ln -sf a.txt b.txt found in man ln : [OPTION] -f, --force remove existing destination files


1

You need to remove file b.txt previously with command rm b.txt, then create symbolic link with your command ln -s a.txt b.txt. You could use hard link from b.txt to a.txt, then execute ln a.txt b.txt, both a.txt and b.txt would point the same file on hard drive and removing a.txt doesn't remove file, which could be read through b.txt. With symbolic link ...


3

for i in {b,c,d}; do cp /path/to/directory/a.txt /path/to/file/$i.txt; done


2

The most common used idiom in Unix to separate the command line flags from the rest of the arguments is to use a double dash (--). If the utility uses the C library function getopt() (either directly or indirectly), the double dash will signal the end of the command line options, and getopt() will end its parsing of the command line. This is from the ...


1

Consider something like: mycommand --foo=bar arg1 arg2 Requiring =<someval> when assigning a value to the flag would remove ambiguities. It is clear this is a different case where the value is not specified: mycommand --foo arg1 arg2


0

There's no general answer to this. It depends entirely on how mycommand interprets its arguments.


1

FreeBSD (the OS) does not have a mailx program. There are however several programs called mailx which is derived from Berkeley Mail. Some are ported to FreeBSD and are available as packages. The OP is using the package: mailx-0.5_1 This package is a fairly old Perl script. I would rather recommend using the Heirloom version of mailx: heirloom-mailx-12.4_7 ...


1

(Posting @glennjackman comment as a community answer to prevent system from autodeleting the question) jq '.body.test2 = ["hi"]' will do it



Top 50 recent answers are included