Hot answers tagged

15

There are three independent "directories" at play here: your current shell's current working directory, the shell script's current working directory, and the directory containing the shell script. To demonstrate that they are independent, you can write a shell script, saved to /tmp/pwd.sh, containing: #!/bin/sh pwd cd /var pwd You can then change ...


14

If both terminals belong to the same user, you can send your output to the virtual device that is used as the particular terminal's tty. So you can use the output from w, which includes the TTY information, and write directly to that device. ls > /dev/pts/7 (If the device mentioned by w was pts/7) Another option is to use the number of a process that ...


8

You can use write command. As @MelBurslan commented, if write permission is off, first execute: $ mesg y From man mesg OPTIONS y Allow write access to your terminal. Usage of write: $ write username tty e.g. Send ls output to other terminal. $ w USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT user :0 :0 ...


7

With GNU grep: grep -o '\b\w*\.swf\b' file Output: example.swf example2.swf example3.swf \b: a zero-width word boundary \w: word character \.: match one dot See: The Stack Overflow Regular Expressions FAQ


4

Yes, it is provided by GRUB. The GRUB command shell is just as powerful as the shell. You can use it to discover boot images, kernels, and root filesystems. When you're at the grub> prompt, you have a lot of functionality similar to any command shell such as history and tab-completion. The grub rescue> mode is more limited, with no history and no ...


4

I found a similar method. On first terminal: $ tty /dev/pts/0 $ <no need to run any command here, just see the output> On second terminal: $ ls > /dev/pts/0 Now you get the output on first terminal


4

Present (or Current) Working Directory Does the command pwd in a shell script return the directory the shell script is in? No. Firstly, by definition, no shell script or shell command returns anything other than a numeric exit status between 0 - 255. That's axiomatic, but not generally not what people mean when they ask these types of questions. ...


3

There is this concept called cwd that every running process keeps track of. Or better worded: the kernel keeps an idea of the cwd of each process. That could be read with (for a system with /proc): readlink /proc/$PID_of_PROCESS/cwd And for the running shell (of which its PID should be $$): $ readlink /proc/$$/cwd The shell keeps track of the same ...


3

You've got most of the technical details, but I think you're missing the semantics of the whole thing. The single quotes in '^d' keep whatever shell runs that pipeline from treating characters in the regular expression (which is '^d') as "special". For example, $ is the regular expression meaning "end of line". Shells also use $ to mark the next token as a ...


3

First step Replace spaces with line ends using sed Second step Filter the output using grep Example sed -e s/\ /\\n/g file | grep .swf


3

Depending on the user you are using, you may need to type su - or sudo first to get root privileges. Type lsblk: > lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 111,8G 0 disk ├─sda1 8:1 0 1020K 0 part ├─sda2 8:2 0 41G 0 part ├─sda3 8:3 0 11G 0 part ├─sda4 8:4 0 19G 0 part / ├─sda5 8:5 0 ...


3

You can do: grep -o '[^ ]*\.swf' file.txt [^ ]* matches zero or more non-space characters \.swf matches literal .swf Example: % grep -o '[^ ]*\.swf' file.txt example.swf example2.swf example3.swf


2

This is not an answer, but maybe it's an acceptable work-around: alias p='perl; echo hit control-d again; cat > /dev/null' Then, if your perl script exits prematurely, you'll harmlessly paste the remainder to /dev/null; if the perl script succeeds, you'll see your friendly reminder and hit control-d to exit the cat catcher.


2

Reinstalling the entire system would be overkill, if you ran the command as non-root user. Even if you can't/won't restore all settings and files immediately, it would be far easier to create another user on the system and work as that user. You can still move over settings, data files, etc. from the old account as you find the need. (Keep in mind though ...


2

As for software for doing remote Windows automation tasks from the Unix/Linux side, I am aware of: Ansible - devops automation framework Rundeck - web based Java automation framework putty - pscp tools, for talking SSH on the Windows remote side cygwin - cross-compiled GNU tools framework for Windows Win32-openSSH - Microsoft´s port of OpenSSH freeSSHd - a ...


2

You are missing one pipe | character. Try: sort myfile |uniq -u|tee newfile.txt If this is not working, please provide the error message you are getting. By the way, this command uniq -u eliminates all lines which have duplicates. If this is your intention, that is fine. But if you want to see one of the duplicate lines, you need to drop -u for the uniq ...


1

I think that ifconfig is not handling wireless stuff like ESSID, channel and key. Take a look to iwconfig instead. http://manpages.ubuntu.com/manpages/vivid/it/man8/iwconfig.8.html


1

I did df -a and saw root was 100% in use. so then I tried: du -ak / | sort -nr | less to get the directories holding the most space. while that was attempting to run, it crashed, saying "/var/tmp is full" so I went into /var/tmp, and deleted everything. once I did that, I was able to print again. for giggles, I ran du -ak / | sort -nr | less again, to ...


1

You can use the read shell builtin: while IFS=" " read -r value1 value2 remainder do ... done < "input.txt" Extra fields, if any, will appear in 'remainder'. The shell's default IFS (inter-field-seperator) consisting of white space characters will be used to split each line into its component fields.


1

Workaround: Open additional pdf files either using the absolute path names or relative path names to the initial pdf file. So for example okular foo.pdf & okular ../foobar.pdf and okular foo.pdf & okular /the/complete/absolute/path/to/foobar.pdf both work. //Update: To automate the workaround, this function can be added to ~/.bashrc. It ...


1

The recode program can do this quickly even for large files, either frequency statistics either for bytes or for the characters of various character sets. E.g. to count byte frequencies: $ echo hello there > /tmp/q $ recode latin1/..count-characters < /tmp/q 1 000A LF 1 0020 SP 3 0065 e 2 0068 h 2 006C l 1 006F o 1 0072 r 1 ...


1

Instead of pasting into the terminal, have the command read from the clipboard. You can use xclip or xsel to print the clipboard content (or conversely write their input to the clipboard). xsel | perl # automatic selection (click+drag, middle click) xsel -b | perl # manual selection (Ctrl+C, Ctrl+V) This only works if the shell in the ...


1

In addition to the "solution/work-around" by Jeff Schaller , the proper solution seems to be to make the environment aware of copy-paste, both from sender side and from receiver side, which is known as "bracketed paste mode". From https://cirw.in/blog/bracketed-paste , here is a short snippet to explain a little more : In summary: Enable ...



Only top voted, non community-wiki answers of a minimum length are eligible