New answers tagged

0

tree offers no filtering outside of file names, however it offers to display the owner and permissions of the files it displays with its -u and -p flags. I would therefore enable these flags and pipe the result to a tool that will implement the filters : tree -P *.so -up /usr | grep -v "root\s*]" | grep "\[.rwxrwxrwx"


0

ctime ctime is the inode or file change time. The ctime gets updated when the file attributes are changed, like changing the owner, changing the permission or moving the file to an other filesystem but will also be updated when you modify a file. mtime mtime is the file modify time. The mtime gets updated when you modify a file. Whenever you update ...


1

I've tried a bunch of tools, including iftop, ntop, iptraf, and of course the very useful built-in netstat -tupln, but the most practical for my use case turned out to be nethogs - it aggregates connections by the originating app, and is the least noisy of all. Installable via: sudo apt-get install nethogs Run as root: sudo nethogs


0

This will (pretend to) delete any differences between the folders: diff -awr folderA folderB | sed 's/Only in //;s/: /\//' | while read f; do echo "removing ${f}"; done; If you want to remove differences in A but not B, you can add in a grep like so: diff -awr folderA folderB | sed 's/Only in //;s/: /\//' | grep "^folderA/" | while read f; do echo "...


0

You can refer this link this link. rsync is having the feature of deleting the folder which doesn't exits on the live ENV. rsync -av --delete


2

If your goal is to monitor the system, you want pam_tty_audit. As the name implies, pam_tty_audit is a pam module which when configured properly, is invoked any time a user opens a session (and gets a TTY). The module records all input & output, and sends everything it records to the auditd daemon. You can then execute queries against the auditd daemon ...


2

If you really want to, you could make a program (or shell script) which calls script writing to a timestamped "typescript" file (and in turn calling your real shell) and make that program your default shell in /etc/passwd. There are a few pitfalls: you may have to add this program to /etc/shells doing this sets the SHELL environment variable, which is ...


3

You can't, as it has been already said, if the files have been compressed with standard gzip. If you have control over the compression, you can use dictzip to compress the files, it compresses the files in separate blocks and you can decompress just the last block (typically 64KB). And it is backward compatible with gzip, meaning the dictzipped file is ...


2

I'm not sure why your dhcpcd isn't using syslog, as that's the default behavior of the utility (maybe Void Linux is using a special version). Anyway the output is going to the console because that's where the init manager sends its output, and unless redirected, applications started by the init manager inherit STDOUT & STDERR. Meaning the fix is to ...


1

You have two options: Modify the Python script, or write a shell script wrapper. To modify the Python script: You should loop around what it is you want to be doing. Install a signal handler to catch the INT signal (sent by Ctrl-C) and TERM signal (sent by plain kill). When the signal is caught, set a variable telling the Python script that it should no ...


1

You can create a cron job to run your command on regular basis. For example if you want to execute the job on every hour you should create the following cron job: 0 * * * * /path/to/your/command >/dev/null 2>&1 If you want to stop the execution of the job type ps aufx|grep yourcommand|grep -v and kill the pid of it.


1

You can try using a watch 'loop' to run the program repeatedly and see the result, or a while loop. Obtain the PID of that process with echo $! and use kill to terminate that PID. For example : while :; do ./test.py; done & echo $! > /tmp/testpy.pid Use kill to terminate program when you want : kill -9 `cat /tmp/testpy.pid`


-1

You can press CTRL + c or send the SIGTERM signal with kill or killall.


0

The space is actually irrelevant. The shell parses the command in exactly the same way. The difference is whether Firefox is already running or not. It appears that the -private option only works when starting Firefox. If Firefox is already running, firefox -private opens a non-private window in the existing Firefox instance.


1

These look very much like section names from the Linux kernel. The ones prefixed by .rela contain relocation information for the named section, e.g. .rela.text is the relocation information for the text section (where kernel object code is stored). Other sections of interest are: .modinfo - kernel module information .rela.__ksymtab - kernel symbol table ...


2

+1 to what @jos said above ("google it"). In this particular case you should remove the ".rela_" and "_gpl" parts. You'll find that these are kernel symbols. "rela" is an acronym for "relocation" and has to do with the ELF file format. These are all interesting topics and I encourage you to look into them further.


0

Here is my regex attempt. Replacement happens in-place so make a copy of your document before you start. This variation works when the colour array is present: $ perl -pi -e 's/(\/Type.*\/Annot.*\/Subtype.*\/Highlight.*\/C\s*\[)[^]]*]/${1}0.5 0.5 0.5]/' document.pdf This one is for when the colour array is not specified (which defaults to black): $ perl ...


2

You can do that with bash itself, using command substitution and then parameter expansion. First take the output of the command in a variable by using command substitution $(), and then use parameter expansion to replace all newlines with spaces ${variable//$'\n'/ }: $ myVariable=$(grep "type" /root/myFile | cut-d'=' -f2) $ myVariable=${myVariable//$'\n'/ ...


1

myVariable=`grep "type" /root/myFile | cut-d'=' -f2` What is between back-ticks (`) is run and the output is assigned to myVariable. If your current output is separated by line feeds (\n), then you may want to replace them with spaces with tr such as: myVariable=`grep "type" /root/myFile | cut-d'=' -f2`|tr '\n' ' '` Note: Some people prefer using the $...


1

You can override the builtin compgen for simple directory completions (as for cd and ls). For example, put this function in your ~/.bashrc compgen(){ local IFS=$'\n' local x tmp x=$( builtin compgen "$@" ) && while read -r tmp; do [[ "$tmp" =~ ^/home/e && ! "$tmp" =~ ^/home/elsherbini$ ]] || echo "$tmp" ...


1

For the general question in your title, head -1 or sed -n 1p -- or sed 1q -- are ways to select the first line of anything. But your case is to select the first substitution result by sed. You can get that from sed itself with a slight modification, and it can also do the equivalent of your grep and your useless cat, plus you only need one of your capture ...


5

Yes, you can. Using grep with PCRE(-P): ip addr | grep -Po '^\d+:\s+\K[^:]+' ^\d+:\s+ matched the portion before interface name at the start, \K discards the match [^:]+ gets the portion upto the next : i.e. the interface name Similar logic using sed: ip addr | sed -nE 's/^[[:digit:]]+:[[:blank:]]+([^:]+).*/\1/p' On my system: % ip addr | grep -Po ...


1

That's a lot of commands doing the same things only one command could do. I don't know how "listener.ora" is formatted, but the below line should work fine, at most with some minor tweaking. sed -rn '/PORT/ s/.*([0-9]{4}).*/\1/p' /ora$sid/dbs/listener.ora -r for regex -n for suppressing automatic printing /PORT/ to find line containing PORT s/ for replace ...


0

grep -m1 PORT /ora$sid/dbs/listener.ora | sed 's/.*PORT.*\([0-9]\{4\}\)\(.*\)/\1/' or Change the if($count > NUM) to restrict the number of returned matches, here it is 3 matches. perl -e 'my $count = 0; while(<>) { if(/PORT (\d+)/) {print "$1\n"; $count+=1; if($count > 2) {exit}} }' /ora$sid/dbs/listener.ora


1

I'm using zsh which allows completion to be customized very thoroughly. This option prevents certain patterns from completion: autoload -Uz compinit; compinit # ignore some common patterns that we usually don't want as completions zstyle ':completion:*' ignored-patterns "/usr/share/iscan" "/usr/lib/iscan" \ "iscan" "/usr/lib/ispell" "ispell" "/usr/...


1

One way I'd suggest is to have an alias if we are just concerned about the home directory path, adding the below to your profile would help here, whatever unique alias you made should autocomplete with even a first character. alias myHome="cd /home/elsherbini" . .profile my\T pwd /home/elsherbini EDIT: The other way could be binding a key but even this ...


5

Never known about the command intel_gpu_time interesting, thank you. This command is part of the package intel-gpu-tools (apt-get install intel-gpu-tools) under Ubuntu and by the look of it the package under RedHat (CentOS) is called exactly the same. So, give yum install intel-gpu-tools a try.


1

If you want the first returned value you can use |head -1 to get it. You can then use the $() structure to return it as a value eg port=$(cat /ora$sid/dbs/listener.ora|grep PORT|sed 's/.*PORT.*\([0-9]\{4\}\)\(.*\)/\1/' | head -1)


1

Given the way you've constructed the command, by recommendation would be to use head, tail, or some combination of the two to get only one result. If you just want the first result, head -1 should do it. If you're looking for a specific line number, a combination of head and tail will likely be necessary.


4

You can use history expansion $ echo test !#:^ echo test test test test $ echo a/b/test.py proj_copy/!#:^ echo a/b/test.py proj_copy/a/b/test.py a/b/test.py proj_copy/a/b/test.py !# The entire command line typed so far. :^ The first argument You could also use brace expansion $echo test{,} test test $echo {,proj_copy}/a/b/test.py /a/b/...


1

You can do it like this: $ MYVAR='<li class="rainbow-list-item southern disrupted " data-line-id="lul-southern" data-severity-codes="4,6,9" data-mode="national-rail">' $ echo $MYVAR | tr ' ' '\n' | awk -F= '/data-severity-codes/ {print $2}' "4,6,9" You can also use sed to remove " and replace , by a blank if you need it: $ echo $MYVAR | tr ' ' '\n' ...


1

You can use the matching operator =~: #! /bin/bash var='<li class="rainbow-list-item southern disrupted " data-line-id="lul-southern" data-severity-codes="4,6,9" data-mode="national-rail">' if [[ $var =~ data-severity-codes=\"([^\"]+)\" ]] ; then echo ${BASH_REMATCH[1]} fi Output: 4,6,9 Or use an XML-aware tool: xmllint --xpath li/@data-...


1

A quick look at the manual page shows: password=arg specifies the CIFS password. If this option is not given then the environment variable PASSWD is used. If the password is not specified directly or indirectly via an argument to mount, mount.cifs will prompt for a password, unless the guest option is specified. So, ...


5

apt-get install whois Requires a network connection that can see the kali repo at http://http.kali.org/


0

One thing I don't see here, which I've found very useful especially when testing out commands, is pidof. You can use pidof [command] to find the process id of a process that is currently running. I like it because it allows me to quickly find the id of the command I want, which is usually something I just invoked. Once you have the pid, you can simply kill ...


1

Press Up or Ctrl+P to recall the previous line. Repeat if you want the line before, etc. Press Home or Ctrl+A to go to the beginning of the line. Press Alt+D to delete the word under the cursor, i.e. the command you want to replace. Type the command you want to run now. Press Enter to run the command.


2

You can search for a specific integer with a regular expression. Search for the digits preceded by either the beginning of the data or a non-digit character, and likewise after the digits. grep -e '^6$' -e '^6[^0-9]' -e '[^0-9]6$' -e '[^0-9]6[^0-9]' # BRE syntax grep -E '(^|[^0-9])6($|[^0-9])' # ERE syntax An entire-word ...


1

I guess this wasn't such an obscure need. My regular programming editor, pluma supports this via the "find" dialog using the option "Match entire word only". I'm sure many other editors have this as well -- although at the moment, apparently not pluma's ancestor, gedit.


6

grep -E '\b6\b' \b is a "word boundary" Edit: After pointing @nobar in the right direction, he found/pointed_out the shortcut-option -w (word-regexp) in the manpage, which simplifies the above to: grep -w 6 If used a lot, you could use a function similar to wgrp(){ grep -w "$1" "$2"; } Note (to @glenn-jackman): If you don't quote "$2" here, you can ...


4

Two changes to your current script: don't parse ls; instead rely on the shell's globbing because the files are in a subdirectory, either cd there first and run the loop, or use basename and dirname to pull out the directory and filename portions of the file before adding the prefix. (Note: I also changed your "/Path" to "./Path" as I didn't want to ...


5

You can use !!:* to refer to all the words but the zeroth of the last command line. !! refers to the previous command, : separates the event specification from the word designator, * refers to all the words but the zeroth. This is from the HISTORY EXPANSION section of bash(1). wieland@host in ~» cat foo | grep bar bar wieland@host in ~» tail -f !!:* tail -...


0

At least with GNU tools: grep -rcZ "some_pattern" | awk -F'\0' '{s+=$NF}END{print s}' This is likely superior in speed compared to wc -l. It also works for files with newline in name.


4

I was able to put the answer together with help from this question. The program "wc" program counts newlines, words and byte counts. The "-l" option specifies that the number of lines is desired. For my application, the following worked nicely to count the number of instances of "somePattern": $grep -r "somePattern" | wc -l


3

The sqlite3 interface uses the ReadLine library for command line editing. You can erase a full line with Ctrl-U but once you have pressed Enter, the line has been accepted and is no longer editable (well, it is, but not as part of the current statement). As you've noticed, sending end-of-file with Ctrl-D will prompt the client to exit, which is not what you ...


0

You have a few possible solutions: Simply $ ./script *g.log >output ... and hope that *g.log doesn't expand to something that makes the command line too long. This is not very robust. If your script doesn't depend on the number of files given to it, i.e., if output can just be appended to output for each input file, then this is another solution: $ ...


0

If you like you can put the files into a directory /opt/location/source /0001g.log /0002g.log /0003g.log Then in your bash script you can try the following #!/bin/bash # store path to files SOURCE="/opt/location/source/" # loop through files for FILE in `ls $SOURCE*g.log`; do # do what you want to specific file echo $FILE done


0

if ./script 0001g.log 0002g.log 0003g.log > output eq. ./script 0001g.log > output ./script 0002g.log >> output ./script 0003g.log >> output then you can use loop or `seq -f '%04gg.log' 10` | script > output


0

This is related to another which I answered recently, but the accepted answer in that case is unsuitable: terminal: displaying special characters The first screenshot clearly shows htop being run on a terminal where UTF-8 encoding is not supported, because the misdrawn text should be line-drawing characters. The latter shows it using ASCII characters to ...


7

With zsh: rm -f pre*(OL[2,-1]) OL: reverse order by size [2,-1]: second to last only The equivalent with bash and GNU utilities would be something like: eval "files=($(LC_ALL=C ls --quoting-style=shell-always -dS ./pre*))" rm -f "${files[@]:1}" You may want to limit it to regular files, as the size for non-regular files has generally not much ...


7

You can use a combination of few utilities: stat -c '%s %n' pre_* | sort -k1,1rn | tail -n +2 | cut -d' ' -f2 | xargs rm Assuming GNU system and no unusual filenames. stat gets the filesize and name separated by space for all pre_* files sort sorts the file according to the file size, with highest sized one goes to top tail -n +2 gets the rest of the ...



Top 50 recent answers are included