Tag Info

Hot answers tagged

28

I would say because it's hardly ever necessary to create an empty file that you won't fill with content immediately on the command line or in shell scripting. There is absolutely no benefit in creating a file first and then using I/O redirection to write to the file if you can do so in one step. In those cases where you really want to create an empty file ...


20

To me the "cd ../code" is a noop. I'm very interested into hearing why it isn't. Because files and directories are fundamentally filesystem inodes, not names -- this is perhaps an implementation detail specific to the filesystem type, but it is true for all the ext systems, so I'll stick to it here. When a new directory code is created, it is ...


17

Yes, there is a big difference. && is short-circuiting, so the subsequent command would be executed only if the previous one returned with an exit code of 0. Quoting from the manual: expression1 && expression2 True if both expression1 and expression2 are true. On the other hand, a script containing expression1 expression2 would ...


13

Your shell doesn't every time do a cd to the path that it was in during the last command, before executing the next command. You deleted the current directory and created a directory with the same name, which is not the same directory, just something with the same name/path. File browsers like Nautilus and Windows Explorer normally "go up" the directory ...


11

The answer is, as so often, "it depends". Usually directories directly under /home are only user home directories. It is entirely possible to put other stuff there too, and it won't harm anything. Whether a user can access a directory under /home, e.g. /home/thisdir, will depend on what permission the directory has. If you grand read and execute ...


9

Adrian Frühwirth's answer is right on. I just wanted to add that there is actually a command specifically written to create files: mktemp. NAME mktemp - create a temporary file or directory SYNOPSIS mktemp [OPTION]... [TEMPLATE] DESCRIPTION Create a temporary file or directory, safely, and print its name. TEM‐ PLATE must ...


8

Use dpkg -L pkgname and pipe it to a grep command searching for bin/ and games/: $ dpkg -L bash | grep -E '(bin|games)/' /bin/bash /usr/bin/bashbug /usr/bin/clear_console /bin/rbash If you want to check for all binaries regardless if they are in your $PATH try this bash function: find_binaries (){ dpkg -L "$@" | while read; do [ -f "$REPLY" ...


7

Trying to run source-highlight as suggested in the linked question produces this error: $ source-highlight -o STDOUT -i .bashrc --out-format=esc source-highlight: could not find a language definition for input file .bashrc That's because .bashrc is not recognized automatically by source-highlight, a quick look through its manual shows that it has the -s ...


7

You can just pipe the output to shuf. $ seq 100 | shuf Example $ seq 10 | shuf 2 6 4 8 1 3 10 7 9 5 If you want the output to be horizontal then pipe it to paste. $ seq 10 | shuf | paste - -s -d ' ' 1 6 9 3 8 4 10 7 2 5 $ seq 10 | shuf | paste - -s -d ' ' 7 4 6 1 8 3 10 5 9 2 $ seq 10 | shuf | paste - -s -d ' ' 9 8 3 6 1 2 10 4 7 5 Want it with ...


6

Yes, && is condition. Command behind will be started only if the previous one returns 0 (ends without an error). On the other hand your script hasn't this control so if eg. wget ends with error it will continue and try to unzip and move nothing.. Onliner for your script is: wget http://something.com ; unzip something ; mv -f something /home/poney/ ...


6

Most basic shell tools are not designed for any very specific purpose at all. Most basic shell tools are designed only to interact with others to achieve your purpose. Or maybe it should be said that most tools do only one very basic thing regardless of how they might be combined to achieve a goal. : >./file That creates an empty file. Or truncates an ...


4

I like @Stephane's answer for the general case, but here's something more appropriate for your specific example. Start up MySQL interactive mode and use the source command to run SQL scripts. $ mysql -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 947 Server version: 5.1.73-1 (Debian) Type ...


4

It sounds like you want something like this (although it's not clear what you mean when distinguishing "iterative command" from "recursive command", since rm -rf is both recursive and iterative): find . -type d -name '.[^.]*' -prune -exec echo rm -rf {} + Once you're happy, remove echo from the option arguments to -exec to remove the listed directories.


4

dc is a very archaic tool and somewhat older than bc. To quote the Wikipedia page: It is one of the oldest Unix utilities, predating even the invention of the C programming language; like other utilities of that vintage, it has a powerful set of features but an extremely terse syntax. The syntax is a reverse polish notation, which basically means that ...


4

The most straight forward way I can see to do this is with GNU find, bash and the sponge utility from moreutils: find dir/with/files -name '*.txt' ! -name '*.DontTouch.txt' -print0 | while IFS= read -rd '' file; do echo 'cat path/to/theCommonComment.txt "$file" | sponge "$file"' done As it stands this will just print the cat/sponge commands ...


3

On most UNIX-like systems, the "current directory" for a process is stored in the kernel as a file descriptor pointing to that directory. The kernel doesn't actually store the path of the current directory: that information is tracked by your shell. A filesystem object (file or directory) is only destroyed for good when all filesystem links to it are gone, ...


3

What is the difference between the ways? from bash manpage: eval [arg ...] The args are read and concatenated together into a single com‐ mand. This command is then read and executed by the shell, and its exit status is returned as the value of eval. If there are no args, or only null ...


3

You could use \ before the character ? so it is consider as a normal character in the name of the file and not a special character to be interpreted. The command would then be: mv Giko\ Suzo\ San\?e\ -\ Ep1.avi 'Giko Suzo Sane - Ep1.avi' EDIT: following discussion in comments, this line did the trick: mv Giko\ Suzo\ Sa*\ -\ Ep1.avi 'Giko Suzo Sane - ...


3

1. Use a tool designed for the job. The easiest and probably the most robust way is to install dlocate: sudo apt-get install dlocate You can then run dlocate -lsbin package-name As xplained in man dlocate: -lsbin List full path/filenames of executable files (if any) in package 2. Parse the package database This is a similar approach to @Winny's ...


3

x="$(head -15 testfile.txt)" if [ "$x" = disabled ] then echo "We are disabled" fi Generally, any time that you want to capture the output from a command into a shell variable, use the form: variable="$(command args ...)". The variable= part is assignment. The $(...) part is command substitution. Also note that the shell does not do if statements ...


3

The reason the that you do not see the input box is because whiptail writes the display to stdout, which you are capturing. The result of the input is written to stderr, which you are not capturing. To make this work, you need the command substitution to capture stderr, but not stdout. You can do this with redirection: #!/bin/bash xfreerdp ...


3

The following function permits to change to sibling directories (bash function) function sib() { ## sib search sibling directories ## prompt for choice (when two or more directories are found, current dir is removed from choices) ## change to directory after selection local substr=$1 local curdir=$(pwd) local choices=$(find ...


3

\< matches the beginning of a word \> matches the end of a word \b matches both boundaries if at the end or at the beginning The important thing about those special characters is that they match an empty string and not the word boundary itself. a word boundary being the contrary of the the set of character represented by \w equivalent of ...


3

Since you opened a quotation ' and pressed enter, the shell is wanting you to close the quote. The quote> prompt is simply a visual indication of such. This is so that you can pass multi-line arguments to programs. For example: $ echo 'hi quote> there' hi there Since you typed ls'Enterls'Enter, this is the equivalent to trying to run a command ...


3

The difference between man and other commands like ls is that latter ones (those not complaining about non-existent directory) don't try to explicitly change there but already stay there. Man also does, but it additionally tries to explicitly change there, too. UNIX directories (as files) aren't deleted immediately when you call unlink(2) or rmdir(2) on ...


2

You should type arm-linux-gcc instead of ./arm-linux-gcc. ./arm-linux-gcc indicate that you run arm-linux-gcc program, located in you current working directory. So the shell can not find you program because it is installed somewhere in your $PATH. You can find its location by using: which arm-linux-gcc


2

This isn't possible. I dug through the source code and you can force a line break (CTRL+V,CTRL+M), but this actually messes up the display. The event stays on the same line but the line break starts over at the beginning and overwrites the characters. Given the following two examples: 00000325 Popeye statue unveiled, Crystal City TX Spinach Festival, ...


2

I assume xfreerdp is a gui programm (an "X client"). So on Linux, you need an "X server" to run it. That's what you have on the GUI based Linux box. You can not run it on the command-line-only Linux in itself. Depending on what you are trying to do, it could make sense to run it on the command-line-only Linux and show the GUI somewhere else over the ...


2

Another difference to the one mentioned is that your shell script runs in a separate shell, therefore any changes to the environment won't propagate out. For example, if you type in your interactive shell test -f foo && file=foo || file=other then your interactive shell will contain a variable file (which you can read with $file) containing foo if ...


2

printf '%s, ' `seq 1 10 | shuf` You don't even need a for loop. OUTPUT 7, 3, 4, 10, 2, 9, 1, 8, 5, 6, To get them in a shell array you do: ( set -- $(seq 1 10 | shuf) ; printf '%s, ' "$@" ) OUTPUT 5, 9, 7, 2, 4, 3, 6, 1, 10, 8, And then they're in your shell array. If you get them in the shell array, you don't even need printf: ( set -- $(seq 1 ...



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